Layering of SpringBoot framework (View layer, Controller layer, Service layer, Mapper layer, pojo layer)

The SpringBoot framework is generally divided into View layer, Controller layer, Service layer, Mapper layer, and pojo layer.

  1. View layer: The view layer displays the page to the user according to the received data

  2. Controller layer: Respond to user needs, decide what view to use, and what data needs to be prepared for display. The Controller layer is responsible for front-end and back-end interaction, receiving front-end requests, calling the Service layer, receiving the data returned by the Service layer, and finally returning specific data and pages to the client

  3. Service layer: Service layer can also be divided into three aspects

(1) Interface: used to declare methods

(2) Inheritance implements the interface

(3) impl: implementation of the interface (a file that integrates mapper and service)

The Service layer stores business logic processing, and has some operations related to database processing, but it does not directly deal with the database. There are interfaces and interface implementation methods. In the impl implementation interface class, the mapper class needs to be imported, and the mapper layer directly operates with the database. of.

4. Mapper layer: It can also be called DAO layer. It is the interface of database CRUD. It only has the method name. It is specifically implemented in the mapper. Provides CRUD operations)

5. The mapper.xml file in the src/main/resource folder stores the real database CRUD statements

6. Pojo layer: store entity classes, which are basically consistent with the attributes in the database, generally including getter, setter, and toString methods (when the plug-in lombok is not used).

It can be seen that the Service layer is above the Mapper layer and below the Controller layer. It not only calls the Mapper interface, but also provides the interface for the Controller layer.

After layering, there is a clear division of labor between accessing the database and performing services, and there is no need to modify the Mapper layer to modify the requirements of the Service. If there is a new requirement for accessing the database, it only needs to be modified at the Mapper layer.

at last

I know that most junior and middle-level Java engineers want to improve their skills, and they often try to grow by themselves or enroll in classes. However, the tuition fees of nearly 10,000 yuan for training institutions are really stressful. The effect of self-study is inefficient and long, and it is easy to hit the ceiling and stagnate in technology!

Therefore, I collected and sorted out a " Complete Set of Learning Materials for Java Development " and gave it to everyone. The original intention is also very simple, that is, I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.

The editor has encrypted: aHR0cHM6Ly9kb2NzLnFxLmNvbS9kb2MvRFVrVm9aSGxQZUVsTlkwUnc==For security reasons, we encode the website through base64, and you can decode the URL through base64.

Guess you like

Origin blog.csdn.net/m0_67393827/article/details/126774237