Detailed explanation of SpringMVC three-tier architecture

The engineering structure of Java SpringMVCd is generally divided into three layers. From top to top, it is the Model (model, database access layer)/Cotroller layer (control, logic control layer), View layer (view, page display layer), and the Model layer It is divided into two layers: the dao layer and the service layer. The main reason for the layering of the MVC architecture is to reduce the coupling between codes. The benefits of adopting a layered architecture are generally accepted that system layering is conducive to system maintenance and system expansion. It is to enhance the maintainability and scalability of the system.

For a framework like Spring, the (ViewWeb) presentation layer calls the control layer (Controller), the control layer calls (Service), and the business calls the database access layer (dao).

 

service layer : business layer, used to implement business logic. It can call dao layer or service layer, and return data object DO or business object BO. BO is usually converted and integrated from DO, and can contain attributes of multiple DOs, or only part of attributes of one DO. Usually for the sake of simplicity, if there is no need to convert, the service can also directly return DO. The external call (HTTP, RPC) method is also at this layer. For external calls, the service generally converts the DTO returned by the external call into BO. It focuses on business logic, and all database operations required are implemented through Dao. It is mainly responsible for some business processing, such as obtaining connections, closing database connections, and transaction rollbacks. Some complex logical business processing is placed in the service layer.

DAO layer : responsible for accessing the database for data operations, obtaining the result set, and then extracting and encapsulating the data in the result set into VO objects and returning them to the service layer. The data layer directly performs the read and write operations of the database, and returns the data object DO, which corresponds to the database table one by one. The role of Dao is to encapsulate access to the database: adding, deleting, modifying, and checking does not involve business logic, but only meets the requirements of obtaining specified data according to certain conditions.

Cotroller layer : called the control layer, the main function is to process the request sent by the user. Mainly handles external requests. Call the service layer, convert the BO/DO returned by the service layer into DTO/VO and encapsulate it into a unified return object to return to the caller. If the returned data is used for front-end template rendering, it returns VO, otherwise it generally returns DTO. Whether it is DTO or VO, some conversion and integration of data in BO/DO are generally performed.

View layer : called the display layer, mainly responsible for real data.

In actual development, the dao layer must first define its own operating standards, that is, standard interfaces, in order to decouple.

Guess you like

Origin blog.csdn.net/m0_67094505/article/details/127898526