zoukankan      html  css  js  c++  java
  • springboot PageHelper实现分页

    • pom.xml文件添加引用,注意此种分页不是基于原生PageHelper分页

    <!--pageHelper-->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.3</version>
    </dependency>
    
    
    • 属性文件,添加如下配置,注意此配置可不添加,添加作用是为了处理特殊情况
      pagehelper.helperDialect=mysql
      pagehelper.reasonable=true #为了使用输入页数为负或者超出最大页时候使页数为最小或最大值
      pagehelper.supportMethodsArguments=true
      pagehelper.params=count=countSql
    • 分页关键代码
     @ApiOperation("查询列表")
        @PostMapping("/selectList")
        @JwtIgnore
        public Result selectList(@RequestBody PageRequest request) {
            Page page = PageHelper.startPage(request.pageNum,request.pageSize); //这行是重点(放在方法第一行)表示从pageNum页开始,每页pageSize条数据
            List<User_info> _list= userService.selectList();//返回集合和分页之前不要有其它代码,这两行上下要紧靠近
            PageInfo pageInfo = new PageInfo<>(_list);
            return  Result.SUCCESS( pageInfo);
        }
     @Override
        public List<User_info> selectList() {
            return uMapper.selectList();
        }
        <!---查询列表-->
        <select id="selectList" resultType="User_info">
        select * from User_info
        </select>

      使用postman接口测试工具,调用效果

    {
        "code": 1,
        "message": "操作成功!",
        "data": {
            "pageNum": 1,
            "pageSize": 3,
            "size": 3,
            "startRow": 1,
            "endRow": 3,
            "total": 5,
            "pages": 2,
            "list": [
                {
                    "id": "43591639-e5fb-4369-b4d6-aab12a982ebf",
                    "create_time": "2020-08-19T08:06:57.000+00:00",
                    "name": "string1"
                },
                {
                    "id": "66bafe88-b716-48d5-8cfb-b91a881a355a",
                    "create_time": "2020-08-19T07:25:50.000+00:00",
                    "name": "string1"
                },
                {
                    "id": "6afb9f4c-7a95-45fb-881b-543e2dcc2c72",
                    "create_time": "2020-08-19T07:38:52.000+00:00",
                    "name": "string1"
                }
            ],
            "prePage": 0,
            "nextPage": 2,
            "isFirstPage": true,
            "isLastPage": false,
            "hasPreviousPage": false,
            "hasNextPage": true,
            "navigatePages": 8,
            "navigatepageNums": [
                1,
                2
            ],
            "navigateFirstPage": 1,
            "navigateLastPage": 2,
            "firstPage": 1,
            "lastPage": 2
        }
    }

  • 相关阅读:
    精确覆盖DLX算法模板另一种写法
    Hdu3498-whosyourdaddy(精确覆盖模板题)
    精确覆盖DLX算法模板
    Object2Map
    Use ResourceBundle read properties file.
    Kendo UI Example(grid)
    Kendo 日期控件
    Spring mvc 中文乱码问题解决方法
    Thread communication java.util.concurrent.locks.Condition 用法(二)
    Thread communication java.util.concurrent.locks.Condition 用法(一)
  • 原文地址:https://www.cnblogs.com/personblog/p/13935995.html
Copyright © 2011-2022 走看看