網(wǎng)站首頁 編程語言 正文
MyBatis-plus 通過 wrapper.and方法給sql添加額外的查詢條件
MyBatis-plus方法:
public Children and(boolean condition, Consumer<Children> consumer) {
return this.and(condition).addNestedCondition(condition, consumer);
}
一、需求:如果用戶穿插了查詢參數(shù),就給sql附加條件(當(dāng)然,這個條件可以是復(fù)雜的條件),否則查詢不用帶上條件。
示例:
@org.junit.Test
public void test() {
String name = "狗哥";
QueryWrapper<Animal> wrapper = new QueryWrapper<>();
wrapper.and(StringUtils.isNotBlank(name),item->item.apply(
"FIND_IN_SET({0},name)",name));
List<Animal> animalList = animalMapper.selectList(wrapper);
log.info("總記錄:{}",animalList.size());
animalList.forEach(System.out::println);
}
一、需求:如果用戶穿插了查詢參數(shù),就給sql附加條件(當(dāng)然,這個條件可以是復(fù)雜的條件),否則查詢其他的條件。
default Children and(Consumer<Param> consumer) {
return this.and(true, consumer);
}
@org.junit.Test
public void test() {
String name = "";
QueryWrapper<Animal> wrapper = new QueryWrapper<>();
wrapper.and(item->item.apply(
"FIND_IN_SET({0},name)",name).or().eq("name","貓哥"));
List<Animal> animalList = animalMapper.selectList(wrapper);
log.info("總記錄:{}",animalList.size());
animalList.forEach(System.out::println);
}
wrapper.apply("(receipt_no Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or customer Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or matter Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or bill_unit Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or receipt_money Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or item_name Like '%"+incomeCollectionReceipt.getSearchValue()+"%')");
原文鏈接:https://blog.csdn.net/m0_59259076/article/details/125120100
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-03-03 el-form動態(tài)表單切換導(dǎo)致的校驗bug(v-if、v-show導(dǎo)致校驗失效的bug)
- 2022-06-29 Tomcat配置訪問日志和線程數(shù)的實現(xiàn)步驟_Tomcat
- 2023-09-17 Git “強制“提交代碼
- 2022-09-26 符合選擇器和css三大特性組合
- 2022-03-20 Android自動攔截與接聽功能APK黑白名單_Android
- 2022-07-03 C語言由淺入深了解變量的應(yīng)用_C 語言
- 2023-12-09 添加依賴時,出現(xiàn)了此問題maven Cannot resolve org.apache.dubbo:
- 2022-12-26 Python?gRPC流式通信協(xié)議詳細(xì)講解_python
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 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錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支