1. Schematic diagram of SpringMVC operation
2. Operation process analysis
1. The client user sends a request to the front-end controller DispatcherServlet
.
2. DispatcherServlet
Call the HandlerMapping
processor mapper upon receiving the request .
3. The HandlerMapping
processor mapper finds a specific processor (you can search according to the xml configuration and annotations), generates a processor object and a processor interceptor (if there is one), and returns it DispatcherServlet
.
4. DispatcherServlet
Call the HandlerAdapter
processor adapter, and HandlerAdapter
call the specific processor ( Controller
, also called the back-end controller) after adaptation .
5, Controller
the controller performs a complete return ModelAndView
, HandlerAdapter
the controller
execution result ModelAndView
is returned to DispatcherServlet
.
6. The DispatcherServlet
front controller will be ModelAndView
passed to the ViewReslover
view resolver.
7. ViewReslover
Return specific after parsing View
.
8, DispatcherServlet
according to View
render view (ie, the model data to fill the view), and returned to the client user.
3. Description of SpringMVC important components
1. The front-end controller DispatcherServlet (does not need to be developed by engineers), provided by the framework (important)
Function: Entry function of Spring MVC. Receiving the request and responding to the result is equivalent to a repeater and a central processor. With DispatcherServlet reduces the coupling between other components. When the user request reaches the front-end controller, it is equivalent to c in the mvc mode. DispatcherServlet is the center of the entire process control. It calls other components to process user requests. The presence of DispatcherServlet reduces the coupling between components.
2. HandlerMapping (not required to be developed by engineers), provided by the framework
Function: Find Handler according to the requested url. HandlerMapping is responsible for finding the Handler or Controller according to user requests. SpringMVC provides different mappers to implement different mapping methods, such as: configuration file method, interface method, annotation method, etc.
3. HandlerAdapter
Function: Execute the Handler according to specific rules (the rules required
by the HandlerAdapter ). The HandlerAdapter executes the processor. This is the application of the adapter mode. More types of processors can be executed through the expansion adapter.
4. Processor Handler (requires engineer development)
Note: When writing the Handler, do it according to the requirements of the HandlerAdapter, so that the adapter can correctly execute the Handler. The
Handler is the back-end controller following the DispatcherServlet front-end controller, and the Handler processes specific user requests under the control of the DispatcherServlet.
Since the Handler involves specific user business requests, engineers generally need to develop Handlers based on business needs.
5. View resolver (requires no engineer development), provided by the framework
Function: Perform view resolution and resolve to a real view according to the logical view name. The
View Resolver is responsible for generating the View result from the processing result. The View Resolver first resolves the logical view name to the physical view name, that is, the specific page address, and then generates the View view. Object, and finally render the View to display the processing results to the user through the page. The springmvc framework provides many View view types, including: jstlView, freemarkerView, pdfView, etc.
Generally, the model data needs to be displayed to the user through the page through the page label or page template technology, and the engineer needs to develop a specific page according to the business needs.
6. View (requires engineer development)
View is an interface, the implementation class supports different View types (jsp, freemarker, pdf ...)
Note: The processor Handler (that is, the Controller we usually talk about) and the view layer view require our own manual development. Some other components such as: front-end controller DispatcherServlet, processor mapper HandlerMapping, processor adapter HandlerAdapter, etc. are provided to us by the framework, do not need to be developed manually.
References:
http://www.imooc.com/article/256062 [Mu Class Network]
https://blog.csdn.net/qq_39470733/article/details/80980320