The main components of Spring MVC?

The main components of Spring MVC?
(1) The front controller DispatcherServlet (does not require programmers to develop)
Function: Receive requests and response results, which is equivalent to a repeater. With DispatcherServlet, the coupling between other components is reduced.
(2) HandlerMapping (no need for programmers to develop)
Function: Find Handler according to the requested URL
(3) HandlerAdapter HandlerAdapter

Note: When writing the Handler, it must be written according to the rules required by the HandlerAdapter, so that the
HandlerAdapter can execute the Handler correctly.
(4) Handler (programmer development is required)
(5) View resolver ViewResolver (programmer development is not required)
Function: to analyze the view and resolve it into a real view according to the logical name of the view
(6) View View (Need programmer to develop jsp)
View is an interface, and its implementation class supports different view types (jsp, freemarker, pdf, etc.)

What is DispatcherServlet
Spring's MVC framework is designed around DispatcherServlet, which is used to process all HTTP requests and responses.

What is the controller of the Spring MVC framework?
The controller provides a behavior to access the application, which is usually implemented through a service interface. The controller parses the user input and transforms it into a model that is presented to the user by the view. Spring implements a control layer in a very abstract way, allowing users to create controllers for multiple purposes.

Is the controller of Spring MVC a singleton mode? If so, what is the problem and how to solve it?
Answer: It is a singleton mode, so there are thread safety issues during multi-threaded access. Do not use synchronization, which will affect performance. The solution is that you cannot write fields in the controller.

3. Working principle

Please describe the workflow of Spring MVC? Describe the workflow of DispatcherServlet?

(1) The user sends a request to the front controller DispatcherServlet;
(2) After receiving the request, the DispatcherServlet calls the HandlerMapping processor mapper to request Handle;

(3) The request handler mapping to locate the specific url processor, an object processor, and a processor generates blocker (if any is generated) collectively returned to the DispatcherServlet;
(. 4) to call the DispatcherServlet HandlerAdapter processor adapter;
(5) HandlerAdapter calls a specific processor (Handler, also called back-end controller) after adaptation;
(6) Handler execution is complete and returns ModelAndView;
(7) HandlerAdapter returns Handler execution result ModelAndView to DispatcherServlet;
(8) DispatcherServlet sends ModelAndView to ViewResolver The view resolver parses;
(9) ViewResolver parses and returns the specific View;
(10) DispatcherServlet renders the view (that is, fills the model data into the view)
(11) DispatcherServlet responds to the user.

Guess you like

Origin blog.csdn.net/qq_42918433/article/details/113943216