Dao layer and the service layer

DAO layer: DAO layer is mainly done work data persistence layer, is responsible for some liaison tasks with the database package in this, DAO design layer is first designed DAO interface, and then in the Spring define the implementation of this interface configuration file class, then you can call this interface module for data processing services, without concern for this particular interface implementation class is which class, it is very clear structure, DAO data source configuration layer, and the parameters are related to the database connection in the Spring to configure configuration file.  

  

Service Layer: Service layer is responsible for application design business logic module. Also the interface is designed first, and then its implementation design class, followed Spring of the configuration file is associated with its implementation. So that we can call in the application Service interface to business processes. Service business layer implementation, specific to the defined call to DAO layer interface, the encapsulation Service business logic layer in favor of the independence of the common business logic and reusability, the program is very simple.  

  

Controller Layer : Controller layer is responsible for controlling specific business modules process, in which this layer to be called Serice the interface layer to control business processes, control configuration also in the Spring carried the configuration file which, for specific business processes, will there are different controllers, the specific design process flow proceeds abstract induction may be designed flow module may subunit reused, so that not only the structure of the program becomes clear, also greatly reduces the amount of code.  

  

View layer this layer is combined with the control layer more closely, it is necessary to work together and combine the two IDF. View layer is mainly responsible for the reception jsp presentation of the page,   

  

DAO layer, Service layer these two levels can be developed separately, each coupling is very low, completely independent, such a model in the development of large projects in particular have an advantage, the Controller , View layer because the degree of coupling Compare high, and thus to develop together, but as a whole may be separate from the previous two layers developed. Thus, before the layers we just need to know the definition of the interface, to complete the call interface logic unit required for the application, everything is very clear and simple.  

  

DAO design and overall planning requires between tables, and the realization of one-design class.  

  

DAO interfaces defined in the method level are similar, it is up to us in the DAO operations for database access layer to the decision, the operation of the database, we basically use that to add, update, delete, query and other methods . Thus DAO layer which should substantially cover these methods corresponding to the operation. In addition, you can define some special way for database access custom.  

  

Service logic layer design  

  

Service layer is built DAO top layer, the establishment of DAO after layer can create Service layer and Service layer is the Controller under the layer, thus Service layer should call both DAO interface level, but also provides an interface to Controller type layer to make the call, it is just at a position intermediate layer. Each model has a Service interfaces each encapsulate a respective service processing method.  

  

In DAO some methods layers defined in the Service does not use the layer, then why in the DAO defined layer of it? This is determined by the needs of our definition of logic. DAO operating layer through an abstraction basically universal, therefore we define the DAO can be completed related methods defined layers when such benefits are of Service time does not need to be expanded again DAO layer modification, improve the scalability of the program.  

Code:

 

Guess you like

Origin www.cnblogs.com/lhq1996/p/11345547.html