Briefly talk about the workflow of SpringMVC

How to process model data

1) Set the return value of the method to ModelAndView

public ModelAndView test(){
    1.创建ModelAndView对象
    ModelAndView mav=new ModelAndView();
    2.设置模型数据,最终会返稿request域中
    mav.addObject("xxx","xx");
    3.设置视图
    mav.setViewName("success");
    return mav
}

3) The return value of the method is still of String type, and Map, Model or ModelMap is passed in the input parameters of the method. Regardless of whether the return value of the processor method is set to ModelAndView or Map, Model or ModelMap is passed in the method's input parameters. SpringMVC will be converted to a ModelAndView object

 

process

 

1. The user sends a request to the front controller DispatcherServlet.

2. DispatcherServlet receives the request to call the HandlerMapping processor mapper.

3. The processor mapper finds the specific processor (you can search based on the xml configuration and annotations), generates the processor object and the processor interceptor (generate if there is one) and returns it to the DispatcherServlet.

4. DispatcherServlet calls the HandlerAdapter processor adapter.

5. HandlerAdapter calls a specific processor (Controller, also called back-end controller) through adaptation.

6. The Controller returns to ModelAndView after execution.

7, HandlerAdapter returns the controller execution result ModelAndView to DispatcherServlet.

8. DispatcherServlet passes ModelAndView to ViewReslover view resolver.

9. After ViewReslover parses, it returns to the specific View.

10. DispatcherServlet renders the view according to the View (that is, fills the model data into the view).

11. DispatcherServlet responds to users.
 

Guess you like

Origin blog.csdn.net/di_ko/article/details/114920084