说明
判空查询,对应SQL语句中的 in
语句,查询参数包含在入参列表之内的数据。
in
@Testvoid inNonEmptyList() {// 非空列表,作为参数List<Integer> ages = Stream.of(18, 20, 22).collect(Collectors.toList());in(ages);}@Testvoid inEmptyList() {// 空列表,作为参数List<Integer> ages = new ArrayList<>();in(ages);}/*** 查询用户列表, 查询条件:年龄包含在参数列表之内。* <br>* 入参不为空和空列表时,“包含”条件生效。*/void in(List<Integer> ages) {LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();wrapper.in(!CollectionUtils.isEmpty(ages), User::getAge, ages);List<User> users = mapper.selectList(wrapper);log.info(users.toString());}
- 非空列表,作为参数
- 空列表,作为参数
notIn
/*** 查询用户列表, 查询条件:年龄不包含在参数列表之内。*/@Testvoid notIn() {List<Integer> ages = Stream.of(18, 20, 22).collect(Collectors.toList());LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();wrapper.notIn(!CollectionUtils.isEmpty(ages), User::getAge, ages);List<User> users = mapper.selectList(wrapper);log.info(users.toString());}
inSql
/*** 查询用户列表, 查询条件:年龄包含在"sql语句的查询结果"之内。*/@Testvoid inSql() {LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();wrapper.inSql(User::getAge, "select age from tb_user where age > 25");List<User> users = mapper.selectList(wrapper);log.info(users.toString());}
notInSql
/*** 查询用户列表, 查询条件:年龄不包含在"sql语句的查询结果"之内。*/@Testvoid notInSql() {LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();wrapper.notInSql(User::getAge, "select age from tb_user where age > 25");List<User> users = mapper.selectList(wrapper);log.info(users.toString());}