In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about the sample analysis of the dao layer, the service layer, and the controller layer in MVC. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Dao layer, service layer and controller layer 1, dao layer of MVC
The dao layer mainly does the work of the data persistence layer, and some tasks responsible for communicating with the database are encapsulated here. The design of the dao layer is to first design the interface of the dao layer, then define the implementation class of this interface in the configuration file of Spring, and then call this interface in the module to process the data business, regardless of which class is the specific implementation class of this interface. The structure is very clear. The data source configuration of the dao layer, as well as related database connection parameters, are configured in the Spring configuration file.
2. Service layer
Service layer is mainly responsible for the application logic application design of business module. Similarly, the interface is designed first, and then its implementation class is designed, and then the association of its implementation is configured in the configuration file of Spring. In this way, we can call the service interface in the application for business processing. The business of the service layer is pragmatic, specifically to call the defined dao layer interface, encapsulating the service layer business logic is conducive to the independence and reuse of the general business logic. The program is very concise.
3. Controller layer
The controller layer is responsible for the control of the specific business module process. In this layer, the interface of the service layer is called to control the business process. The configuration of the control is also carried out in the configuration file of Spring. For the specific business process, there will be different controllers. Our specific design process can abstract the process and design a sub-unit process module that can be reused. This not only makes the program structure clear, but also greatly reduces the amount of code.
4. View layer
The combination of view layer and control layer is relatively close, so it is necessary to combine them to develop cooperatively. The view layer is mainly responsible for the display of the foreground jsp page.
5. The relationship between them
The Service layer is built on top of the Dao layer, and the Service layer can only be established after the DAO layer is established, while the Service layer is under the Controller layer, so the Service layer should not only call the interface of the DAO layer, but also provide the interface to the classes of the Controller layer for invocation, which happens to be in the position of an intermediate layer. Each model has a Service interface, and each interface encapsulates its own business processing methods.
Some notes on dao layer / Mapper layer 1, BaseMapper
After inheriting this interface, Mapper can get the CRUD function without writing a mapper.xml file.
Mybatis-Plus is a Mybatis dynamic SQL automatic injection Mybatis add, delete, modify and check CRUD operation middleware to reduce your development cycle and optimize dynamic maintenance of XML entity fields.
CRUD: add, change and delete, that is, create/read/update/delate is mainly used to describe the basic operational functions of the database or persistence layer in the software system.
2. @ mapper
Advantages of using interface annotations:
It is convenient to write mapping statements quickly.
Disadvantages of using interface annotations:
It is suitable for relatively simple configuration, but the interface cannot be handled when it is too complex.
Can't use dynamic SQL, it's a bit of a chicken rib.
Thank you for reading! This is the end of this article on "sample analysis of dao layer, service layer and controller layer in MVC". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.