个人主页: 叶落闲庭
我的专栏:
c语言
数据结构
javaEE
操作系统
石可破也,而不可夺坚;丹可磨也,而不可夺赤。
//方式一:按条件查询
QueryWrapper qw = new QueryWrapper();
//小于3
qw.lt("id",3);
List userList = userDao.selectList(qw);
System.out.println(userList);
QueryWrapper qw = new QueryWrapper();
//小于3大于1
qw.lt("id",3).gt("id",1);
List userList = userDao.selectList(qw);
System.out.println(userList);
//方式三:lambda格式按条件查询
LambdaQueryWrapper<User> lwq = new LambdaQueryWrapper<>();
//id为1到3之间
lwq.lt(User::getId,3);
lwq.gt(User::getId,1);
//id为小于2或者大于3
//链式查询
lwq.lt(User::getId,2).or().gt(User::getId,3);
List userList = userDao.selectList(lwq);
System.out.println(userList);
qw.lt("id",3).gt("id",1);
lwq.lt(User::getId,2).or().gt(User::getId,3);
UserQuery uq = new UserQuery();
uq.setId(1);
uq.setId2(3);
//null判定
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
if(null != uq.getId()) {
lqw.lt(User::getId,uq.getId2());
}
if(null != uq.getId2()) {
lqw.gt(User::getId,uq.getId());
}
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
//先判定第一个参数是否为true,如果为true,连接当前条件
UserQuery uq = new UserQuery();
uq.setId(1);
uq.setId2(3);
//null判定
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.gt(null!=uq.getId2(), User::getId, uq.getId())
lqw.lt(null!= uq.getId(),User::getId,uq.getId2());
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
//先判定第一个参数是否为true,如果为true,连接当前条件
UserQuery uq = new UserQuery();
uq.setId(1);
uq.setId2(3);
//null判定
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.gt(null!=uq.getId2(), User::getId, uq.getId())
.lt(null!= uq.getId(),User::getId,uq.getId2());
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.select(User::getId,User::getAddr);
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
QueryWrapper<User> qw = new QueryWrapper<>();
qw.select("count(*) as count");
qw.groupBy("gender");
List<Map<String, Object>> userList = userDao.selectMaps(qw);
System.out.println(userList);