DAO layer, Service layer, controller layer, view layer introduction

Source: Internet
Author: User

from: http://jonsion.javaeye.com/blog/592335 DAO LayerDAO layer is mainly to do the data persistence layer of work, responsible for the database to contact some of the tasks are encapsulated here, the DAO layer is designed to design the DAO interface, and then define the implementation class of this interface in the spring configuration file, then you can call this interface in the module for Data service processing, Instead of worrying about which class the specific implementation class of this interface is, it appears that the structure is very clear, the data source configuration of the DAO layer, and the parameters about the database connection are configured in spring's configuration file.

Service Layer The service layer is primarily responsible for the logic application design of the business module. The same is to first design the interface, then design its implementation of the class, and then the spring configuration file to configure its implementation of the association. This allows us to invoke the service interface in the application for business processing. Service layer of the business implementation, specifically to call to the defined DAO layer interface, encapsulating the service layer of business logic to facilitate the independence of general business logic and reuse, the program appears very concise.

controller layer Controller layer is responsible for the specific business module process Control, in this layer to invoke the Serice layer interface to control the business process, the configuration of the control is also in the spring configuration file, for the specific business process, there will be different controllers, In our specific design process, we can abstract the process, design a reusable sub-unit process module, which not only makes the program structure clear, but also greatly reduces the amount of code.

View Layer This layer is closely combined with the control layer, which needs to be combined to work together. The view layer is primarily responsible for the presentation of the foreground JSP page,

DAO layer, service layer these two levels can be developed independently, mutual coupling degree is very low, can completely independent, such a pattern in the process of developing large projects, especially has the advantage, Controller,view layer because of high coupling degree, so to combine to develop together, But it can also be seen as a whole that is developed independently of the first two layers. In this way, before the layer and layer we just need to know the definition of the interface, call the interface to complete the required logic unit application, everything seems very clear and simple.

The overall planning of DAO design requires a one by one correspondence between the design table, and the implementation class.

DAO layer defines the interface in the same way, this is by the DAO layer on the database access to the operation of the decision, the operation of the database, we basically need to use is new, update, delete, query and other methods. Therefore, the DAO layer should basically cover the corresponding operation of these methods. In addition, you can define some custom special methods for accessing the database.

Service Logic Layer Design

The service layer is built on the DAO layer, and the service layer can be established after the DAO layer is established, and the service layer is under the controller layer, so the service layer should call the interface of the DAO layer. It also provides the interface to the controller layer's class to make the call, which is just in the middle of an intermediate position. Each model has a service interface, each of which encapsulates its own business processing methods.

Some of the methods defined in the DAO layer are not used at the service layer, so why do you define it in the DAO layer? This is determined by the logic of the requirements we define. DAO layer Operations After abstraction is basically universal, so we can define the DAO layer when the relevant method is defined, the advantage is that the service is extended without the need to modify the DAO layer, improve the program extensibility.

DAO layer, Service layer, controller layer, view layer introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.