Page
package pageUntil;
import java.util.List;
public class Page<T> {
private Integer total;
private Integer pageNo;
private PageItem[] pis;
private List<T> table;
public static <T> Page init(Integer total, Integer pageNo, PageItem[] pis, List<T> table){
return new Page(total,pageNo,pis,table);
}
public Page(Integer total, Integer pageNo, PageItem[] pis, List<T> table) {
this.total = total;
this.pageNo = pageNo;
this.pis = pis;
this.table = table;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getPageNo() {
return pageNo;
}
public void setPageNo(Integer pageNo) {
this.pageNo = pageNo;
}
public PageItem[] getPis() {
return pis;
}
public void setPis(PageItem[] pis) {
this.pis = pis;
}
public List<T> getTable() {
return table;
}
public void setTable(List<T> table) {
this.table = table;
}
}
PageItem
package pageUntil;
public class PageItem {
//0上一页,2下一页
private int type;
private int page;
private int isCurr;
public static PageItem first(int page){return new PageItem(0,page,false);}
public static PageItem last(int page){return new PageItem(2,page,false);}
public static PageItem other(int page,boolean isCurr){return new PageItem(1,page,isCurr);}
private PageItem(){}
private PageItem(int type, int page,boolean isCurr) {
this.type = type;
this.page = page;
this.isCurr = isCurr?1:0;
}
public int getIsCurr() {
return isCurr;
}
public int getType() {
return type;
}
public int getPage() {
return page;
}
public void setType(int type) {
this.type = type;
}
public void setPage(int page) {
this.page = page;
}
public void setIsCurr(int isCurr) {
this.isCurr = isCurr;
}
}
PageUnti
package pageUntil;
public class PageUnti {
public static PageItem[] pageltems(int pageNo, int pageSize, int total) {
final int SIZE = total <= 5 ? total : total <= 30 ? 5 : 10;
final int REAL_SIZE = SIZE <= 5 ? SIZE : pageNo == 1 || pageNo == total ? SIZE + 1 : SIZE + 2;
PageItem[] pis = new PageItem[REAL_SIZE];
int begin = 0, end = pis.length - 1;
if (SIZE > 5) {
if (pageNo < total) pis[end--] = PageItem.last(pageNo + 1);
if (pageNo > 1) pis[begin++] = PageItem.first(pageNo - 1);
}
final int HALF = SIZE / 2, _HALF = HALF + 1;
int page = pageNo <= _HALF ? 1 : pageNo >= total - HALF ? total - SIZE + 1 : pageNo - HALF;
for (int i = begin; i <= end; i++, page++) {
pis[i] = PageItem.other(page, page == pageNo);
}
return pis;
}
}
Result
package pageUntil;
public class Result {
private boolean err;
private Object data;
public static Result succeed(Object data){
return new Result(false,data);
}
public static Result fail(){
return new Result(true,null);
}
public Result(boolean err, Object data) {
this.err = err;
this.data = data;
}
public boolean isErr() {
return err;
}
public Object getData() {
return data;
}
}