JAVA paging tool class and its usage, java paging tool class

Source: Internet
Author: User

JAVA paging tool class and its usage, java paging tool class

Pager. java

1 package pers. kangxu. datautils. common; 2 3 import java. io. serializable; 4 import java. util. list; 5 6/** 7*8 * <B> generic paging class </B> 9*10 * @ author kangxu 11 * @ param <T> 12*13 */14 public class Pager <T> implements Serializable {15 16/** 17*18 */19 private static final long serialVersionUID = 4542617637761955078L; 20 21/** 22 * currentPage current page 23 */24 private int currentPage = 1; 25/** 26 * PageSize 27 */28 private int pageSize = 10; 29/** 30 * Total pageTotal pages 31 */32 private int pageTotal; 33/** 34 * Total recordTotal number of items 35 */36 private int recordTotal = 0; 37/** 38 * previousPage Previous Page 39 */40 private int previousPage; 41/** 42 * nextPage next page 43 */44 private int nextPage; 45/** 46 * firstPage first page 47 */48 private int firstPage = 1; 49/** 50 * lastPage last page 51 */52 private Int lastPage; 53/** 54 * content 55 */56 private List per page <T> content; 57 58 // The following set method is the 59/** 60 * value to be assigned to set the current page <br> 61*62 * @ author kangxu 63*64 * @ param currentPage 65 */ 66 public void setCurrentPage (int currentPage) {67 this. currentPage = currentPage; 68} 69 70/** 71 * sets the size of each page, or you do not need to assign a value, the default size is 10 <br> 72*73 * @ author kangxu 74*75 * @ param pageSize 76 */77 public void setPageSize (in T pageSize) {78 this. pageSize = pageSize; 79} 80 81/** 82 * set the total number of entries, the default value is 0 <br> 83*84 * @ author kangxu 85*86 * @ param recordTotal 87 */88 public void setRecordTotal (int recordTotal) {89 this. recordTotal = recordTotal; 90 otherAttr (); 91} 92 93/** 94 * set the page content <br> 95*96 * @ author kangxu 97*98 * @ param content 99 */100 public void setContent (List <T> content) {101 this. content = content; 10 2} 103 104/** 105 * set other parameters 106*107 * @ author kangxu108 * 109 */110 public void otherAttr () {111 // total page number 112 this. pageTotal = this. recordTotal % this. pageSize> 0? This. recordTotal/this. pageSize + 1: this. recordTotal/this. pageSize; 113 // page 1 114 this. firstPage = 1; 115 // The last page 116 this. lastPage = this. pageTotal; 117 // the first page of 118 if (this. currentPage> 1) {119 this. previousPage = this. currentPage-1; 120} else {121 this. previousPage = this. firstPage; 122} 123 // next page 124 if (this. currentPage <this. lastPage) {125 this. nextPage = this. currentPage + 1; 126} else {127 this. nextPage = this. lastPage; 128} 129} 130 131 // release the private property 132 public int getCurrentPage () {133 return currentPage; 134} 135 136 public int getPageSize () {137 return pageSize; 138} 139 140 public int getPageTotal () {141 return pageTotal; 142} 143 144 public int getRecordTotal () {145 return recordTotal; 146} 147 148 public int getPreviousPage () {149 return previousPage; 150} 151 152 public int getNextPage () {153 return nextPage; 154} 155 156 public int getFirstPage () {157 return firstPage; 158} 159 160 public int getLastPage () {161 return lastPage; 162} 163 164 public List <T> getContent () {165 return content; 166} 167 168 @ Override169 public String toString () {170 return "Pager [currentPage =" + currentPage + ", pageSize =" + pageSize171 + ", pageTotal = "+ pageTotal +", recordTotal = "+ response +", previousPage = "+ previousPage +", nextPage = "+ nextPage173 +", firstPage = "+ firstPage + ", lastPage = "+ lastPage174 +", content = "+ content +"] "; 175} 176 177 178}

Use PagerTester. java

1 package pers. kangxu. datautils. utils; 2 3 import java. util. arrayList; 4 import java. util. list; 5 6 import pers. kangxu. datautils. common. pager; 7 8/** 9 * Paging data test 10 * <B> 11*12 * </B> 13 * @ author kangxu14 * 15 */16 public class PagerTester {17 18 public static void main (String [] args) {19 20 Pager <String> pager = new Pager <String> (); 21 22 List <String> content = new ArrayList <String> (); 23 content. add ("str1"); 24 content. add ("str2"); 25 content. add ("str3"); 26 content. add ("str4"); 27 content. add ("str5"); 28 content. add ("str6"); 29 content. add ("str7"); 30 content. add ("str8"); 31 content. add ("str9"); 32 content. add ("str10"); 33 34 pager. setCurrentPage (1); 35 pager. setPageSize (10); 36 pager. setRecordTotal (62); 37 pager. setContent (content); 38 39 System. out. println (pager); 40 41} 42 43}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.