spring boot 整合pagehelper分页插件

Posted 菜霸

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot 整合pagehelper分页插件相关的知识,希望对你有一定的参考价值。

Spring Boot 整合pagehelper分页插件

测试环境:

spring boot  版本 2.0.0.M7

mybatis starter 版本  1.3.1

jdk 1.8

---------------------------------------------------

1.  maven  引入 pagehelper 相关Jar包

        <!-- 分页插件pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>
        <!-- 分页插件pagehelper -->

2.  Service层代码 只需添加一句核心分页代码  (要在dao调用之前)

参数page为当前页码 、pagesize为每页显示多少条记录

    public List<UserEntity> usersList(String loginName, int pageSize, int page) {
        PageHelper.startPage(page,pageSize);
        return userDao.usersList();
    }

3.  Controller层代码   用pagehelper封装的 PageInfo类封装返回查询的list结果 如下图红色字体 

    @GetMapping("/users")
    public PageInfo<UserEntity> usersList(String loginName, int pageSize, int page) {
        
        List<UserEntity> list = userService.usersList(loginName,pageSize,page);
        PageInfo<UserEntity> pageinfo = new PageInfo<UserEntity>(list);
        log.debug("The method is ending");
        return pageinfo;
    }

  下断点调试后  显示 pageinfo的结果为

各项信息都已经显示出来  分页插件加载成功!

 

      

以上是关于spring boot 整合pagehelper分页插件的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询

Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询

Spring Boot 2.0 整合 ES 5 文章内容搜索实战

spring boot+mybatis整合

spring boot+mybatis整合

spring boot+mybatis整合