Various layers in java web development

The web development process is divided into the following layers:

  • Dao layer
  • Entity layer
  • Service layer
  • Controller layer
  • view layer
Insert picture description here

xxx: on behalf of the company name
yyy: on behalf of the project name  d a o Layer interface~~~~~~~~~~~~~~~~~~~~~~~~~ Dao layer interface                           D A O layer connection port  d a o layer realization~~~~~~~~~~~~~~~~~~~dao layer realization                    D A O layer solid Online s e r v i c e layer interface ~~~~~~~~~~~~~~~~~~~~service layer interface                     S E R & lt V I C E layer connection port s e r v i c e layer realization~~~~~~~~~~~~~ service layer realization               S E R & lt V I C E layer solid Online w e b layer~~~~~~~~~~~~~~~~~~~~~~~web layer                         w e b layer Tool Bag~~~~~~~~~~~~~~~~~~~~~~~~ Tool Bag                          Work tool bag j a v a b e a n ~~~~~~~~~~~~~~~~~~javabean                   j a v a b e a n

1. Dao layer (persistence layer, data access layer)

Function: ①It is only responsible for interacting with the data of the database. The dao layer connects the background code and the database through @MyBatisDao under the framework of Mybatis. @Repository is used to mark the Dao layer of data access components.
②The DAO layer will first create the DAO interface, and then define the implementation class of the interface in the configuration file, and then you can call the DAO interface in the module to process the data business.
③The Dao layer is used to access the database to achieve data persistence (Save the data in the memory permanently to the hard disk).
Summary: The Dao layer is used to define the method interface, and then implement the interface method in the service layer and the serviceimpl layer, so as to achieve the purpose of operating the database. For the persistence operation of the database, the method statement is mainly for the database, and mainly realizes some addition, deletion, modification, and checking operations. The methods in Mybatis are mainly mapped to each other in xx.xml.

Insert picture description here code

Insert picture description here

can be seen, Dao file Li just defines the interface, and annotated @Repository

2. Controller layer (control layer, action layer)

Function: Control business logic

The Controller layer is responsible for the control of specific business module processes. The controller layer mainly calls the interfaces in the Service layer to control specific business processes. The configuration of the control also needs to be carried out in the configuration file.


3. Service layer (business layer, biz)

Function: The specific method used by the Service layer to implement the operation, including the code for the page operation module.
Service is used to store business logic processing and does not directly deal with the database. It provides method interfaces for the controller layer. The Service layer not only has interfaces but also interface implementation methods. The interface implementation methods are in the impl file.

Insert picture description here

Insert picture description here

Insert picture description here

4. Entity layer (entity layer, domain layer)

Function: The entity layer is used to define entities, define each attribute and the getter() and setter() methods of each attribute.
Entity layer: Used to store entity classes, basically consistent with the attributes in the database, and implement setter() and getter() method.

Insert picture description here

Insert picture description here

5.view layer

Function: This layer is closely related to the Controller layer and needs to be developed collaboratively. The view layer is mainly responsible for the representation of the front-end JSP page.

Controller, View层因为耦合度比较高,因而要结合在一起开发,但是也可以看作一个整体独立于前两个层进行开发。这样,在层与层之间我们只需要知道接口的定义,调用接口即可完成所需要的逻辑单元应用,一切显得非常清晰简单。