-
Notifications
You must be signed in to change notification settings - Fork 5
07. PageUtil
晓寻遥 edited this page Nov 6, 2021
·
1 revision
the paging tool is not an encapsulation of database paging, but a conversion of paging methods. when we manually paging, we often use the page number + the number of pages per page, but some databases need to use the start position and the end position to indicate. Many times this conversion is prone to errors (boundary issues), so the PageUtil tool class is encapsulated.
convert the number of pages and the number of entries per page into a start position and an end position. this method is used for paging methods that do not include the end position.
public void transToStartEnd(){
// 10 20
int[] a = PageUtil.transToStartEnd(1, 10);
for(int i : a){
System.out.print(i + " ");
}
System.out.println();
// 0 10
int[] b = PageUtil.transToStartEnd(0, 10);
for(int i : b){
System.out.print(i + " ");
}
}
calculate the total number of pages based on the total.
public void totalPage(){
int a = PageUtil.totalPage(10, 3);
// 4
System.out.println(a);
}
to learn more, refer to the API documentation