首页 > 代码库 > PageUtil

PageUtil

  1 package cn.com.qmhd.oto.common;
  2 
  3 
  4 import java.io.Serializable;
  5 import java.util.List;
  6 
  7 import org.springframework.data.domain.PageImpl;
  8 
  9 /**
 10  * 转换为json时需要的bean
 11  * @version 1.0
 12  * @时间 2016年9月14日
 13  * @描述
 14  */
 15 public class Page<T> implements Serializable {
 16     
 17     private static final long serialVersionUID = -3640039664184539350L;
 18         //当前页
 19         private long page;
 20         //前一页
 21         private long prePage;
 22         //后一页
 23         private long nextPage;
 24         //每页大小
 25         private long pageSize;
 26         //总条数
 27         private long totalCount;
 28         //总页数
 29         private long pageCount;
 30         //当前页数据
 31         private List<T> rows;
 32         /**
 33          * @return the page
 34          */
 35         public long getPage() {
 36             return page;
 37         }
 38         /**
 39          * @param page the page to set
 40          */
 41         public void setPage(long page) {
 42             this.page = page;
 43         }
 44         /**
 45          * @return the prePage
 46          */
 47         public long getPrePage() { 
 48             return prePage;
 49         }
 50         /**
 51          * @param prePage the prePage to set
 52          */
 53         public void setPrePage(long prePage) {
 54             this.prePage = prePage;
 55         }
 56         /**
 57          * @return the nextPage
 58          */
 59         public long getNextPage() {
 60             if(nextPage<=0){
 61                 return 1;
 62             }else{
 63                 return nextPage>pageCount?pageCount:nextPage;
 64             }
 65         }
 66         /**
 67          * @param nextPage the nextPage to set
 68          */
 69         public void setNextPage(long nextPage) {
 70             this.nextPage = nextPage;
 71         }
 72         /**
 73          * @return the pageSize
 74          */
 75         public long getPageSize() {
 76             return pageSize;
 77         }
 78         /**
 79          * @param pageSize the pageSize to set
 80          */
 81         public void setPageSize(long pageSize) {
 82             this.pageSize = pageSize<=0?10:pageSize;
 83         }
 84         /**
 85          * @return the totalCount
 86          */
 87         public long getTotalCount() {
 88             return totalCount;
 89         }
 90         /**
 91          * @param totalCount the totalCount to set
 92          */
 93         public void setTotalCount(long totalCount) {
 94             this.totalCount = totalCount;
 95         }
 96         /**
 97          * @return the pageCount
 98          */
 99         public long getPageCount() {
100             return pageCount;
101         }
102         /**
103          * @param pageCount the pageCount to set
104          */
105         public void setPageCount(long pageCount) {
106             this.pageCount = pageCount;
107         }
108         /**
109          * @return the rows
110          */
111         public List<T> getRows() {
112             return rows;
113         }
114         /**
115          * @param rows the rows to set
116          */
117         public void setRows(List<T> rows) {
118             this.rows = rows;
119         }
120         public void resetNextPage(){
121             nextPage=page+1;
122             this.prePage = page -1>0?page-1:1;
123             pageCount=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
124         }
125         
126         public Page(org.springframework.data.domain.Page<T> pageImpl) {
127             if(pageImpl!=null){
128                 this.page = pageImpl.getNumber()+1;
129                 this.pageSize = pageImpl.getSize();
130                 this.rows = pageImpl.getContent();
131                 this.totalCount = pageImpl.getTotalElements();
132                 this.pageCount = pageImpl.getTotalPages();
133                 resetNextPage();
134             }
135         }
136         public Page() {
137         }
138 }

 

PageUtil