Interview: SpringMVC workflow

1. Work flow chart

Insert picture description here

2. Component function

2.1 Front controller DispatcherServlet (does not require engineer development), provided by the framework

Function: Receive request, respond to result, equivalent to repeater, central processing unit. With dispatcherServlet, the coupling between other components is reduced.

When a user request arrives at the front controller, it is equivalent to c in the mvc mode. DispatcherServlet is the center of the entire process control. It calls other components to process user requests. The existence of dispatcherServlet reduces the coupling between components.

2.2 HandlerMapping (no need for engineers to develop), provided by the framework

Role: Find Handler according to the requested url

HandlerMapping is responsible for finding the Handler that is the processor according to the user's request. Springmvc provides different mappers to implement different mapping methods, such as: configuration file mode, implementation interface mode, annotation mode, etc.

2.3 HandlerAdapter

Role: execute Handler according to specific rules (rules required by HandlerAdapter)

The processor is executed through the HandlerAdapter, which is an application of the adapter pattern, and more types of processors can be executed by extending the adapter.

2.4 Handler (requires engineer development)

Follow the requirements of HandlerAdapter when writing Handler, so that the adapter can execute Handler correctly

Handler is the back-end controller following the DispatcherServlet front controller. Under the control of DispatcherServlet, the Handler processes specific user requests.

Since Handler involves specific user business requests, it is generally necessary for engineers to develop Handler according to business requirements.

2.5 View resolver (no need for engineer development), provided by the framework

Function: Perform view resolution, resolve it into a real view based on the logical view name

The View Resolver is responsible for generating the View view from the processing result. The View Resolver first resolves the logical view name into the physical view name, which is the specific page address, and then generates the View view object. Finally, the View is rendered and the processing result is displayed to the user through the page. The springmvc framework provides many types of View views, including: jstlView, freemarkerView, pdfView, etc.

Generally, it is necessary to display model data to users through the page through page label or page template technology, and engineers need to develop specific pages according to business requirements.

2.6 View (requires engineers to develop page rendering)

View is an interface, and the implementation class supports different View types (jsp, freemarker, pdf...)

A brief understanding of MVC: MVC is often said to be a design pattern, not the SpringMVC framework (it's just that the framework supports this MVC pattern)

Guess you like

Origin blog.csdn.net/xueguchen/article/details/108246798