前端传输的要的分页属性和后端给的Mybatis-Plus的Page属性不一致如何解决?这里给出答案.重写Page内的get方法并重写构造方法

本文为子豪原创:

有时候前端需要的分页属性名字固定死了,但是Mybatis-Plus的Page属性为下表

public class Page<T> implements IPage<T> {
    private static final long serialVersionUID = 8545996863226528798L;
    //查询出来的数据
    protected List<T> records; 
    //返回记录的总数
    protected long total;
    //每页显示条数 默认 10
    protected long size;
    //当前页  默认 1
    protected long current;
    //排序字段信息
    protected List<OrderItem> orders;
    // 自动优化 COUNT SQL 默认为true  
    protected boolean optimizeCountSql;
    //是否进行 count 查询,设置false后不会返回total
    protected boolean isSearchCount;
    //是否命中count缓存 默认为 false
    protected boolean hitCount;
    protected String countId;
    //单页分页条数限制
    protected Long maxLimit;
}

那么问题来了,前端要的是Count,TotalPages,PageSize和CurrentPage怎么办呢?
答案是重写
代码如下:

package com.itheima.ydd.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * @author zihao
 * @version 1.0
 * @date 2022/4/11 0011 zihao
 */

public class YddCatePageDto<T> extends Page<T> {


    public List<T> getdata() {
        return super.getRecords();
    }

    public List<T> getRecords() {
        return null;
    }

    //一共多少条
    public long getCount() {
        return super.total;
    }

    //一共多少页
    public long getTotalPages() {
        return super.getPages();
    }

    //每页数量
    public long getPageSize() {
        return super.size;
    }

    //  当前页码
    public long getCurrentPage() {
        return super.current;
    }

  public YddCatePageDto() {
  }

  //构造
  public YddCatePageDto(long current, long size) {
    super(current, size);
  }

  public YddCatePageDto(long current, long size, long total) {
    super(current, size, total);
  }

  public YddCatePageDto(long current, long size, boolean isSearchCount) {
    super(current, size, isSearchCount);
  }

  public YddCatePageDto(long current, long size, long total, boolean isSearchCount) {
    super(current, size, total, isSearchCount);
  }
}

这样就可以直接调取了

YddCatePageDto<YddCate> pageInfo = new YddCatePageDto<>(pageLong, limitLong);

觉得问题解决了的话,请点赞哦!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值