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

    1. Spring scan requests define Map collections
    2. Get all classes annotated with @Controller
    3. Reflection traverses all method objects in a class
    4. Determine if the method is annotated with @requestMapping
    5. Put the value of the @RequestMapping annotation as the Key of the map set
    6. According to the users to send requests, get in the request URI (url: http://localhost:8080/test.do URI: / test. Do)
    7. 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

    1. BeanName
    2. @Controller

    Three kinds of implementation

    1. @Controller
    2. implements HttpRequestHandler
    3. 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