concept

The SpringMVC framework is a request-driven Web framework designed using a ‘front controller’ model, which is then distributed to the corresponding page controller for processing according to the ‘request mapping rules’.

1. Specific steps

  • 1. First, the user sends a request to the front controller. The front controller decides which page controller to enter according to the request and delegates the request to it.
  • 2. After receiving the request, the page controller performs functional processing. First, it needs to collect and bind the request parameters to an object, which is called command object in Spring Web MVC, and verify it, and then delegate the command object to the business object for processing; After processing, return a ModleAndView;
  • 3. The front-end controller retrieves control, and then selects the corresponding View to render according to the returned View, and passes in model data for View rendering
  • 4. The front-end controller takes back control again and returns it to the user accordingly.

  • 1. Send requests to DispatcherServlet
  • 2. The front-end controller requests the HandlerMapper to find the Handler (which can be based on the XML configuration, annotations).
  • The forward controller returns a Handler. HandlerMapping maps the request to a HandlerExecutionChain object. Multiple HandlerInterceptor interceptor objects), with this policy pattern, it is easy to add new mapping policies
  • The front-end controller calls the HandlerAdapter to execute the Handler
  • 5. The HandlerAdapter will execute the Handler based on the result of the adaptation
  • 6. Handler returns ModelAndView to the adapter after execution
  • 7. HandlerAdapter returns the ModelAndView to the DispatcherServlet
  • 8. DispatcherServlet requests viewResolver for view resolution. With this strategy, you can replace other view technologies by changing the viewResolver
  • 9. The View parser returns a View to the DispatcherServlet
  • 10. DispatcherServlet renders the view and fills it into the Request field
  • 11. Return the corresponding result

2. Summarize the core development steps

  • 1. Deployment description of DispatcherServlet in web.xml to intercept Spring Web MVC
  • Configuration of HandlerMapping to map requests to handlers
  • 3. HandlerAdapter configuration to support multiple types of processors
  • Note: Processor mapping requests and adapter usage relief are included in the annotation driver and do not need to be configured separately
  • ViewResolver configuration to resolve logical view names to specific view technologies
  • 5, processor configuration, so as to carry out functional processing

View is an interface that implements classes that support different View types (JSP, Freemaker, PDF)