springboot整合mybatis分页插件

2019/03/18 14:25
阅读数 0

1.springboot版本为2.0.1,数据库为mysql,引入pagehelper的pom依赖

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

如果引入不兼容版本,启动报错

2.不要另外配置,使用默认配置即可。

@RequestMapping("/list")
    public PageInfo<BaseRole> pageByExample(BaseRole record,int page,int limit){
        PageHelper.startPage(page, limit);
        List<BaseRole> list = service.selectAll(record);
        PageInfo<BaseRole> pageInfo = new PageInfo<BaseRole>(list);
        return pageInfo;
        
    }

3.请求如下

http://localhost:8080/list?page=1&limit=2

结果如下

{
    "pageNum": 1,
    "pageSize": 2,
    "size": 2,
    "startRow": 1,
    "endRow": 2,
    "total": 5,
    "pages": 3,
    "list": [
        {
            "id": 1,
            "rolename": "111",
            "limits": "1",
            "descr": "1",
            "isuse": "1",
            "createtime": "2019-03-15T09:48:09.000+0000",
            "updatetime": "2019-03-15T09:48:12.000+0000"
        },
        {
            "id": 2,
            "rolename": "2",
            "limits": "2",
            "descr": "2",
            "isuse": "2",
            "createtime": "2019-03-18T06:09:29.000+0000",
            "updatetime": "2019-03-18T06:09:33.000+0000"
        }
    ],
    "prePage": 0,
    "nextPage": 2,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
        1,
        2,
        3
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 3,
    "firstPage": 1,
    "lastPage": 3
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部