package com.ld.igds.data;
|
|
import com.baomidou.mybatisplus.plugins.Page;
|
|
import java.io.Serializable;
|
import java.util.Collection;
|
import java.util.List;
|
|
/**
|
* 对Page<E>结果进行包装
|
*
|
* 之所以进行封装是因为LayUI中不管分页与否获取数据,都需要一个完整的格式返回。 LAYUI中要求查询数据必须封装为: {
|
* code:0,msg:"",count:1000,data:[] }
|
*
|
*
|
*/
|
public class LayPage<T> implements Serializable {
|
|
private static final long serialVersionUID = 1L;
|
// 当前页
|
private int curr;
|
// 每页的数量
|
private int limit;
|
// 总记录数
|
private long count;
|
// 总页数
|
private int pages;
|
// 结果集
|
private List<T> data;
|
// 是否为第一页
|
private boolean isFirstPage = false;
|
// 是否为最后一页
|
private boolean isLastPage = false;
|
|
// LayUI中的必须返回的结果编码 0表示成功。
|
private int code = 0;
|
// LayUI中异常信息。
|
private String msg;
|
|
public LayPage() {
|
super();
|
this.count = 0;
|
this.curr = 1;
|
this.code = 0;
|
this.msg ="无数据";
|
}
|
|
/**
|
* 包装Page对象
|
*
|
* @param list
|
*/
|
public LayPage(List<T> list) {
|
super();
|
if (null == list || list.isEmpty()) {
|
this.count = 0;
|
this.curr = 1;
|
this.code = 0;
|
this.msg ="无数据";
|
}
|
if (list instanceof Collection) {
|
this.curr = 1;
|
this.limit = list.size();
|
|
this.pages = 1;
|
this.data = list;
|
this.count = list.size();
|
}
|
if (list instanceof Collection) {
|
// 判断页面边界
|
judgePageBoudary();
|
}
|
}
|
|
public LayPage(Page<T> page) {
|
this.curr = page.getCurrent();
|
this.limit = page.getSize();
|
|
this.pages = (int)page.getPages();
|
this.data = (List<T>) page.getRecords();
|
this.count = page.getTotal();
|
}
|
|
/**
|
* 判定页面边界
|
*/
|
private void judgePageBoudary() {
|
isFirstPage = curr == 1;
|
isLastPage = curr == pages;
|
}
|
|
public int getPageNum() {
|
return curr;
|
}
|
|
public void setPageNum(int pageNum) {
|
this.curr = pageNum;
|
}
|
|
public int getLimit() {
|
return limit;
|
}
|
|
public void setLimit(int limit) {
|
this.limit = limit;
|
}
|
|
public long getCount() {
|
return count;
|
}
|
|
public void setCount(long count) {
|
this.count = count;
|
}
|
|
public int getPages() {
|
return pages;
|
}
|
|
public void setPages(int pages) {
|
this.pages = pages;
|
}
|
|
public List<T> getData() {
|
return data;
|
}
|
|
public void setData(List<T> data) {
|
this.data = data;
|
}
|
|
public boolean isIsFirstPage() {
|
return isFirstPage;
|
}
|
|
public void setIsFirstPage(boolean isFirstPage) {
|
this.isFirstPage = isFirstPage;
|
}
|
|
public boolean isIsLastPage() {
|
return isLastPage;
|
}
|
|
public void setIsLastPage(boolean isLastPage) {
|
this.isLastPage = isLastPage;
|
}
|
|
@Override
|
public String toString() {
|
final StringBuffer sb = new StringBuffer("PageInfo{");
|
sb.append("curr=").append(curr);
|
sb.append(", limit=").append(limit);
|
sb.append(", count=").append(count);
|
sb.append(", pages=").append(pages);
|
sb.append(", data=").append(data);
|
sb.append(", isFirstPage=").append(isFirstPage);
|
sb.append(", isLastPage=").append(isLastPage);
|
sb.append(", navigatepageNums=");
|
sb.append('}');
|
return sb.toString();
|
}
|
|
public int getCode() {
|
return code;
|
}
|
|
public void setCode(int code) {
|
this.code = code;
|
}
|
|
public String getMsg() {
|
return msg;
|
}
|
|
public void setMsg(String msg) {
|
this.msg = msg;
|
}
|
|
}
|