Spring MVC principle and Spring MVC Principle

Source: Internet
Author: User

Spring MVC principle and Spring MVC Principle
Spring MVC Workflow
Figure 1

Figure 2

Spring workflow description1. the user sends a request to the server. The request is captured by the Spring front-end control Servelt DispatcherServlet; 2. DispatcherServlet parses the request URL to obtain the request Resource Identifier (URI ). Then, according to the URI, call HandlerMapping to obtain all the related objects (including the Handler object and the interceptor corresponding to the Handler object) of the Handler configuration, and finally return the result in the form of the HandlerExecutionChain object; 3. dispatcherServlet selects a suitable HandlerAdapter Based on the obtained Handler. (Notes: If HandlerAdapter is obtained successfully, the preHandler (...) of the interceptor will be executed (...) method) 4. extract the model data in the Request, fill in the Handler input parameter, and start to execute Handler (Controller ). During the Handler input parameter filling process, Spring will help you with some additional work according to your configuration: HttpMessageConveter: Send request messages (such as Json and xml data) convert an object to a specified response data conversion: Convert the request message data. For example, convert String to Integer or Double: format the request message data. For example, convert a string to a formatted number or a formatted date for data verification: verify the validity (length, format, etc.) of the data, the verification results are stored in BindingResult or Error 5. after Handler completes execution, return a ModelAndView object to DispatcherServlet; 6. based on the returned ModelAndView, select a suitable ViewResolver (which must be ViewResolver already registered in the Spring container) and return it to DispatcherServlet; 7. viewResolver uses Model and View to render a View. returns the rendering result to the client.
Spring workflow description why does Spring use only one Servlet (DispatcherServlet) to process all requests? For details, see the J2EE design mode. Why does Spring use HandlerMapping and HandlerAdapter to process Handler? In line with the single responsibility principle in Object-Oriented Systems, the Code architecture is clear and easy to maintain. The most important thing is the high reusability of code. For example, HandlerAdapter may be used to process multiple Handler types.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.