spring-boot修改mybatisPlus的分页插件的size,current,total参数名称!!!

前几天项目中需要对分页插件返回的size,current,total这3个参数的名称进行修改,在网上找了半年都没有,只好自己解决了。
首先分页插件肯定是一个工具类,所有就想着能不能看下有他自带的方法去修改这3个属性,但是大家都知道,set get方法只能修改他们的值,不能修改他们本身的名称。
后来又想着看能不能去这个工具类里面去修改,但是不知道为什么分页插件的这个类只是可读的,不能够对他进行修改。
所有最后实在没办法了,就写了一个工具类去继承,除了这3个属性名称不一样,其他方法都是一样的,然后在使用分页插件的时候,就引入这个类!
package com.loogear.commons.util;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.*;
import java.util.function.Predicate;

public class PageHelp extends Page {
private static final long serialVersionUID = 8545996863226528798L;
protected List records;
protected long totalCount;
protected long pageNum;
protected long pageSize;
protected List orders;
protected boolean optimizeCountSql;
protected boolean isSearchCount;
protected boolean hitCount;
protected String countId;
protected Long maxLimit;

public  PageHelp() {
    this.records = Collections.emptyList();
    this.totalCount = 0L;
    this.pageSize = 10L;
    this.pageNum = 1L;
    this.orders = new ArrayList();
    this.optimizeCountSql = true;
    this.isSearchCount = true;
    this.hitCount = false;
    super.current=this.pageNum;
    super.size=this.pageSize;
    super.total=this.totalCount;
}

public PageHelp(long pageNum, long pageSize) {
    this(pageNum, pageSize, 0L);
}

public PageHelp(long pageNum, long pageSize, long totalCount) {
    this(pageNum, pageSize, totalCount, true);
}

public PageHelp(long pageNum, long pageSize, boolean isSearchCount) {
    this(pageNum, pageSize, 0L, isSearchCount);
}

public PageHelp(long pageNum, long pageSize, long totalCount, boolean isSearchCount) {
    this.records = Collections.emptyList();
    this.totalCount = 0L;
    this.pageSize = 10L;
    this.pageNum = 1L;
    this.orders = new ArrayList();
    this.optimizeCountSql = true;
    this.isSearchCount = true;
    this.hitCount = false;
    if (pageNum > 1L) {
        this.pageNum = pageNum;
    }

    this.pageSize = pageSize;
    this.totalCount = totalCount;
    this.isSearchCount = isSearchCount;
}

public boolean hasPrevious() {
    return this.pageNum > 1L;
}

public boolean hasNext() {
    return this.pageNum < this.getPages();
}

public List<T> getRecords() {
    return this.records;
}

public Page<T> setRecords(List<T> records) {
    this.records = records;
    return this;
}

public long getTotal() {
    return this.totalCount;
}

public Page<T> setTotal(long totalCount) {
    this.totalCount = totalCount;
    return this;
}

public long getSize() {
    return this.pageSize;
}

public Page<T> setSize(long pageSize) {
    this.pageSize = pageSize;
    return this;
}

public long getCurrent() {
    return this.pageNum;
}

public Page<T> setCurrent(long pageSize) {
    this.pageSize = pageSize;
    return this;
}

public String countId() {
    return this.getCountId();
}

public Long maxLimit() {
    return this.getMaxLimit();
}

private String[] mapOrderToArray(Predicate<OrderItem> filter) {
    List<String> columns = new ArrayList(this.orders.size());
    this.orders.forEach((i) -> {
        if (filter.test(i)) {
            columns.add(i.getColumn());
        }

    });
    return (String[])columns.toArray(new String[0]);
}

private void removeOrder(Predicate<OrderItem> filter) {
    for(int i = this.orders.size() - 1; i >= 0; --i) {
        if (filter.test(this.orders.get(i))) {
            this.orders.remove(i);
        }
    }

}

public Page<T> addOrder(OrderItem... items) {
    this.orders.addAll(Arrays.asList(items));
    return this;
}

public Page<T> addOrder(List<OrderItem> items) {
    this.orders.addAll(items);
    return this;
}

/** @deprecated */
@Deprecated
public Page<T> setAscs(List<String> ascs) {
    return CollectionUtils.isNotEmpty(ascs) ? this.setAsc((String[])ascs.toArray(new String[0])) : this;
}

/** @deprecated */
@Deprecated
public Page<T> setAsc(String... ascs) {
    this.removeOrder(OrderItem::isAsc);
    String[] var2 = ascs;
    int var3 = ascs.length;

    for(int var4 = 0; var4 < var3; ++var4) {
        String s = var2[var4];
        this.addOrder(OrderItem.asc(s));
    }

    return this;
}

/** @deprecated */
@Deprecated
public Page<T> setDescs(List<String> descs) {
    if (CollectionUtils.isNotEmpty(descs)) {
        this.removeOrder((item) -> {
            return !item.isAsc();
        });
        Iterator var2 = descs.iterator();

        while(var2.hasNext()) {
            String s = (String)var2.next();
            this.addOrder(OrderItem.desc(s));
        }
    }

    return this;
}

/** @deprecated */
@Deprecated
public Page<T> setDesc(String... descs) {
    this.setDescs(Arrays.asList(descs));
    return this;
}

public List<OrderItem> orders() {
    return this.getOrders();
}

public boolean optimizeCountSql() {
    return this.optimizeCountSql;
}

public boolean isOptimizeCountSql() {
    return this.optimizeCountSql();
}

public boolean isSearchCount() {
    return this.total < 0L ? false : this.isSearchCount;
}

public Page<T> setSearchCount(boolean isSearchCount) {
    this.isSearchCount = isSearchCount;
    return this;
}

public Page<T> setOptimizeCountSql(boolean optimizeCountSql) {
    this.optimizeCountSql = optimizeCountSql;
    return this;
}

public void hitCount(boolean hit) {
    this.hitCount = hit;
}

public void setHitCount(boolean hit) {
    this.hitCount = hit;
}

public boolean isHitCount() {
    return this.hitCount;
}

public List<OrderItem> getOrders() {
    return this.orders;
}

public void setOrders(final List<OrderItem> orders) {
    this.orders = orders;
}

public String getCountId() {
    return this.countId;
}

public void setCountId(final String countId) {
    this.countId = countId;
}

public Long getMaxLimit() {
    return this.maxLimit;
}

public void setMaxLimit(final Long maxLimit) {
    this.maxLimit = maxLimit;
}

public long getTotalCount() {
    return totalCount;
}

public void setTotalCount(long totalCount) {
    this.totalCount = totalCount;
}

public long getPageNum() {
    return pageNum;
}

public void setPageNum(long pageNum) {
    this.pageNum = pageNum;
}

public long getPageSize() {
    return pageSize;
}

public void setPageSize(long pageSize) {
    this.pageSize = pageSize;
}

}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Mybatis-Plus提供了一个分页插件`PaginationInterceptor`,可以方便地进行分页查询。下面是配置Mybatis-Plus分页插件的步骤: 1. 导入依赖 在`pom.xml`文件中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatis-plus.version}</version> </dependency> ``` 2. 配置分页插件 在Spring Boot的配置文件`application.yml`中添加以下配置: ```yaml mybatis-plus: configuration: # 开启驼峰命名规则 map-underscore-to-camel-case: true # 配置分页插件 global-config: # 分页插件 db-config: # 分页查询最大限制 limit: 10000 # 分页插件 page-size: 10 page-current: 1 # 数据库类型,不同的数据库分页语句不同 db-type: mysql plugins: - com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor ``` 其中,`PaginationInterceptor`就是Mybatis-Plus提供的分页插件。`mybatis-plus.global-config.db-config`中的`limit`表示分页查询最大限制,`page-size`表示每页记录数,`page-current`表示当前页数。`db-type`表示数据库类型,需要根据实际情况进行配置。 3. 使用分页插件 在Mapper接口中继承`BaseMapper`,然后在查询方法中使用`Page`对象即可实现分页查询: ```java public interface UserMapper extends BaseMapper<User> { // 分页查询用户列表 List<User> selectUserList(Page<User> page); } ``` 使用示例: ```java // 创建分页对象 Page<User> page = new Page<>(1, 10); // 查询用户列表 List<User> userList = userMapper.selectUserList(page); // 获取分页信息 long total = page.getTotal(); long current = page.getCurrent(); long size = page.getSize(); ``` 以上就是配置Mybatis-Plus分页插件的步骤。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值