当前位置:网站首页>Relationship among controller, service and Dao
Relationship among controller, service and Dao
2022-06-29 17:51:00 【Two rasps!】
List of articles
Preface
Tips : Here you can add the general content to be recorded in this article :
I mentioned the code writing process in the last article
1、 Draw page , To write A.jsp
2、 Write the customer request address , Initiate customer request , To write B.jsp
3、 Write control layer code (xxxController.java)
4、 Write business layer code (xxxService.java)
5、 Write data persistence layer code (xxxDao.java and xxxDao.xml)
————————————————————————————————————————
Today, let's talk about their relationship
Tips : The following is the main body of this article , The following cases can be used for reference
One 、model
model Layer is the database entity layer , Also known as entity layer ,pojo layer
Generally, a table in a database corresponds to an entity class , Class attributes are the same as table fields One A corresponding .

Generally, the entity layer will automatically generate Getter、Setter、to String Methods and construction methods
Eclipse Quickly add Getter、Setter Method

Eclipse Quickly add to String Method

Eclipse Quickly add construction methods in

idea Quickly add Getter、Setter Method
Here we borrow the classic dynamic pictures on the Internet :
idea Quickly add to String Method


idea Quickly add construction methods in
Here we borrow the classic dynamic pictures on the Internet :
Two 、Controller Business control layer
controller The function of the layer is request and response control .
controller The layer does not allow direct operation of the database !controller The layer is responsible for the interaction between the front end and the back end , He is a bridge , Set up the communication between the outside world and the business layer , Accept front-end requests , call Serice Layer to control the business process , receive service The data returned by the layer , Finally, return the specific page and data to the client .
It's like a company's front-line staff wants to see the feedback from the company's boss , So the front-line staff will communicate their purpose through the manager and the boss , The manager then asked the boss for instructions , Finally, the feedback from the boss is transferred to the front-line staff .
in addition ,Service It will play a great role in future distributed deployment , It's like a waiter , Which table of guests need to order , Just call the waiter ! Corresponding , What kind of business does the outside world need to complete , Just through Controller To call different Service, Here's the thing to remember ,Controller Just a middleman or forwarder , Should not be in Controller Exposed in Service Business logic of , Instead, it should be forwarded directly Service Business processing results !
3、 ... and 、Dao Database persistence layer ;
dao Layers are also called mapper layer .
dao Layer is to deal with the database , Some of the tasks responsible for contacting the database are encapsulated here ,dao The layer sends data to the database SQL sentence , Complete the task of data addition, deletion, modification and query .
dao The design of the layer is first of all design dao The interface of , And then in Spring The implementation class of this interface is defined in the configuration file of , Then you can call this interface in the module for data service processing. , You don't need to worry about which implementation class of this interface is , Very clear structure ,DAO Data source configuration for layer , And the database connection parameters are Spring Configuration in the configuration file .
DAO The master plan of design needs and the table of design , And implementation classes One A corresponding .
DAO The methods in the interface defined by layer are similar , It's up to us to DAO Layer to the database access operation to determine , Operation on Database , What we basically need to use is to add , Delete , to update , Query methods .
thus DAO The layer should basically cover the operations corresponding to these methods . besides , You can define some custom special database access methods .
Four 、Service The business layer / Service layer ;
service Layers are built on dao Above the layers , Established dao You can set up after layer Service layer , and service Layer is again controller Below that layer ,service Layer calling dao Layer interface , But also provide an interface to controller Layer to call , It's just in the middle of a layer .
All internal business logic will be handled here ,
For example, user's addition, deletion, modification and query , Or send a verification code or email , Or do a lottery and so on , Will be in service In the middle of ,service Layer calls dao Layer interface , receive dao The data returned by the layer , Complete the basic function design of the project , therefore Dao Layers are essential ;
Every model has one service Interface , Each interface encapsulates its own business processing method .
summary
DBUtil.java
General , One Controller Corresponding to one Service, One Service Corresponding to one Dao, One Dao Corresponding to a database table ,
Of course, depending on the complexity of the project or business , One Controller You can call multiple Service, And one Service You can also call multiple Dao, however Controller Layer does not allow intermodulation ,Service Layers also do not allow intermodulation ,
Namely AController Can't call directly BController
AService You can't call directly BService, Follow the principle of high cohesion and low coupling
Part of the content of this article draws on the articles of other bloggers , But I forgot which article , I would like to thank the blogger of the original article
边栏推荐
- lodash深拷贝使用
- 3h精通OpenCV(六)-图像堆叠
- Visual studio plug-in coderush officially released v22.1 -- visual tool for optimizing debugging
- selenium 文件上传方法
- Detailed introduction and Simulation of bitmap
- Serial port experiment based on stm32f103zet6 library function
- [try to hack] cookies and sessions
- Parental delegation mechanism
- Split palindrome string [dp + DFS combination]
- DevCloud加持下的青软,让教育“智”上云端
猜你喜欢

How to use the chart control of the b/s development tool devextreme - customize the axis position?

MATLAB 最远点采样(FPS)

Premature end of script headers 或 End of script output before headers

YoloV6+TensorRT+ONNX:基于WIN10+TensorRT8+YoloV6+ONNX的部署

VB. Net read / write NFC ntag tag source code

SRM供应商协同管理系统功能介绍

Parental delegation mechanism

Issue 42: is it necessary for MySQL to have multiple column partitions

Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly

基于注解和拦截器防止表单重复提交
随机推荐
Custom handlerinterceptor interceptor for user authentication
Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]
DevCloud加持下的青软,让教育“智”上云端
人脸识别4-百度商用方案调研
[网鼎杯 2020 青龙组]AreUSerialz
位图的详细介绍及模拟实现
给定一个数在序列中求最大异或值(01字典)
Timer interrupt experiment based on stm32f103zet6 library function
SSH协议学习笔记
ISO 32000-2 国际标准7.7
Web Scraping with Beautiful Soup for Data Scientist
软件快速交付真的需要以安全为代价吗?
2022春夏系列 KOREANO ESSENTIAL重塑时装生命力
/usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
双亲委派机制
3h精通OpenCV(六)-图像堆叠
selenium 组合键操作
基于STM32F103ZET6库函数PWM输出实验
What is a SCM system? What are the advantages of a supply chain management system?
字典树(随学)