SpringMVC foundation - what is springMVC

basic concept

three-tier architecture

Our development architecture is generally based on two forms, one is C/S architecture, that is, client/server, and the other is B/S architecture, that is, browser server. In JavaEE development, almost all of them are based on B/S architecture. Then in the B/S architecture, the standard three-tier architecture of the system includes: presentation layer, business layer, and persistence layer. The three-tier architecture is used a lot in our actual development, so the cases in our courses are also designed based on the three-tier architecture. In the three-tier architecture, each layer performs its own duties. Next, let's talk about what each layer is responsible for:

Presentation layer : This is what we often call the web layer. It is responsible for receiving client requests and responding to the client. Usually, the client uses the http protocol to request the web layer, and the web needs to receive the http request and complete the http response. The presentation layer includes a display layer and a control layer: the control layer is responsible for receiving requests, and the display layer is responsible for displaying results. The presentation layer relies on the business layer, and generally calls the business layer for business processing upon receiving a client request, and responds to the client with the processing result. The design of the presentation layer generally uses the MVC model. (MVC is the design model of the presentation layer and has nothing to do with other layers)

Business layer : This is what we often call the service layer. It is responsible for business logic processing and is closely related to the needs of our development projects. The web layer depends on the business layer, but the business layer does not depend on the web layer. The business layer may rely on the persistence layer during business processing, and transaction consistency needs to be guaranteed if the data is to be persisted. (That is to say, transactions should be placed in the business layer to control)

Persistence layer : That is what we often call the dao layer. Responsible for data persistence, including the data layer, namely the database and the data access layer. The database is the carrier for data persistence. The data access layer is the interface for the interaction between the business layer and the persistence layer. The business layer needs to persist data through the data access layer to in the database. In layman's terms, the persistence layer interacts with the database, and checks the database tables for deletions, modifications, and changes.

MVC model

The full name of MVC is Model View Controller, which is the abbreviation of model (model)-view (view)-controller (controller), and it is a pattern for designing and creating the presentation layer of Web applications. Each part of MVC has its own role:

Model (model) : Usually refers to our data model. The role is generally used to encapsulate data.

View (view) : usually refers to our jsp or html. The role is generally to display data. Usually views are created from model data.

Controller (controller) : is the part of the application that handles user interaction. The role is generally to process program logic. Compared with the first two, it is not very easy to understand. Here is an example: We want to save a user's information, which includes name, gender, age and so on. At this time, the form input requires that the age must be an integer between 1 and 100. Name and gender cannot be empty. And fill the data into the model.
At this time, in addition to the verification of js, the server should also verify the accuracy of the data, so the verification is what the controller should do. When the verification fails, the controller is responsible for displaying the error page to the user. If the verification is successful, the controller is also responsible for filling the data into the model, and calling the business layer to achieve complete business requirements.

Guess you like

Origin blog.csdn.net/qq_44660367/article/details/108909204