搞混了一次,特此笔记
1、bitCode or iotStr 跟其他ID一个都不能有重复
1
2
|
queryWrapper.ne(LineProductionPlan::getId,bean.getId());
queryWrapper.and(i -> i.eq(LineProductionPlan::getBitCode,bean.getBitCode()).or().eq(LineProductionPlan::getIotStr,bean.getIotStr()));
|
打印sql
2、模糊查询codeOrName变量匹配二个字段
1
|
queryWrapper.lambda().and(StrUtil.isNotEmpty(codeOrName), i -> i.like(Point::getName, codeOrName).or().like(Point::getBitCode, codeOrName));
|
扩展:Mybatis-Plus中or()的使用避坑
1.连接 or()
当需要简单的将两个条件或连接,则最直接的写法为:
1
2
3
4
5
|
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相当于把两个条件()一块;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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 st
|
|