赞
踩
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='张三' 一致
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。