使用PageInfo分页查询列表

先引入依赖

    <!-- pageHelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
<exclusions>
<exclusion>
<artifactId>mybatis-spring</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

service层
    @Override
    public PageInfo<SysHospital> sysHospitalList(SearchHospitalListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        Example example = new Example(SysHospital.class);
        Example.Criteria criteria = example.createCriteria().andEqualTo("deleteFlag", DeleteFlagEnum.NORMAL.getCode())
                .andEqualTo("hospitalType",req.getHospitalType());
        example.setOrderByClause("create_time desc");
        List<SysHospital> sysHospitals = sysHospitalMapper.selectByExample(example);
        PageInfo pageInfo = PageInfo.of(sysHospitals);
        pageInfo.setList(sysHospitals);
        return pageInfo;
    }

  

posted @ 2021-07-22 15:46  下饭  阅读(311)  评论(0编辑  收藏  举报