2-1springboot 添加pageHelper插件

1.在pom.xml中添加


    com.github.pagehelper
    pagehelper-spring-boot-starter
    1.2.3

2.application.yml中添加

pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  params: count=countSql

3.上手用 UserController.java

@ResponseBody
@RequestMapping(value = "/userAllController", method = RequestMethod.GET)
@Privilege
public ResultBean userAllController(  @RequestParam(value = "currentPage") final int currentPage,@RequestParam(value = "pageSize") final int pageSize) {
    final ResultBean result = new ResultBean();
    //使用分页插件,核心代码就这一行
    PageHelper.startPage(currentPage,pageSize);
    List users=userService.findAll();
    PageInfo pageInfo = new PageInfo(users);
    result.setData(users);
    result.setData(pageInfo);
 result.setCode(ErrorCode.SUCCESS);
 return result;
}

UserServiceImpl.java

public  List findAll(){
     return   userDao.findAll();
 }

UserService.java

List findAll();

UserDao.xml

4.swagger测试。.../userAllController?currentPage=1&pageSize=3

data中的内容 即为pageInfo中的内容

{
  "code":0,
  "message":null,
  "data":{
    "pageNum":1,
    "pageSize":3,
    "size":3,
    "startRow":1,
    "endRow":3,
    "total":16,
    "pages":6,
    "list":[
      {
        "id":"411363f928fa11e8a05900163e017f3d",
        "username":"650206.4304893896",
        "password":"e10adc3949ba59abbe56e057f20f883e",
        "nickname":null,
        "organization":null,
        "phone":null,
        "email":null,
        "address":null,
        "groupId":8,
        "createdTime":"2018-03-16T17:13:13.352+0800",
        "status":1,
        "photo":null,
        "access":null
      }
,
      {
        "id":"4292af4c28fa11e8a05900163e017f3d",
        "username":"959584.9369276175",
        "password":"e10adc3949ba59abbe56e057f20f883e",
        "nickname":null,
        "organization":null,
        "phone":null,
        "email":null,
        "address":null,
        "groupId":8,
        "createdTime":"2018-03-16T17:13:15.864+0800",
        "status":1,
        "photo":null,
        "access":null
      }
,
      {
        "id":"42d4708d28fa11e8a05900163e017f3d",
        "username":"847305.408536741",
        "password":"e10adc3949ba59abbe56e057f20f883e",
        "nickname":null,
        "organization":null,
        "phone":null,
        "email":null,
        "address":null,
        "groupId":8,
        "createdTime":"2018-03-16T17:13:16.295+0800",
        "status":1,
        "photo":null,
        "access":null
      }

    ]
,
    "prePage":0,
    "nextPage":2,
    "isFirstPage":true,
    "isLastPage":false,
    "hasPreviousPage":false,
    "hasNextPage":true,
    "navigatePages":8,
    "navigatepageNums":[
      1,
      2,
      3,
      4,
      5,
      6
    ]
,
    "navigateFirstPage":1,
    "navigateLastPage":6,
    "lastPage":6,
    "firstPage":1
  }

}


遇到问题:
mybatisplus 与 pagehelper冲突。导致pageHelper包导入错误
1.删除了mybatisplus插件。

修正导入的包为:

package com.github.pagehelper;





你可能感兴趣的:(插件)