Detailed interpretation of the SpringMVC framework

Table of contents

1. What is the SpringMVC framework?

2. Advantages of the SpringMVC framework

3. How to create a SpringMVC project

4. Steps of SpringMVC development

4.1 Detailed introduction of the DispatcherServlet class (important)

 5. web.xml configuration DispatcherServlet (central scheduler)

 6. Configuration of SpringMVC.xml file

 7. SpringMVC project startup process


1. What is the SpringMVC framework?

Answer: The SpringMVC framework is based on the Spring framework. In fact, the SpringMVC framework is a module of the Spring framework, specializing in Web development. It can be understood as: SpringMVC is an upgrade of the Servlet learned earlier.

We use Servlet to do web development is the most primitive form, but it is also the core. In the learning process of Spring, we let this custom class inherit the HTTPServlet class through a custom class, and rewrite the methods such as doGet(), doPost() and configure the Servlet in the web.xml file. Only in this way can the request be processed. Although after getting proficient, I feel that there is nothing wrong with it, but the overall steps are still too cumbersome.

Then we developed the SpringMVC framework. This SpringMVC framework not only implements the functions of Servlet, but also adds some other more useful functions on the basis of Servlet, making our Web development easier and more concise.

2. Advantages of the SpringMVC framework

First of all, SpringMVC, also known as Spring Web MVC, was released after Spring3.0. Then his advantages are as follows:

  • Based on MVC architecture, with clear division of labor and decoupling
  • Easy to understand, quick to use, and simple to use.
  • It is lightweight, the jar package is small, and does not depend on specific interfaces and classes
  • As part of Spring, Spring's IOC and AOP core technologies can also be used to facilitate the integration of Mybatis

3. How to create a SpringMVC project

 4. Steps of SpringMVC development

Notice:

Whether to use the DispatcherServlet in step 3 above determines whether your project is the standard of SpringMVC.

So about the DispatcherServlet class, we will introduce it in detail.

4.1 Detailed introduction of the DispatcherServlet class (important)

DispatcherServlet, called the central scheduler, also known as the front controller, is to call other controller objects, and then the result is returned to the user by DispatcherServlet itself. We need to know that the @Controller annotation class used in the SpringMVC framework is not a Servlet class; the object created using the @Controller annotation is just the most common object, but the SpringMVC framework gives it some additional functions. We just treat it as a Servlet, but he is not a Servlet, he just has some functions related to Servlet.

From the following point, it can be confirmed that the class where @Controller is located is not a Servlet.

We all know that the jsp page interacts directly with the Servlet, but the jsp page cannot directly interact with the class where @Controller is located. Jsp can only forward the request to the class where @Controller is located through DispatcherServlet.

The following will give the inheritance relationship diagram of Servlet and DispatcherServlet

 5. web.xml configuration DispatcherServlet (central scheduler)

 6. Configuration of SpringMVC.xml file

 7. SpringMVC project startup process

Guess you like

Origin blog.csdn.net/weixin_44362089/article/details/127462157