MyBatis-Plus自帶的分頁模型Page有些參數(shù),我覺得不是很必要,因此自定義自己的分頁模型。該類繼承了 IPage 類,實現(xiàn)了簡單分頁模型如果你要實現(xiàn)自己的分頁模型可以繼承 Page 類或者實現(xiàn) IPage 類。因為Java是單繼承多實現(xiàn)的,所以我們使用實現(xiàn)IPage接口的方式實現(xiàn)我們自己的分頁模型。文章來源地址http://www.zghlxwxcb.cn/news/detail-527729.html
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; //當(dāng)前頁頁碼
protected long size; //當(dāng)前頁數(shù)據(jù)數(shù)量
protected long total; //數(shù)據(jù)總量
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;
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-527729.html
到了這里,關(guān)于MyBatis-Plus自定義分頁模型的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!