当前位置:网站首页>Mapper agent development
Mapper agent development
2022-07-29 04:54:00 【Chen Yuchen】
Mapper Agent development
Mapper Concept of agent development
We used to write code in a basic way , It also has the problem of hard coding ( Too high coupling ): as follows
// perform sql list<User>users = sqlSession.selectList("test.selectAll"); System.out.println(users);
This call selectList() Method pass parameters are in the mapping configuration file namespace.id value . This is not convenient for later maintenance . If you use Mapper The way of agency is as follows , Then the coupling degree can be reduced//3. Get proxy object UserMapper userMapper = SqlSession.getMapper(UserMapper.class); //4. Execution method , It's actually execution sql sentence List<User>users=userMapper.selectAll();
As can be seen from the above description Mapper The purpose of agency :
Reduced coupling
Simplify late execution SQL
stay MyBatis The official website is also recommended Mapper Agency mode .
Use Mapper Agency request
Use Mapper Agency mode , The following requirements must be met :
Definition and SQL Mapping files with the same name Mapper Interface , And will Mapper Interface and SQL The mapping files are placed in the same directory . Here's the picture
Set up SQL Mapping files namespace The attribute is Mapper The interface is fully qualified
<!--
namespace: The name space , Must be the fully qualified name of the corresponding interface
-->
<mapper namespace="com.itheima.mapper.UserMapper">
stay Mapper Define methods in interfaces , The method name is SQL In the mapping file sql Of the statement id, And keep the parameter type consistent with the return value type
边栏推荐
- What are the core features of the digital transformation of state-owned construction enterprises?
- Corresponding order of 18 and 25coco data of openpose and joint points
- 命令行交互工具(最新版) inquirer 实用教程
- 谷歌浏览器 打开网页出现 out of memory
- Data Lake: spark, a distributed open source processing engine
- Opencv environment construction
- ios面试准备 - objective-c篇
- C language implementation of three chess
- Solution to the fourth game of 2022 Hangzhou Electric Multi school league
- 安装spinning up教程里与mujoco对应的gym,报错mjpro150
猜你喜欢
The most comprehensive promotion plan for the launch of new products
Excel卡住了没保存怎么办?Excel还没保存但是卡住了的解决方法
Command line interactive tools (latest version) inquirer practical tutorial
MySQL定时调用预置函数完成数据更新
C language implementation of three chess
Opencv learning 1 (environment configuration)
excel怎么设置行高和列宽?excel设置行高和列宽的方法
使用近场探头和电流探头进行EMI干扰排查
Common current limiting methods
A little knowledge about management
随机推荐
JS daily question (10)
ios面试准备 - 网络篇
PHP判断用户是否已经登录,如果登录则显示首页,如果未登录则进入登录页面或注册页面
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
Climbing the pit of traffic flow prediction (III): using pytorch to realize LSTM to predict traffic flow
img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
钉钉对话框文子转换成图片 不能复制粘贴到文档上
Classes and objects (I)
MySQL定时调用预置函数完成数据更新
The most complete NLP Chinese and English stop words list in the whole station (including punctuation marks, which can be copied directly)
Conv1d of torch
UE 在场景或UMG中播放视频
SparkSql批量插入或更新,保存数据到Mysql中
Sguard64.exe ace guard client exe: frequent disk reading and writing, game jamming, and Solutions
The most comprehensive promotion plan for the launch of new products
office2010每次打开都要配置进度怎么解决?
Connection database time zone setting
< El table column> place multiple pictures
【无标题】
Go面向并发的内存模型