Pager.java
package pers.kangxu.datautils.common;import java.io.Serializable;import java.util.List;/** * * <b> Pagination general class</b> * * @author kangxu * @param <T> * */public class Pager<T> implements Serializable { /** * */ private static final long serialVersionUID = 4542617637761955078L; /** * currentPage Current page*/ private int currentPage = 1; /** * pageSize Per page size*/ private int pageSize = 10; /** * pageTotal number of pages*/ private int pageTotal; /** * recordTotal number of pieces*/ private int recordTotal = 0; /** * previousPage Previous page*/ private int previousPage; /** * nextPage Next page*/ private int nextPage; /** * firstPage First page*/ private int firstPage = 1; /** * lastPage Last page*/ private int lastPage; /** * content Content of each page*/ private List<T> content; // The following set method requires assignment /** * Set the current page<br> * * @author kangxu * * @param currentPage */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } /** * Set the size of each page, you can also do not need to assign values. The default size is 10 items<br> * * @author kangxu * * @param pageSize */ public void setPageSize(int pageSize) { this.pageSize = pageSize; } /** * Set the total number of items, the default is 0 <br> * * @author kangxu * * @param recordTotal */ public void setRecordTotal(int recordTotal) { this.recordTotal = recordTotal; otherAttr(); } /** * Set the page content<br> * * @author kangxu * * @param content */ public void setContent(List<T> content) { this.content = content; } /** * Set other parameters* * @author kangxu * */ public void otherAttr() { // Total number of pages this.pageTotal = this.recordTotal % this.pageSize > 0 ? this.recordTotal / this.pageSize + 1 : this.recordTotal / this.pageSize; // First page this.firstPage = 1; // Last page this.lastPage = this.pageTotal; // Previous page if (this.currentPage > 1) { this.previousPage = this.currentPage - 1; } else { this.previousPage = this.firstPage; } // Next page if (this.currentPage < this.lastPage) { this.nextPage = this.currentPage + 1; } else { this.nextPage = this.lastPage; } } // Let go of the private attributes 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<T> 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 + "]"; }}Using PagerTester.java
package pers.kangxu.datautils.utils;import java.util.ArrayList;import java.util.List;import pers.kangxu.datautils.common.Pager;/** * Pagination data test* <b> * * </b> * @author kangxu * */public class PagerTester { public static void main(String[] args) { Pager<String> pager = new Pager<String>(); List<String> content = new ArrayList<String>(); 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); }}The above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!