PageItem

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

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值