MyBatis-Plus に付属しているページングモデル Page にはパラメータがいくつかありますが、必要ないと思うので独自にカスタマイズしています。このクラスは IPage クラスを継承し、単純なページング モデルを実装します。独自のページング モデルを実装する場合は、Page クラスを継承するか、IPage クラスを実装します。Java は単一継承と複数実装を実装しているため、IPage インターフェイスを実装することで独自のページング モデルを実装します。
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import lombok.Data;
import java.util.Collections;
import java.util.List;
@Data
public class PageImpl<T> implements IPage<T> {
private static final long serialVersionUID = 1L;
protected long current; //当前页页码
protected long size; //当前页数据数量
protected long total; //数据总量
protected List<T> records; //记录
public static <T> PageImpl<T> of(long current, long size){
return of(current,size,0L);
}
public static <T> PageImpl<T> of(long current, long size, long total){
return new PageImpl<>(current,size,total);
}
public PageImpl(long current, long size, long total) {
this.records = Collections.emptyList();
this.current = Math.max(current, 1L);
this.size = size;
this.total = total;
}
@Override
public List<OrderItem> orders() {
return null;
}
@Override
public List<T> getRecords() {
return this.records;
}
@Override
public IPage<T> setRecords(List<T> records) {
this.records = records;
return this;
}
@Override
public long getTotal() {
return this.total;
}
@Override
public IPage<T> setTotal(long total) {
this.total = total;
return this;
}
@Override
public long getSize() {
return this.size;
}
@Override
public IPage<T> setSize(long size) {
this.size = size;
return this;
}
@Override
public long getCurrent() {
return this.current;
}
@Override
public IPage<T> setCurrent(long current) {
this.current = current;
return this;
}
}