SpringMVC (1) What is SpringMVC

1. Review MVC

1.1. What is MVC
MVC is an abbreviation of Model, View, and Controller, and is a software design specification.

It is a method of separating business logic, data, and display to organize code.

The main function of MVC is to reduce the two-way coupling between view and business logic.

MVC is not a design pattern, MVC is an architectural pattern. Of course, there are differences between different MVCs.

Model

The data model provides the data to be displayed, so it contains data and behavior. It can be considered as a domain model or JavaBean component (including data and behavior), but it is generally separated now: Value Object (data Dao) and service layer (behavior Service) ). That is, the model provides functions such as model data query and model data status update, including data and business.

View

Responsible for the display of the model, which is generally the user interface we see and what customers want to see.

Controller

Receive user requests, entrust to the model for processing (state change), and return the returned model data to the view after processing, and the view is responsible for displaying. In other words, the controller does the job of a dispatcher.

2. SpringMVC execution principle

Insert picture description here

The picture shows a relatively complete flow chart of SpringMVC. The solid line represents the technology provided by the SpringMVC framework and does not need to be implemented by the developer, and the dotted line represents that it needs to be implemented by the developer.

Briefly analyze the execution process

  1. DispatcherServlet represents the front controller and is the control center of the entire SpringMVC. The user sends a request, and the DispatcherServlet receives the request and intercepts the request.

We assume that the requested url is: http://localhost:8080/SpringMVC/hello

The above URL is split into three parts:

http://localhost:8080 server domain name

SpringMVC deployed on the web site on the server

hello means controller

Through analysis, the above url is expressed as: request the hello controller of the SpringMVC site on the server localhost:8080.

  1. HandlerMapping is the processor mapping. DispatcherServlet calls
    HandlerMapping, HandlerMapping finds Handler according to the request url.
  2. HandlerExecution represents a specific Handler, its main function is to find the controller according to the url, as the above url is searched for the controller: hello.
  3. HandlerExecution passes the parsed information to DispatcherServlet, such as parsing controller mapping and so on.
  4. HandlerAdapter represents the processor adapter, which executes the Handler according to specific rules.
  5. Handler lets specific Controller execute.
  6. Controller returns specific execution information to HandlerAdapter, such as ModelAndView.
  7. HandlerAdapter passes the view logical name or model to DispatcherServlet.
  8. DispatcherServlet calls the view resolver (ViewResolver) to resolve the logical view name passed by the HandlerAdapter.
  9. The view resolver passes the resolved logical view name to DispatcherServlet.
  10. DispatcherServlet calls specific views based on the view results parsed by the view parser.
  11. The final view is presented to the user.

Guess you like

Origin blog.csdn.net/weixin_45925906/article/details/112910453