常用的两种条件构造器分别是 QueryWrapper 和 LambdaQueryWrapper
QueryWrapper
@Autowiredprivate StudentMapper studentMapper;@Testpublic void test() {//条件分页查询学生,性别为2(代表女),年龄大于等于12的学生QueryWrapper<StudentEntity> qw = new QueryWrapper<>();qw.lambda().eq(StudentEntity::getGender, 2).ge(StudentEntity::getAge, 12);Page<StudentEntity> page = new Page<>(1, 10);studentMapper.selectPage(page, qw);//当前展示数据List<StudentEntity> students = page.getRecords();students.forEach(System.out::println);}
LambdaQueryWrapper
@Autowiredprivate StudentMapper studentMapper;@Testpublic void test() {//条件分页查询学生,性别为2(代表女),年龄大于等于12的学生LambdaQueryWrapper<StudentEntity> lqw = new LambdaQueryWrapper<>();lqw.eq(StudentEntity::getGender, 2).ge(StudentEntity::getAge, 12);Page<StudentEntity> page = new Page<>(1, 10);studentMapper.selectPage(page, lqw);//当前展示数据List<StudentEntity> students = page.getRecords();students.forEach(System.out::println);}
两种写法都是Lambda格式,推荐使用。