網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
MybatisPlus的UpdateWrapper和QueryWrapper的區(qū)別
查詢
測(cè)試代碼
@Test
public void testWrapper(){
LambdaQueryWrapper<Picture> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Picture::getEnterpriseCode, "FASTECH_DEV");
lambdaQueryWrapper.eq(Picture::getServerCode, "HL_FIRE_SAFE");
lambdaQueryWrapper.eq(Picture::getId, 296);
List<Picture> pictureList1 = pictureMapper.selectList(lambdaQueryWrapper);
System.out.println("QueryWrapper查詢出來的結(jié)果:" + pictureList1);
LambdaUpdateWrapper<Picture> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(Picture::getEnterpriseCode, "FASTECH_DEV");
lambdaUpdateWrapper.eq(Picture::getServerCode, "HL_FIRE_SAFE");
lambdaUpdateWrapper.eq(Picture::getId, 296);
List<Picture> pictureList2 = pictureMapper.selectList(lambdaQueryWrapper);
System.out.println("UpdateWrapper查詢出來的結(jié)果:" + pictureList2);
}
運(yùn)行結(jié)果
結(jié)論
對(duì)于查詢來說,兩者基本沒啥區(qū)別,但是一般查詢都是用QueryWrapper
修改
源數(shù)據(jù)
QueryWrapper測(cè)試代碼
@Test
public void testWrapper(){
LambdaQueryWrapper<Picture> lambdaQueryWrapper = new LambdaQueryWrapper<>();
Picture picture = new Picture();
picture.setPictureType("111");
lambdaQueryWrapper.eq(Picture::getId, 296);
pictureMapper.update(picture, lambdaQueryWrapper);
}
運(yùn)行結(jié)果
UpdateWrapper測(cè)試代碼
@Test
public void testWrapper(){
LambdaUpdateWrapper<Picture> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(Picture::getId, 296); // 表示需要修改數(shù)據(jù)的查詢條件,不設(shè)置默認(rèn)修改全部
lambdaUpdateWrapper.set(Picture::getPictureType, "222");
lambdaUpdateWrapper.set(Picture::getEnterpriseCode, null);
pictureMapper.update(null, lambdaUpdateWrapper);
}
運(yùn)行結(jié)果
結(jié)論
QueryWrapper可以根據(jù)id修改,也可以根據(jù)QueryWrapper構(gòu)建的查詢條件進(jìn)行修改,后者修改傳入一個(gè)映射實(shí)體,而且默認(rèn)不會(huì)把映射實(shí)體的空值映射到數(shù)據(jù)庫(kù),如果想將數(shù)據(jù)庫(kù)某個(gè)屬性置空,使用UpdateWrapper
原文鏈接:https://blog.csdn.net/qq_46601365/article/details/123628358
相關(guān)推薦
- 2022-04-04 前端小技巧:關(guān)閉瀏覽器時(shí)觸發(fā)事件
- 2022-05-19 python?字符串常用方法超詳細(xì)梳理總結(jié)_python
- 2023-01-31 Android如何實(shí)現(xiàn)一個(gè)DocumentProvider示例詳解_Android
- 2023-03-01 pyinstaller打包后偶爾出現(xiàn)黑窗口一閃而過的問題及解決_python
- 2022-11-26 R語(yǔ)言學(xué)習(xí)筆記之plot函數(shù)_R語(yǔ)言
- 2022-06-01 C語(yǔ)言?超詳細(xì)梳理總結(jié)動(dòng)態(tài)內(nèi)存管理_C 語(yǔ)言
- 2022-12-03 init?output?stream初始化輸出流源碼分析_Android
- 2022-11-15 Apache?Doris的Bitmap索引和BloomFilter索引使用及注意事項(xiàng)_Linux
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支