public class PageView<T> {
/**查询记录集合**/
List<T> records;
/**当前页码**/
int currentPage = 1;
/**记录总数目**/
long totalCount;
/**每页显示记录数**/
int perPage = 10;
/**总页数**/
long totalPage;
/**当前页记录起始索引**/
int index;
/**需要在分页中显示的页码索引数**/
long pageRange = 10;
/**需要在分页中显示的页码索引范围**/
PageIndex pageIndex;
public List<T> getRecords() {
return records;
}
public void setRecords(List<T> records) {
this.records = records;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
setTotalPage((totalCount % perPage) == 0 ? (totalCount / perPage) : (totalCount / perPage + 1));
}
public int getPerPage() {
return perPage;
}
public void setPerPage(int perPage) {
this.perPage = perPage;
}
public long getTotalPage() {
return totalPage;
}
public void setTotalPage(long totalPage) {
this.totalPage = totalPage;
}
public int getIndex(){
return (currentPage-1) * perPage;
}
public long getPageRange() {
return pageRange;
}
public void setPageRange(long pageRange) {
this.pageRange = pageRange;
}
public PageIndex getPageIndex() {
long beginPage = this.currentPage - (this.pageRange%2 == 0 ? this.pageRange/2 - 1 : this.pageRange/2);
long endPage = this.currentPage + this.pageRange/2;
if(beginPage < 1){
beginPage = 1;
if(pageRange <= totalPage) endPage = this.pageRange;
else endPage = totalPage;
}
if(endPage > totalPage){
endPage = totalPage;
if(endPage - this.pageRange > 0) beginPage = endPage - pageRange + 1;
else beginPage = 1;
}
this.pageIndex = new PageIndex(beginPage, endPage);
return pageIndex;
}
}
/**查询记录集合**/
List<T> records;
/**当前页码**/
int currentPage = 1;
/**记录总数目**/
long totalCount;
/**每页显示记录数**/
int perPage = 10;
/**总页数**/
long totalPage;
/**当前页记录起始索引**/
int index;
/**需要在分页中显示的页码索引数**/
long pageRange = 10;
/**需要在分页中显示的页码索引范围**/
PageIndex pageIndex;
public List<T> getRecords() {
return records;
}
public void setRecords(List<T> records) {
this.records = records;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
setTotalPage((totalCount % perPage) == 0 ? (totalCount / perPage) : (totalCount / perPage + 1));
}
public int getPerPage() {
return perPage;
}
public void setPerPage(int perPage) {
this.perPage = perPage;
}
public long getTotalPage() {
return totalPage;
}
public void setTotalPage(long totalPage) {
this.totalPage = totalPage;
}
public int getIndex(){
return (currentPage-1) * perPage;
}
public long getPageRange() {
return pageRange;
}
public void setPageRange(long pageRange) {
this.pageRange = pageRange;
}
public PageIndex getPageIndex() {
long beginPage = this.currentPage - (this.pageRange%2 == 0 ? this.pageRange/2 - 1 : this.pageRange/2);
long endPage = this.currentPage + this.pageRange/2;
if(beginPage < 1){
beginPage = 1;
if(pageRange <= totalPage) endPage = this.pageRange;
else endPage = totalPage;
}
if(endPage > totalPage){
endPage = totalPage;
if(endPage - this.pageRange > 0) beginPage = endPage - pageRange + 1;
else beginPage = 1;
}
this.pageIndex = new PageIndex(beginPage, endPage);
return pageIndex;
}
}