How do I configure Spring mvc

Spring is a web framework based on the MVC design concept provided by the view plane and is currently one of the most popular MVC frameworks.

After Spring 3.0, it completely surpasses Struts2. Spring MVC uses a number of MVC annotations to make POJO (Java Bean) a controller for processing requests without implementing interfaces.

Spring MVC supports REST-style URL requests and uses a loosely coupled pluggable component structure.

The characteristics of Spring MVC are as follows:

Clear division of roles

Powerful and straightforward configuration method

Customizable, non-invasive controller

Reusable business code

Customizable binding and validation

Customizable handler mapping and view resolution

Flexible model conversion

Customizable localization and topic analysis

The processing flow of Spring MVC:

1. The user sends a request to the server, and the Spring front-end control, Servelt DispatcherServlet, collects the request.
2. DispatcherServlet parses the request URL to get the requested resource identifier (URI). Then call HandlerMapping according to the URI to get all of the related objects configured by the handler (including the handler object and the interceptor corresponding to the handler object) and finally return it as a HandlerExecutionChain object.
3. DispatcherServlet selects a suitable HandlerAdapter according to the handler received. (Note: If the HandlerAdapter is successfully obtained, the preHandler (...) method of the Interceptor is executed at this point.)
4. Extract the model data in the request, enter the handler input parameters and start executing the handler (controller). As you fill in the handler input parameters according to your configuration, Spring will help you do some extra work:
HttpMessageConveter: Convert the request message (e.g. Json, XML, etc.) to an object and convert the object to the specified response message
Data Conversion: Perform a data conversion for the request message. B. String converted to integer, double, and so on.
Data roots: Format the request message. B. converting a string to formatted numbers or formatted dates, etc.
Data verification: Check the validity of the data (length, format, etc.) and save the verification result in BindingResult or Error
5. After the handler runs, it returns a ModelAndView object to DispatcherServlet.
6. According to the returned ModelAndView, select a suitable ViewResolver (must be a ViewResolver registered in the Spring container) and send it back to DispatcherServlet.
7. ViewResolver combines the model and view to render the view
8. Return the rendering result to the client.

The process of using Spring MVC:
1. Add JAR package:

2. Configure dispatcherServlet in web.xml

3. Add the Spring MVC configuration file in servlet-mvc.xml
4. Write the request handler:
5. Write the view

ANT style: URL matching can be fuzzy matching

?: Represents any character

*: Represents any number of characters (0,1,) **: Matches any multilayer path:

Add static resources to the page, three configuration methods:

1. Configure in web.xml

2. Configure in servlet-mvc.xml 3. Configure in servlet-mvc.xml Of the three methods, method 3 is the best. It only needs to be configured once