From accepting requests to returning responses, the many components of the Spring MVC framework are stretched out on their arms and sleeves, doing their jobs and doing their job in a methodical way. Throughout the framework, Dispatcherservlet is at the core, and it is responsible for coordinating and organizing different components to work together to complete the request response. Like most web MVC frameworks, spring MVC receives all requests through a front-end servlet processor and delegates specific work to other components for specific processing, Dispatcherservlet is the front-end servlet processor for spring MVC. Let's take a look at the overall process of Spring MVC processing requests at a high altitude:
① the entire process begins by sending an HTTP request to the client;
②dispatcherservlet receives this request and delegates the processing of the request to the specific processor (Handler), which handles the request to execute the appropriate business logic. Prior to this, Dispatcherservlet must be able to find the requested processor by a mechanism based on the request (URL or request parameters, etc.), Dispatcherservlet to complete the work by inquiring handlermapping;
③ when Dispatcherservlet obtains the processor for the current request from the handlermapping, it assigns the request to the processor. The processor executes the appropriate business logic based on the requested information, and a well-designed processor should complete the business process by invoking the service layer's business object rather than someone else itself.
When the ④ processor finishes processing the business logic, it returns a Modelandview to Dispatcherservlet,modelandview that contains the view logical name and the model data object to be used when rendering the view;
⑤ because Modelandview contains the name of the view logic, Dispatcherservlet must know the real view object corresponding to the logical name, and the work of the view parsing is done by calling Viewresolver;
⑥ when a real view object is obtained, Dispatcherservlet assigns the request to the View object, which completes the rendering of the model data.
⑦ the end client gets the response returned, which could be a normal HTML page, or an Excel spreadsheet, or even a PDF document, a view of the type of spring that is unusually rich and flexible
Spring MVC request processing process and source code analysis