[Knowledge] The difference between the View layer, the Controller layer, the Server layer, and the Dao layer and the corresponding functions

1, Dao layers

The Dao layer mainly does the work of the data persistence layer, and some tasks responsible for contacting the database are encapsulated here.
Dao layer design: First, design the interface of the dao layer, and then define the implementation class of this interface in the Spring configuration file, and then you can call this interface in the module to process the data business, without worrying about the specifics of this interface Which class is the implementation class, the structure is very clear. The data source configuration of the dao layer and the related database connection parameters are configured in the Spring configuration file.

2. Service layer

The Service layer is mainly responsible for the application logic application design of business modules.
Service layer design: The same is to first design the interface, then design its implementation class, and then configure its implementation in the Spring configuration file. In this way, we can call the service interface in the application for business processing. The business reality of the service layer specifically calls the defined dao layer interface to encapsulate the service layer business logic to facilitate the independence and reusability of the general business logic. The program is very concise.

3. Controller layer

The Controller layer is responsible for the control of the specific business module process. In this layer, the interface of the service layer is called to control the business process. The configuration of the control is also carried out in the Spring configuration file. For specific business processes, there will be different Controller. Our specific design process can abstract the process and design sub-unit process modules that can be reused. This not only makes the program structure clear, but also greatly reduces the amount of code.

4. View layer

The view layer and the control layer are closely integrated, and the two need to be combined for collaborative development. The view layer is mainly responsible for the display of the front jsp page.

5. The relationship between them:

The Service layer is built on the Dao layer. After the Dao layer is established, the Service layer can be established. The Service layer is under the Controller layer. Therefore, the Service layer should both call the Dao layer interface and provide the interface to The Controller layer class is used to call, which is just in the middle layer. Each model has a Service interface, and each interface encapsulates its own business processing method.

Personal understanding:

The Controller layer is called the control layer, responsible for request forwarding, accepting the parameters from the page, passing it to the Service for processing, receiving the return value, and passing it to the page. It is used for interface exposure.

The Service layer is called the service layer, which is called a service. A rough understanding is to re-encapsulate one or more DAOs and encapsulate them into a service. That is, the service layer is used for logic processing, and the service layer focuses on business logic, and all database operations required in it are implemented through Dao.

The Dao layer is called the data access layer, and the full name is data access object. It belongs to a relatively low-level, relatively basic operation, specifically for adding, deleting, modifying and checking a table or entity. It does not involve business logic, but only meets certain conditions. Requirements for obtaining the specified data.
The View layer is called the presentation layer. This layer is closely integrated with the control layer and requires the two to be combined to work together. The View layer is mainly responsible for the representation of the front-end JSP page.
The presentation layer (View\Web) calls the control layer (Controller), the control layer (Controller) calls the business layer (Service), and the business layer (Service) calls the data access layer (Dao)

Dao is table-oriented, Service is business-oriented. In the back-end development, all tables are designed in the database first, and then the Dao layer is designed for each table, and then the Dao layer is further encapsulated into a Service layer according to the specific business logic, which is provided as a service externally.

Guess you like

Origin blog.csdn.net/qq_51808107/article/details/113331377