How SpringMVC works

  • process

    1. The user sends the request to the front-end controller DispatcherServlet(also called CPU)

    2. When DispatcherServlet receives a request, it invokes the HandlerMapping processor

    3. The processor mapping area finds the specific processor (which can be found according to the XML configuration, annotations) and generates the processor object and the processor interceptor (if any) back to the DispatcherServlet

    4.DispatcherServlet invokes the HandlerAdapter processor adapter

    5.HandlerAdapter ADAPTS to call specific processors (controllers, also called back-end controllers)

    6.Controller Returns to ModelAndView

    7. The HandlerAdapter returns the Controlller execution result ModelAndView to the DispatcherServlet

    8.DisPatcherServlet passes ModelAndView to the ViewReslover view parser

    9.ViewReslover parses and returns a specific View

    10.DisPatcherServlet renders the View according to the View (that is, populates the View with model data) 11. DisPatcherServlet responds to the user

  • Component description

    The following components are typically implemented using frameworks:

    • DispatcherServlet: as the front-end controller, the center of the whole process control, control the execution of other components, unified scheduling, reduce the coupling between components, improve the properties of each component
    • HandleMapping: Extends the processor mapper to implement different mapping modes, such as configuration file mode, implementation interface mode, and annotation mode
    • HandlAdapet: Processor adapter
    • ViewResolve: The view resolver can resolve: JSPS, Freemarker, PDF, Excel, and more
  • component

    • 1. Front-end controller DispatcherServlet (without engineer development), provided by the framework: receive requests, response results, equivalent to the repeater, central processor. The dispatcherServlet reduces coupling between other components. When the user request reaches the front-end controller, it is equivalent to C in MVC mode. DispatcherServlet is the center of the whole process control, and it calls other components to handle the user’s request. The existence of dispatcherServlet reduces the coupling between components.

    • 2. HandlerMapping(no need for engineer development), provided by the framework: HandlerMapping is responsible for finding handlers based on user requests. Springmvc provides different mappers to implement different mapping methods, such as configuration files, interface implementation, and annotations.

    • 3, processor adapter HandlerAdapter functions: The Handler executes on the processor through the HandlerAdapter. This is the application of the adapter pattern. By extending the adapter, you can execute on more types of processors.

    • 4, processor Handler(need to be developed by engineers) note: Handler is a back-end controller that follows the front-end controller of the DispatcherServlet, Handler processes specific user requests under the control of DispatcherServlet. Because handlers involve specific user service requests, engineers need to develop handlers based on service requirements.

    • 5. View resolver(no need for engineer development), provided by the framework: The view Resolver is responsible for generating view according to the logical view name. The view Resolver first resolves the logical view name into the physical view name, that is, the specific page address, and generates view objects. Finally, render the View and show the results to the user through the page. The SpringMVC framework provides many View types, including jstlView, freemarkerView, pdfView, and more. In general, the model data needs to be displayed to users through page tags or page templates. Engineers need to develop specific pages based on service requirements.

    • 6, View View(need engineer to develop JSP…) View is an interface and the implementation class supports different View types (JSP, Freemarker, PDF…).

  • The specific process steps of the core architecture are as follows:

    • First, the user sends the request — >DispatcherServlet, the front-end controller does not process after receiving the request, but delegates to other parsers for processing, as a unified access point, global process control;
    • 2, DispatcherServlet – > HandlerMapping, HandlerMapping maps requests to HandlerExecutionChain objects (containing one Handler Handler (page controller) object and multiple HandlerInterceptor interceptors). It is easy to add new mapping policies;
    • 3, DispatcherServlet — >HandlerAdapter, HandlerAdapter will wrap the processor as an adapter, so as to support many types of processors, that is, the application of the adapter design pattern, so that it is easy to support many types of processors;
    • 4, HandlerAdapter — > processor function processing method call, HandlerAdapter will be based on the results of the adaptation to call the real processor function processing method, complete the function processing; And returns a ModelAndView object (containing model data, logical view name);
    • 5, ModelAndView logical View name — > ViewResolver, ViewResolver will resolve the logical View name into a specific View, through this strategy mode, it is easy to replace other View technology;
    • 6, View — > Render, the View will render based on the Model data passed in, the Model is actually a Map data structure, so it is easy to support other View technologies;
    • 7. Return control to the DispatcherServlet, which returns the response to the user, and the process ends.

The following two components are typically developed: Handler: the processor, which is the back-end controller represented by controller. View: A View, that is, an interface presented to the user, in which a label language is usually required to present model data.

From blog.csdn.net/qq_43378945…