Mybatis-Plus分页查询带条件的核心笔记

Posted 金石不渝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis-Plus分页查询带条件的核心笔记相关的知识,希望对你有一定的参考价值。

Mybatis-Plus分页查询带条件的核心

//        3 条件查询带分页
        @PostMapping("findPageHospSet/current/limit")
        public Result findPageHospSet(@PathVariable long current,
                                      @PathVariable long limit,
                                      @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo) 
//            //创建page对象,传递当前页,每页记录数
            Page<HospitalSet> page = new Page<>(current, limit);
//            //构建条件
            QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
            String hosname = hospitalSetQueryVo.getHosname();//医院名称
            String hoscode = hospitalSetQueryVo.getHoscode();//医院编号
            if (!StringUtils.isEmpty(hosname)) 
                wrapper.like("hosname", hospitalSetQueryVo.getHosname());
            
            if (!StringUtils.isEmpty(hoscode)) 
                wrapper.eq("hoscode", hospitalSetQueryVo.getHoscode());
            
            //调用方法实现分页查询
            Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);
            //返回结果
            return Result.ok(pageHospitalSet);
        

以上是关于Mybatis-Plus分页查询带条件的核心笔记的主要内容,如果未能解决你的问题,请参考以下文章