The SpringMVC framework is a request-driven Web framework, and uses the 'front-end controller' model for design, and then distributes it to the corresponding page controller according to the 'request mapping rules' for processing.
What is the process of spring mvc?
Overall process:
1. First, the user sends a request——>DispatcherServlet (front-end controller), and the front-end controller receives the request Afterwards, it does not process it itself, but delegates it to other parsers for processing, as a unified access point for global process control;
2. DispatcherServlet——>HandlerMapping (processor mapper), HandlerMapping The request will be mapped to a HandlerExecutionChain object (including a Handler processor (page controller) object, multiple HandlerInterceptor interceptors) object. Through this strategy mode, it is easy to add new mapping strategies;
3 , DispatcherServlet——>HandlerAdapter (processor adapter), HandlerAdapter will package the processor as an adapter to support multiple types of processors, that is, the application of the adapter design pattern, making it easy to support many types of processors;
4. HandlerAdapter——>Call the processor function processing method. HandlerAdapter will call the real processor function processing method according to the adaptation result to complete the function processing; and return a ModelAndView object (including the model Data, logical view name);
5. ModelAndView’s logical view name——> ViewResolver. ViewResolver will parse the logical view name into a specific View. Through this strategy model, it is easy to replace other view technologies. ;
6. View——>Rendering, View will render according to the incoming Model model data. The Model here is actually a Map data structure, so it can easily support other view technologies;
7. Return control to DispatcherServlet, and DispatcherServlet returns a response to the user. This is the end of the process.
Core process:
1. Initiate a request to the front-end controller (DispatcherServlet)
2. The front-end controller requests HandlerMapping to search for Handler (can be searched based on xml configuration and annotations)
3. The processor mapper HandlerMapping returns Handler to the front-end controller. HandlerMapping will map the request to a HandlerExecutionChain object (including a Handler processor (page controller) object, multiple HandlerInterceptor interceptor objects), through this strategy mode, it is easy to add new mapping strategies
4. The front-end controller calls the processor adapter to execute Handler
5. The processor adapter HandlerAdapter will execute the Handler according to the adaptation result
6. After the Handler execution is completed, it returns ModelAndView to the adapter
7. The processor adapter controls the front end The controller returns ModelAndView (ModelAndView is an underlying object of the springmvc framework, including Model and view)
8. The front-end controller requests the view parser to perform view parsing (resolve into a real view (jsp) based on the logical view name ), it is easy to replace other view technologies through this strategy, just change the view resolver
9. The view resolver returns View to the front-end controller
10. The front-end controller performs View rendering (view rendering fills the model data (in the ModelAndView object) into the request field)
11. The front-end controller responds to the user with the results
[Related recommendations: Java Tutorial】
The above is the detailed content of What is the process of spring mvc?. For more information, please follow other related articles on the PHP Chinese website!