springBoot中使用 pagehelper

PageHelper。
  我们知道,在mysql中,分页的sql是使用limit来做,如果我们自己写sql,那分页肯定是没有任何问题的。但是一旦model多了起来,复杂了起来,我们很自然的想到使用mybatis的逆向工程来生成相应的po和mapper,但是同时也会带来弊端,比如这里的分页问题就不好解决了。

在springboot中 使用pagehelper是比较简单的:
第一步:在pom中添加:

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

第二步 ,在application.yml中添加,我使用的是mysql

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

接下来就可以在项目中使用了:

  PageInfo<ShShopSeat> shShopSeatPageInfo = shopService.getWeChatByPageInfo(pageInfo,shopId);

pageInfo:为前端传过来的当前页码

 @Override
    public PageInfo<ShShopSeat> getWeChatByPageInfo(Integer pageInfo, Integer shopId) {
        PageHelper.startPage(pageInfo,10);
        return  new PageInfo<>(shopSeatDAO.findByShopId(shopId));
    }

测试结果:

{
    "code": 0,
    "data": {
        "shShopSeatPageInfo": {
            "pageNum": 0,
            "pageSize": 10,
            "size": 0,
            "startRow": 0,
            "endRow": 0,
            "total": 0,
            "pages": 0,
            "list": [],
            "prePage": 0,
            "nextPage": 0,
            "isFirstPage": false,
            "isLastPage": true,
            "hasPreviousPage": false,
            "hasNextPage": false,
            "navigatePages": 8,
            "navigatepageNums": [],
            "navigateFirstPage": 0,
            "navigateLastPage": 0,
            "firstPage": 0,
            "lastPage": 0
        },
        "code": 0
    },
    "message": "true"
}

想看Mybatis中整合 pageHelper的可以去:https://blog.csdn.net/eson_15/article/details/52270046

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XC_Aaron

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值