当前位置:网站首页>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
边栏推荐
- Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
- Set double click to run the jar file
- SSH protocol learning notes
- What is a SCM system? What are the advantages of a supply chain management system?
- Top 30 open source software
- Matlab farthest point sampling (FPS)
- MATLAB 最远点采样(FPS)
- mysql. What is the concept of sock
- Sword finger offer 13 Robot range of motion (BFS)
- Maidong Internet won the bid of Dajia Insurance Group
猜你喜欢

Selenium upload file

What is the MySQL query view command

How to create a virtual image

Have you grasped the most frequently asked question in the interview about massive data processing?

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

面试中问最常问的海量数据处理你拿捏了没?

VB.Net读写NFC Ntag标签源码

位图的详细介绍及模拟实现
![[webdriver] upload files using AutoIT](/img/69/8c27626d515976b47f1df4831d09c8.png)
[webdriver] upload files using AutoIT
![填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]](/img/33/bda0a898bfe3503197026d1f62e851.png)
填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]
随机推荐
Two controller layer interface authentication methods
Face recognition 4- research on Baidu commercial solutions
ISO 32000-2 international standard 7.7
PWM output experiment based on stm32f103zet6 library function
The R language inputs the distance matrix to the hclust function for hierarchical clustering analysis. The method parameter specifies the distance calculation method between two combined data points,
Visual studio plug-in coderush officially released v22.1 -- visual tool for optimizing debugging
R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
ISO 32000-2 国际标准7.7
How MySQL queries character set codes of tables
【目标跟踪】|stark配置 win otb
字典树(随学)
迈动互联中标大家保险集团
/usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
Force deduction daily question 06.29 add two numbers
VB. Net read / write NFC ntag tag source code
SCM系统是什么?供应链管理系统有哪些优势?
Segment tree and tree array template (copy and paste are really easy to use)
Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what
How to use the chart control of the b/s development tool devextreme - customize the axis position?
关于日期相加减问题