When there are too many data bars in the database, a page can not be displayed. This is to set up paging query. The first thing to use is the limit condition of database sql statement to realize grouping query.
The sql statement is roughly in the form of:
select * from table limit to start the index, showing the number of bars
With this statement, block queries are implemented and fixed number of entries are displayed on each page.
First, to realize background paging, we need to know how many pages it has and how many rows it has per page. This requires knowing how many rows it has in total. When calling sql statements, we also need to know the starting index of each page. The starting index is calculated according to the current number of pages, so we also need to know the current number of pages. After querying, we will return a list to store the current page data. Encapsulating these attributes and methods to get settings into a class has the following page class:
Class Page1 public class Page<T> { 2 private List<T> data;//Data list 3 private int pagenum;//page 4 private int pagesize;//Number of items displayed on the current page 5 private int rows;//Total number of banks 6 public Page(int rows,int pagenum, int pagesize) { 7 super(); 8 data=new ArrayList<>(); 9 this.rows=rows; 10 this.setPagesize(pagesize); 11 this.setPagenum(pagenum); 12 } 13 public Page() { 14 super(); 15 } 16 public int getPagenum() { 17 return pagenum; 18 } 19 public void setPagenum(int pagenum) { 20 if(pagenum>getTotalpage()) 21 { 22 this.pagenum=getTotalpage(); 23 } 24 else { 25 this.pagenum = pagenum; 26 } 27 if(pagenum<1) 28 { 29 this.pagenum=1; 30 } 31 } 32 public int getPagesize() { 33 return pagesize; 34 } 35 public void setPagesize(int pagesize) { 36 this.pagesize = pagesize; 37 } 38 public int getTotalpage() { 39 //Calculate the total number of pages 40 if(rows%pagesize==0) 41 { 42 return rows/pagesize; 43 } 44 else { 45 return rows/pagesize+1; 46 } 47 } 48 public int getRows() { 49 return rows; 50 } 51 public void setRows(int rows) { 52 this.rows = rows; 53 } 54 public int getIndexnum() { 55 //Get the index value 56 return pagesize*(pagenum-1); 57 } 58 public List<T> getData() { 59 return data; 60 } 61 public void setData(List<T> data) { 62 this.data = data; 63 } 64 }