Three-tier architecture:
The MVC design pattern of the same objectives : decoupling , improve code reuse ;
Difference : the two have different perspectives on project understanding
Three-layer composition:
1 Presentation layer (USL, Userm Show Layer view layer)
(1) Front desk:
Corresponds to the View in MVC , which is used to interact with the user and display the interface .
(Through web front-end technologies such as jsp, js, html, css, jquery, etc.)
Code location : WebContent
(2) Backstage:
Corresponding to the MVC Controller , used to control the jump and call the business logic layer .
(Implemented by Selvlet, SpringMVC, Struts, etc.)
2 Business Logic Layer (BLL, Business Logic Layer; Service layer)
Receive the request call of the presentation layer,
assemble the data access layer, logical operations (for example: add, delete, modify, check, for example: delete operation: first determine whether it exists, and then delete (check + delete))
3 Data Access Layer (DAL, Data Access Layer; Dao layer)
The operation of directly accessing the database , the atomic operation (addition, deletion
, modification, check) is located in the xxx.dao package
Three-tier optimization
(1). Join the interface
Suggestion for interface development : interface first - then implement class
(add interface in service and dao)
Naming conventions for interfaces and implementation classes:
① Interface interface :
Name : IStudentService, IStudentDao
② implementation class the implements :
Name : StudentServiceImpl, StudentDaoImpl
Interface : I, the package name of the entity class layer, IStudentService, IStudentDao
, the package : xxx.service xx.dao
Implementation class : For example,
the package where StudentServiceImpl and StudentDaoImpl are located : xxx.service.impl xx.dao.impl
When using an interface/implementation class , it is recommended to write:
interface x = new implementation class ();
Example: IStudentDao studentDao = new StudentDaoImpl();
(2) .DBUtil
General database helper class, which can simplify the amount of code in the Dao layer
The help class is generally recommended to be written in the xxx.util package