Java分页查询工具类

public class PageList<T> {

    private int totalpage;     //总页数  
    private int totalcount;    //总记录数  
    private int currentpage;   //当前页  
    private int pagesize;      //每页的数量  
    private int firstpage;     //第一页
    private int lastpage;  //最后一页
    private int prepage;  //上一页
    private int nextpage;  //下一页
    private boolean isprepage;  //是否有上一页
    private boolean isnextpage;  //是否有下一页
    private List<T> result = new ArrayList<T>(); 
      
    /**
         * 构造方法描述
         * 
         * @param result 返回结果
         * @param currentpage 当前页数
         * @param pagesize 每页的数量  
         * @param totalcount 总记录数 
     */
    public PageList(List<T> result,int currentpage, int pagesize, int totalcount){
        this.result = result;
        this.currentpage = currentpage;  
        this.pagesize = pagesize;  
        this.totalcount = totalcount;  
        
        if(pagesize == 0 || totalcount == 0){
            return ;
        }
        
        if(currentpage < 1){  
            this.currentpage = 1;  
        }  
        
        if (totalcount % pagesize == 0) {
            this.totalpage = totalcount / pagesize;
        } else {
            this.totalpage = totalcount / pagesize + 1;
        }
        
        this.firstpage =1;  
        this.lastpage = totalpage;  
        
        

        if(this.currentpage > 1){  
            this.prepage = this.currentpage - 1;  
        }else{  
            this.prepage = 1;  
        }  
          
        if(this.currentpage < totalpage){  
            this.nextpage = this.currentpage + 1;   
        }else{  
            this.nextpage = totalpage;  
        }  
          
        if(this.currentpage <= 1){  
            this.isprepage = false;  
        }else{  
            this.isprepage = true;  
        }  
          
        if(this.currentpage >= totalpage){  
            this.isnextpage = false;  
        }else{  
            this.isnextpage = true;  
        }  
    }

    public int getTotalpage() {
        return totalpage;
    }

    public void setTotalpage(int totalpage) {
        this.totalpage = totalpage;
    }

    public int getTotalcount() {
        return totalcount;
    }

    public void setTotalcount(int totalcount) {
        this.totalcount = totalcount;
    }

    public int getCurrentpage() {
        return currentpage;
    }

    public void setCurrentpage(int currentpage) {
        this.currentpage = currentpage;
    }

    public int getPagesize() {
        return pagesize;
    }

    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }

    public int getFirstpage() {
        return firstpage;
    }

    public void setFirstpage(int firstpage) {
        this.firstpage = firstpage;
    }

    public int getLastpage() {
        return lastpage;
    }

    public void setLastpage(int lastpage) {
        this.lastpage = lastpage;
    }

    public int getPrepage() {
        return prepage;
    }

    public void setPrepage(int prepage) {
        this.prepage = prepage;
    }

    public int getNextpage() {
        return nextpage;
    }

    public void setNextpage(int nextpage) {
        this.nextpage = nextpage;
    }

    public boolean isIsprepage() {
        return isprepage;
    }

    public void setIsprepage(boolean isprepage) {
        this.isprepage = isprepage;
    }

    public boolean isIsnextpage() {
        return isnextpage;
    }

    public void setIsnextpage(boolean isnextpage) {
        this.isnextpage = isnextpage;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }  
    
    
    
}
原文地址:https://www.cnblogs.com/zhaojinhui/p/4981462.html