SpringMVC workflow analysis

SpringMVC framework is a request-driven Web framework, and uses the front-end controller model to design, and then according to the request mapping rules distributed to the corresponding page controller for processing.

In general, the SpringMVC development process is as follows

  • 1. Configure the DispatcherServlet front-end controller

  • 2. Develop handlers (@controller, @requestMapping) to handle specific business logic

  • 3. XML configuration file configures controller scanning and SpringMVC

  • 4. Tell SpringMVC (DispatcherServlet) the path of the XML file

Spring MVC request processing flow

Process description:

  • Step 1: The user sends the request to the front-end controller DispatcherServlet

  • Step 2: The DispatcherServlet invokes the HandlerMapping processor mapper upon receiving the request

  • Step 3: The processor mapper finds the specific Handler (back-end controller) based on the request Url, generates the processor object and a processor interceptor (if any) that returns the DispatcherServlet

  • Step 4: The DispatcherServlet calls the HandlerAdapter processor adapter to call the Handler

  • Step 5: The processor adapter executes the Handler

  • Step 6: Handler completes execution and returns the ModelAndView to the processor adapter

  • Step 7: The processor adapter returns the ModelAndView to the forward controller, which is an underlying object of the SpringMVC framework that includes Model and View

  • Step 8: The front controller requests the view resolver to parse the view, resolving the real view based on the logical view name.

  • Step 9: The View parser returns the View to the front controller

  • Step 10: The front controller renders the view by populating the model data (in the ModelAndView object) into the Request field

  • Step 11: The front-end controller responds to the user

conclusion

1. The client sends the request to the back end, and then the DispatcherServlet intercepts the request and passes it to the HandlerMapping processor mapper

2. Find the corresponding Handler based on the Url and send it to the HandlerAdapter

3. HandlerAdapter calls Handler to query the result

Note: The processor-mapped summation adapter uses the notation contained in the annotation driver and does not need to be configured separatelyCopy the code

4. Pass the result to ModelAdnView for parsing encapsulation and return to view

View is an interface and the implementation class supports different View types (JSP, Freemarker, PDF...).Copy the code

5. Return the view to the response user in the request