"Internet Architecture" Software Architecture-Spring MVC of Spring Source Code (Part 2) (13)

I was contacted by the old iron and wanted to learn a framework, look at the source code from the bottom, and write comments on each. My suggestion, Lao Tie, don’t be silly. How many people write a framework for a team, and how many days and nights you have to support your family. Actually, there are three stages. Let me talk about the specific three stages.

The stage of learning a framework

  1. Learn to use this framework

Looking through the book, Baidu is basically enough.

  1. Master the architectural ideas of this framework and its hierarchical structure. [It’s just right to master the second stage]

Interface, model, context. Basically understand the thought and level, how to operate.

  1. Grasp the implementation details of the bottom layer (go to the details when you need to remodel)

It is not recommended to master the third layer. If the framework is to be reformed, the bottom-level specific implementation is researched. It is not necessary to understand all of them, but to change where to study and the specific implementation. Implementation. Don’t, look at the source code of a framework, from beginning to end, such as the function of spring MVC, how does MVC implement it, from its definition to its implementation, to the implementation of all subclasses, a vertical study is easy Just fainted. A spring mvc may have thousands of methods to be called. Can you stand it? Old iron!

####mvc's basic theory and spring mvc design ideas

  • Review serlvet and jsp execution

I remember when I just graduated from an interview, I often asked what a servlet was? The life cycle of a servlet? What are the 9 built-in objects of jsp?

Spring MVC essentially encapsulates it to simplify the development process, ease of use, and clearer program structure.

  1. Annotation-based URL mapping
  2. http form parameter conversion
  3. Global unified exception handling
  4. Implementation of interceptor
  5. Multi-view control

In fact, if the project is relatively small, there is no need to use spring mvc to see personal habits. There is also a saying on the Internet that the performance of spring mvc is not as fast as servlet. This can be ignored. In fact, 90% of it is the bottleneck of the database or the web method processing of business logic. Springmvc only completes some functions on the basis of Serlvet. In fact, there is nothing to open up the function, but Serlvet's improvement and encapsulation.

  • spring mvc process

image.png

  • Expand dispatchServlet core class structure based on examples
  1. HandlerMapping: reflection of url and controller
  2. HandlerAdapter: Controller execution adapter
  3. ViewResolver: view repository
  4. view: specific analysis view
  5. HandlerExceptionResolver: exception catcher

  • Spring MVC context initial process(10)
  1. webApplicationContext initial process
  2. handlerMappings initial process
  3. handlerExceptionResolvers initial process
  4. viewResolvers initial process
  5. handleAdapters initial process
  • request process
  1. Call doDispatch()
  2. Traverse handlerMappings and request to obtain an execution chain getHandler()
  3. Traverse handleAdapters and handle to obtain a handle adapter
  4. The preHandle() method in the interceptor is called through the execution chain for preprocessing.
  5. Call the handle method based on the handle adapter and return modelAndView
  6. The PostHandle() method in the interceptor is called through the execution chain for interception processing.
  7. processDispatchResult()
    7.1. Normal: call render() for view resolution
    7.1.1 Obtain View based on traversing
    viewResolvers and viewname 7.1.2 Call view.render() for view resolution and return, set model to request
    7.2 Exception: call traversal handlerExceptionResolvers resolveException(), return mv, and finally jump to the exception

PS: That's all for the spring mvc source code. I'm dizzy and let me smoke a cigarette, haha.

Guess you like

Origin blog.csdn.net/zhugeaming2018/article/details/109330377