Mybatis-plus :分页带条件查询

StudentController

@ApiOperation("分页带条件查询学生信息")
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result getStudentByOpr(
            @ApiParam("页码数") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("页大小") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件")Student student
            ){
                //分页信息封装Page对象
        Page<Student> page = new Page<>(pageNo,pageSize);
        //进行查询
        IPage<Student> studentIPage = studentService.getStudentByOpr(page,student);
        //封装Result返回
        return Result.ok(studentIPage);
    }

StudentServiceImpl

@Override
    public IPage<Student> getStudentByOpr(Page<Student> page, Student student) {
        QueryWrapper<Student> queryWrapper =  new QueryWrapper<>();
        //判断要模糊查询的数据是否为空,在放进条件控制器queryWrapper 
        if(!StringUtils.isBlank(student.getName())){
            queryWrapper.like("name",student.getName());
        }
        if(!StringUtils.isBlank(student.getClazzName())){
            queryWrapper.like("clazz_name",student.getClazzName());
        }
        //降序查询
        queryWrapper.orderByDesc("id");
        Page<Student> StudentPage = baseMapper.selectPage(page, queryWrapper);
        return  StudentPage;
    }

版权声明:本文为weixin_54966486原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。