分页:mybatisPlus + pageHelper

1.依赖

引入pagehelper依赖后
需要排除Mybatis的依赖, 否则会启动报错

注:如果是多模块, 此依赖需要放入到父pom里,不然项目启动不了

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

2.配置文件

yml里配置

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

3.代码实现

  1. 设定 startPage
  2. 查询数据
  3. 返回PageInfo
 @GetMapping("/getAllIp")
    public PageInfo<IpBean> getAllIp() throws IOException {
        //分页
        PageHelper.startPage(1 ,10);
        List<IpBean> IpBeanList=null;
        List<IpBean> ipBeanList = ipBeanService.list();
        PageInfo<IpBean> pageInfo = new PageInfo(ipBeanList);
        return pageInfo;
    }

4 结果

{
    "pageNum": 1,
    "pageSize": 10,
    "size": 10,
    "startRow": 1,
    "endRow": 10,
    "total": 200,
    "pages": 20,
    "list": [
        {
            "ipAddress": "61.145.49.125",
            "ipPort": 9999,
            "serverAddress": "广东江门",
            "anonyType": "高匿",
            "protocolType": "HTTPS"
        },
        .....已省略,共10条数据
    ],
    "prePage": 0,
    "nextPage": 2,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 8,
    "firstPage": 1,
    "lastPage": 8
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值