搞混了一次,特此笔记
1、bitcode or iotstr 跟其他id一个都不能有重复
querywrapper.ne(lineproductionplan::getid,bean.getid()); querywrapper.and(i -> i.eq(lineproductionplan::getbitcode,bean.getbitcode()).or().eq(lineproductionplan::getiotstr,bean.getiotstr()));
打印sql
2、模糊查询codeorname变量匹配二个字段
querywrapper.lambda().and(strutil.isnotempty(codeorname), i -> i.like(point::getname, codeorname).or().like(point::getbitcode, codeorname));
扩展:mybatis-plus中or()的使用避坑
1.连接 or()
当需要简单的将两个条件或连接,则最直接的写法为:
querywrapper<user> querywrapper = new querywrapper<user>(). eq("status",0). or(). eq("status",1); //sql条件为 select * from user where status=0 or status=1
2.连接 or()
当多个条件共同拼接,则最直接的写法为: 要么把or()拼接放最前面,要么用querywrapper.and(
qr.eq("status", 1).or().like("status", 2)),要不查询的数据会有偏差,querywrapper.and相当于把两个条件()一块;
querywrapper<user> querywrapper = new querywrapper<user>(). eq("status",0). or(). eq("status",1) eq("user_name","张三"); //sql条件为 select * from user where status=0 or status=1 and user_name='张三' querywrapper<user> querywrapper = new querywrapper<user>(). eq("user_name","张三"). eq("status",0). or(). eq("status",1); //sql条件为 select * from user where user_name='张三' and status=0 or status=1 查询出来的数据和select * from user where status=0 or status=1 and user_name='张三' 不一致 querywrapper<user> querywrapper = new querywrapper<user>(). eq("user_name","张三").and(q->q.eq("status",0). or(). eq("status",1)); select * from user where select * from user where user_name='张三' and (status=0 or status=1 ) 查询出来的数据和select * from user where status=0 or status=1 and user_name='张三' 一致
到此这篇关于mybatisplus多条件 or()的使用的文章就介绍到这了,更多相关mybatisplus多条件 or()内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论