第19章—后端分页(PageHelper)

本文介绍如何在SpringBoot项目中使用PageHelper分页插件。通过简单的配置和代码示例,展示如何快速实现数据分页功能。适用于希望了解PageHelper基本用法的开发者。

spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html

码云源码地址:https://gitee.com/jinxiaohang/springboot

 

  PageHelper开源分页工具:

    https://gitee.com/free/Mybatis_PageHelper  

    https://github.com/pagehelper/Mybatis-PageHelper

  本次练习在之前第04章—整合Mybatis基础上进行,这里只进行简单使用,详细请参考官方文档

一、添加依赖

专门为了集成springboot设计的,使用起来很方便,建议使用。

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

 如果使用以下集成springboot比较麻烦,本次不使用,所以采用上面的依赖进行实现。

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.2</version>
</dependency>

 

二、编写controller层

@GetMapping("paging")
    public List<User> paging(@RequestParam int pageNum,@RequestParam int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return userService.list();
    }

 对,就这么简单,当然,也可以设计在service层实现。

三、运行测试

所有数据:

分页数据:

四、总结

  更多详细使用方法参考官方文档。

    https://gitee.com/free/Mybatis_PageHelper  

    https://github.com/pagehelper/Mybatis-PageHelper

转载于:https://www.cnblogs.com/jinxiaohang/p/8370718.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值