MybatisPlus问题解决——java.lang.AssertionError

11 篇文章 0 订阅

MybatisPlus问题解决——java.lang.AssertionError

1 报错信息

在这里插入图片描述

2 报错原因

MybatisPlus实现分页查询使用接口IPage来接收返回数据,但是请求对象没有继承Page类。

  /*
  * 分页查询列表
  * */
  IPage<AssetSplitVO> getAssetSplitPage(AssetSplitReq req);
@Data
public class AssetSplitReq extends Page {

  /**拆分单号*/
  private String assetSplitNo;

  /**拆分前资产编号*/
  private String beforeSplitAssetNo;

}

3 问题解决

细心!请求参数一定要继承mybatisPlus的Page类!

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baomidou.mybatisplus.extension.plugins.pagination;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.jetbrains.annotations.Nullable;

public class Page<T> implements IPage<T> {
  private static final long serialVersionUID = 8545996863226528798L;
  protected List<T> records;
  protected long total;
  protected long size;
  protected long current;
  protected List<OrderItem> orders;
  protected boolean optimizeCountSql;
  protected boolean isSearchCount;
  protected boolean hitCount;

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

  public Page(long current, long size) {
    this(current, size, 0L);
  }

  public Page(long current, long size, long total) {
    this(current, size, total, true);
  }

  public Page(long current, long size, boolean isSearchCount) {
    this(current, size, 0L, isSearchCount);
  }

  public Page(long current, long size, long total, boolean isSearchCount) {
    this.records = Collections.emptyList();
    this.total = 0L;
    this.size = 10L;
    this.current = 1L;
    this.orders = new ArrayList();
    this.optimizeCountSql = true;
    this.isSearchCount = true;
    this.hitCount = false;
    if (current > 1L) {
      this.current = current;
    }

    this.size = size;
    this.total = total;
    this.isSearchCount = isSearchCount;
  }

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

  public boolean hasNext() {
    return this.current < 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.total;
  }

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

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

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

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

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

  /** @deprecated */
  @Deprecated
  @Nullable
  public String[] ascs() {
    return CollectionUtils.isNotEmpty(this.orders) ? this.mapOrderToArray(OrderItem::isAsc) : null;
  }

  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 String[] descs() {
    return this.mapOrderToArray((i) -> {
      return !i.isAsc();
    });
  }

  /** @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 List<OrderItem> getOrders() {
    return this.orders;
  }

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

  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;
  }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值