Spring Boot之PageHelper极简入门教程

Spring Boot之PageHelper入门教程

1、首先导入PageHelper依赖

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

2、application.properties中加入pageHelper配置

    #分页插件
    pagehelper.helper-dialect=mysql
    pagehelper.params=count=countSql
    pagehelper.reasonable=true
    pagehelper.support-methods-arguments=true

3、然后再代码中直接只用即可

@GetMapping("queryAll")
public PageInfo selectAll(){
    Page page = PageHelper.startPage(2, 2);
    List users = userService.queryAllUser();
    PageInfo pageInfo = new PageInfo(users);
    pageInfo.getList().stream().forEach(System.out::println);
    int pages = pageInfo.getPages();
    System.out.println(pages);
    users.stream().forEach(System.out::println);
    return pageInfo;
}

返回结果如下

{"total":5,"list":[{"id":3,"name":"wangwu","pwd":"12345"},{"id":4,"name":"曹功德","pwd":"1321"}],
"pageNum":2,"pageSize":2,"size":2,"startRow":3,"endRow":4,"pages":3,"prePage":1,"nextPage":3,"isFirstPage":false,"isLastPage":false,
"hasPreviousPage":true,"hasNextPage":true,
"navigatePages":8,"navigatepageNums":[1,2,3],"navigateFirstPage":1,"navigateLastPage":3,"firstPage":1,"lastPage":3}

你可能感兴趣的:(Mybatis)