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

com.xxx.yyy.dao  d a o Layer interface~~~~~~~~~~~~~~~~~~~~~~~~~ Dao layer interface                           D A O layer connection port
com.xxx.yyy.dao.impl  d a o layer realization~~~~~~~~~~~~~~~~~~~dao layer realization                    D A O layer solid Online
com.xxx.yyy.service s e r v i c e layer interface ~~~~~~~~~~~~~~~~~~~~service layer interface                     S E R & lt V I C E layer connection port
com.xxx.yyy.service.impl s e r v i c e layer realization~~~~~~~~~~~~~ service layer realization               S E R & lt V I C E layer solid Online
com.xxx.yyy.web w e b layer~~~~~~~~~~~~~~~~~~~~~~~web layer                         w e b layer
com.xxx.yyy.util Tool Bag~~~~~~~~~~~~~~~~~~~~~~~~ Tool Bag                          Work tool bag
com.xxx.yyy.domain 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


UserDao.java 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.

Action是管理业务(Service)调度和管理跳转的。
Service是管理具体的功能的。
Action只负责管理,而Service负责实施。

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.

注:Dao层,Service层这两个层都可以单独开发,互相的耦合度很低,完全可以独立进行,这样的一种模式在开发大项目过程中尤其有优势
Controller, View层因为耦合度比较高,因而要结合在一起开发,但是也可以看作一个整体独立于前两个层进行开发。这样,在层与层之间我们只需要知道接口的定义,调用接口即可完成所需要的逻辑单元应用,一切显得非常清晰简单。

reference