SpringMVC
1 SpringMVC 0XML configuration principle
SPI Servlet version 3.0 put forward the new specification, through the root directory of the meta-inf/services/javax.mail Servlet. ServletContainerInitializer directory to set up a file
Spring will pass in a Set at the onStartup startup that incorporates all the methods that need to be called by Tomcat
Web containers (Tomcat, JBOSS, Jetty…)
ServletContext supports Web component registration
Web components: Filter, Servlet, and Listener
The DispatcherServlet registers with the servletContext
2. Spring MVC execution process
Analyze the source reading process: The DispatcherServlet inherits from the Servlet class. The DispatcherServlet inherits from the FrameworkServlet and calls doGet and doPost It’s going to call doService it’s going to call doDispatch() inside of doService it’s going to call doDispatch()
DispatcherServlet intercepts requests :doDispatch() –>
-
CheckMultipart (request) Checks whether there are attached files
-
GetHandler (processRequest) distributes the request
- Spring scan requests define Map collections
- Get all classes annotated with @Controller
- Reflection traverses all method objects in a class
- Determine if the method is annotated with @requestMapping
- Put the value of the @RequestMapping annotation as the Key of the map set
- According to the users to send requests, get in the request URI (url: http://localhost:8080/test.do URI: / test. Do)
- Use the URI as the Key of the map to obtain the corresponding method from the map
-
HaddlerMapping processes the mapper to obtain the corresponding request
-
HaddlerAdapter adapter
The controller is defined
Two types
- BeanName
- @Controller
Three kinds of implementation
- @Controller
- implements HttpRequestHandler
- implements Controllter
-
Invoke the Handler
The argument handler determines which argument handler needs to be called
Custom parameter handlers
-
Returns the ModeAndView object
-
ViewResolver
The DispatcherServlet calls the ViewResolver to look up the view by its name and return the correct view
-
Rendering the view