I. The recent accidents on Malaysia Airlines Flight 370 have been raging, and the plot is confusing. Even springMVC's peaceful mood has been indirectly affected. Just as I was wondering how the MVC process could be better understood? Gray machine, gray machine... My colleagues' discussion and the buzz of heaven gave me an answer, which can be compared with the civil aviation system. The civil aviation system is similar to a professional travel processing system, which has some terms that are only available in the travel system, such as traveling. For example, 1. flight MH370 is a flight code, indicating the flight from Kuala Lumpur to Beijing; 2. record the flight schedules to find all flights. 3. air Ticket: the token that uniquely identifies a traveler in the civil aviation system. The plane ticket is required for boarding the plane. The plane ticket is used to take the luggage. 4. security check: check whether there are any contraband; 5. airplane: complete the trip from departure to destination; 6. airport: From the Perspective of passengers, it is nothing more than air tickets, security checks, and flights. Return to the web system. A url uniquely identifies a processing logic name. For example, login. do is equal to the login logic identifier. HandlerMapping is equivalent to a flight schedule and identifies the flight and the corresponding route. HandlerMethod is equivalent to a plane that processes a flight to complete the conversion from the boarding location to the destination. HandlerAdapter is equivalent to an adaptation tool for switching from a routine state to a flight state, similar to an airport. HandlerInterceptor is equivalent to the common processing logic during the conversion process. For example, if you want to purchase a ticket, you must purchase a ticket with your ID card before boarding the plane, and you need to take the luggage at the destination, and other general matters for Flight travel. These four components constitute the cornerstone of spring mvc processing.: Sidajingang Figure 1: four major components: when traveling, you need to adapt from normal status to travel status, for example, convert your ID card and money into a ticket (a token that uniquely identifies your identity during a trip), and then store your luggage on the plane. After arriving at the destination airport, it is necessary to adapt the travel status to the normal state, and use the air ticket to carry out the luggage operation. All boarding procedures must undergo some general logic, such as security checks and baggage check/retrieval. This part constitutes the reason why HandlerInterceptor exists. These four components fully decouple the web environment and business logic environment, so that the business logic can focus more on the business itself and cut the horizontal travel logic and the longitudinal general logic such as security check. The four components are eXtensible, and HandlerMethod is the most common and abstract method. HandlerInteceptor is an extension interface of the vertical logic, HandlerAdapter is an adaptation extension interface from the web environment to the business environment, and HandlerMapping is an extension interface that maps URL requests to the business logic. I. Component Structure HandlerMapping Mapping HanderAdapter adapting III. processing process: the logic is mainly concentrated in org. springframework. web. servlet. dispatcherServlet. doDispatch (HttpServletRequest, HttpServletResponse). obtain the set of methods that match the interceptor according to the request (such as url, parameter, head, etc.) features. Spring mvc 3.0 can be annotated to identify the logical method and URL ing relationship. Therefore, it involves scanning the source code to identify the @ Controller class and searching for @ RequestMapping to generate a ing table. MappedHandler = getHandler (processedRequest, false); 1. org. springframework. web. servlet. handler. abstractHandlerMethodMapping. getHandlerInternal (HttpServletRequest) gets the Request Path lookupPath to find the corresponding handlerMethod method 1.1 org. springframework. web. servlet. handler. abstractHandlerMethodMapping. lookupHandlerMethod (String, HttpServletRequest) 1.1.1 groups all mappings according to requestURI and stores them in urlMap. In urlMap, find the matched list based on the Request Path for further matching. In the matching list, except for the same request requestURI, some other features such as methods, POST, GET, and request headers are different. 1.1.2 org. springframework. web. servlet. mvc. method. requestMappingInfoHandlerMapping. getMatchingMapping (RequestMappingInfo, HttpServletRequest) first finds matching conditions from the request, such as method, params, produce, consume, and so on, to meet the conditions for generating a match and sort the matching degree of these matches, obtain the most matched match 2. getHandlerExecutionChain (handler, request) adds the matched Interceptor and returns B. handlerAdapter ha = getHandlerAdapter (mappedHandler. getHandler (); The request will get the corresponding parameter., Session, Model, and so on to support custom Controller parameters. 1. org. springframework. web. servlet. mvc. method. abstractHandlerMethodAdapter. handle (HttpServletRequest, HttpServletResponse, Object) is adapted to 1.1 org. springframework. web. servlet. mvc. method. annotation. requestMappingHandlerAdapter. handleInternal (HttpServletRequest, HttpServletResponse, HandlerMethod) 1.2 org. springframework. web. servlet. mvc. method. annotation. requestMappingHandlerAdapter. invokeHandlerMethod (HttpServletRequest, HttpServletResponse, HandlerMethod) 1.2.1 the data binding method and controller adaptation mainly contain two parts: the adaptation of call parameters and the adaptation of return results C. handlerInterceptor [] interceptors = mappedHandler. getInterceptors (); get all interceptors and set interceptors. preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) is called one by one. D. call mv = ha. handle (processedRequest, response, mappedHandler. getHandler (); E. all interceptors use postHandle to call interceptor. postHandle (processedRequest, response, mappedHandler. getHandler (), mv); F.org. springframework. web. servlet. dispatcherServlet. render (ModelAndView, HttpServletRequest, HttpServletResponse) renders the page to check whether the mv is referenced, such as a string, and parses the corresponding view by 1.org. springframework. web. servlet. dispatcherServlet. resolveViewName (String, Map <String, Object>, Locale, HttpServletRequest) calls viewResolver. resolveViewName (viewName, locale); 2. view. render (mv. getModelInternal (), request, response)