Spring Boot之PageHelper极简入门教程

Spring Boot之PageHelper入门教程

1、首先导入PageHelper依赖

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.5</version>
    </dependency>

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<User> selectAll(){
    Page<User> page = PageHelper.startPage(2, 2);
    List<User> users = userService.queryAllUser();
    PageInfo<User> pageInfo = new PageInfo<User>(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}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值