Pager.java
package pers.kangxu.datautils.common; import java.io.Serializable; import java.util.List; public class Pagerimplements Serializable { private static final long serialVersionUID = 4542617637761955078L; private int currentPage = 1; private int pageSize = 10; private int pageTotal; private int recordTotal = 0; private int previousPage; private int nextPage; private int firstPage = 1; private int lastPage; private List content; // 以下set方式是需要赋值的 public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public void setRecordTotal(int recordTotal) { this.recordTotal = recordTotal; otherAttr(); } public void setContent(List content) { this.content = content; } public void otherAttr() { // 总页数 this.pageTotal = this.recordTotal % this.pageSize > 0 ? this.recordTotal / this.pageSize + 1 : this.recordTotal / this.pageSize; // 第一页 this.firstPage = 1; // 最后一页 this.lastPage = this.pageTotal; // 前一页 if (this.currentPage > 1) { this.previousPage = this.currentPage - 1; } else { this.previousPage = this.firstPage; } // 下一页 if (this.currentPage < this.lastPage) { this.nextPage = this.currentPage + 1; } else { this.nextPage = this.lastPage; } } // 放开私有属性 public int getCurrentPage() { return currentPage; } public int getPageSize() { return pageSize; } public int getPageTotal() { return pageTotal; } public int getRecordTotal() { return recordTotal; } public int getPreviousPage() { return previousPage; } public int getNextPage() { return nextPage; } public int getFirstPage() { return firstPage; } public int getLastPage() { return lastPage; } public List getContent() { return content; } @Override public String toString() { return "Pager [currentPage=" + currentPage + ", pageSize=" + pageSize + ", pageTotal=" + pageTotal + ", recordTotal=" + recordTotal + ", previousPage=" + previousPage + ", nextPage=" + nextPage + ", firstPage=" + firstPage + ", lastPage=" + lastPage + ", content=" + content + "]"; } }
使用 PagerTester.java
package pers.kangxu.datautils.utils;
import java.util.ArrayList;
import java.util.List;
import pers.kangxu.datautils.common.Pager;
public class PagerTester {
public static void main(String[] args) {
Pager pager = new Pager();
List content = new ArrayList();
content.add("str1");
content.add("str2");
content.add("str3");
content.add("str4");
content.add("str5");
content.add("str6");
content.add("str7");
content.add("str8");
content.add("str9");
content.add("str10");
pager.setCurrentPage(1);
pager.setPageSize(10);
pager.setRecordTotal(62);
pager.setContent(content);
System.out.println(pager);
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持考高分网!



