There are nine components of SpringMVC

HandlerMapping

HandlerMapping is used to find handlers, which can be classes or methods. For example, each method labeled @requestMapping can be considered a Handler. The Handler is responsible for the actual request processing. After the request arrives, the HandlerMapping function is to find the Handler and Interceptor corresponding to the request.

HandlerAdapter (processor adapter)

A HandlerAdapter is an adapter. Because a SpringMVC Handler can be anything, as long as it handles the request. However, when sending requests to servlets, since servlets have method structures in the form of doService(HttpServletRequest REq,HttpServletResponse RESP), It is the responsibility of the HandlerAdapter to have the fixed Servlet processing method call the Handler for processing.

HandlerExceptionResolver

HandlerExceptionResolver Handles exceptions generated by the Handler. What it does is set up the ModelAndView according to the exception, which is then rendered by the rendering method, which renders the ModelAndView as a page.

ViewResolver

ViewResolver is a View resolver that resolves String View names and Locale views into View views. There is only one resolveViewName() method. As you can see from the method definition, the View name returned by the Controller layer as String viewName will eventually be resolved to View here.

The View is used to render the page, that is, it fills the template with the parameters and data returned by the program to generate an HTML file. The ViewResolver does two main things in this process: the ViewResolver finds the template to render (the first big thing) and the technology to use (the second big thing, which is essentially finding the type of view, such as JSP) and fills in the parameters. By default, the Spring MVC will automatically configure an InternalResourceViewResolver for us, is only for the type of JSP view.

RequestToViewNameTranslator

The ViewName RequestToViewNameTranslator the role of the components from the request. The ViewResolver will use this component to find the ViewName in the request, because the ViewResolver will use this component to find the ViewName in the request.

LocaleResolver

The resolveViewName method of the ViewResolver component takes two parameters: the view name and the Locale. LocaleResolver is used to resolve Locale from the request. For example, Chinese Locale is zh-CN, which indicates a region. This component is also the basis of the I18N.

ThemeResolver

ThemeResolver component is used to parse topics. A theme is a collection of styles, images, and the display effects they form. A set of themes in Spring MVC corresponds to a properties file, which holds all resources related to the current theme, such as images, CSS styles, and so on. Creating a theme is as simple as getting the resource ready, creating a new “theme name.properties” and putting the resource in your classpath, and then using it on your page.

The theme-related classes in SpringMVC are ThemeResolver, ThemeSource, and Theme. ThemeResolver is responsible for resolving the topic name from the request. The ThemeSource finds the specific topic based on the topic name. The abstraction is called Theme, which can be used to retrieve the topic and specific resources.

MultipartResolver

MultipartResolver used to upload the request, through the common request packaging into MultipartHttpServletRequest.

MultipartHttpServletRequest can getFile () method is direct access to the file. If you upload multiple files, you can also call getFileMap() to get a structure like Map<FileName, File>. The MultipartResolver encapsulates a common request and enables File uploading.

FlashMapManager

The FlashMap is used to pass parameters during redirection, such as when processing a user order. To avoid repeated submission, a POST request can be processed and then redirected to a GET request, which can be used to display information such as order details. This can avoid the problem of the user resubmitting the order, but where do you get the data to display the order information on this page?

If you don’t want to write parameters into the URL (not recommended), you can pass them through a FlashMap. Only need to be passed before the redirect data to request (by ServletRequestAttributes. GetRequest () method) attribute OUTPUT_FLASH_MAP_ATTRIBUTE, Spring will then automatically set it to the Model in the Handler after the redirect, and the order information can be retrieved directly from the Model on the page that displays it. The FlashMapManager is used to manage FalshMap.