MyBatisPlus基础查询使用:
-
1:多条件查询&排序:
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().ge(User::getId, 100).orderByDesc(User::getId); list = userService.list(queryWrapper);
-
2:模糊查询:
QueryWrapper<User> queryWrapper=new QueryWrapper<>(); queryWrapper.lambda().like(User::getId,12); List<User> list = userService.list(queryWrapper); for (User user : list) { System.out.println(user.toString()); }
-
3:根据Wrapper更新:
//根据wrapper 更新
LambdaQueryWrapper<User> updateWrapper = new QueryWrapper<User>().lambda().eq(User::getId, 101);
User user = new User();
user.setUsername("东方不败");
user.setCreateDate(new Date());
boolean update_flag = userService.update(user, updateWrapper);
- 4:只查询一行:
LambdaQueryWrapper<User> queyr = new LambdaQueryWrapper<User>().eq(User::getId, 1);
User one = userService.getOne(queyr);
- 5:统计:
LambdaQueryWrapper<User> queyr = new LambdaQueryWrapper<User>().eq(User::getId, 1);
int count = userService.count(queyr);