Visible use of Hibernate, in the query paging operation, is very flexible, hibernate will first attempt to use a specific database paging SQL, if no use, and then try to scrollable, if not, the final use of Rset.next () mobile approach.
(i) Pager class
* @ (#) Pager.java 2005-5-3
*
* Copyright (c), Jeffrey Hsu
*/
Package com.jeffrey.messagelove;
/**
* Pager holds the page info.
*/
public class Pager {
private int totalrows = 0; Total Records
private int totalpages = 0; Total pages
private int pageSize = 10; Display the number of data bars per page, default to 10 records
private int currentpage = 1; Current page
Private Boolean hasprevious = false; Whether there is a previous page
Private Boolean hasnext = false; Whether there is a next page
Public Pager () {
}
/**
* Initialize Pager
* @param totalrows Total record rows
* @param pageSize Total, hold by every page
*/
public void init (int totalrows, int pageSize) {
This.totalrows = totalrows;
This.pagesize = pageSize;
TotalPages = ((Totalrows + pageSize)-1)/pageSize;
Refresh (); Refresh current Page Information
}
/**
* @return Returns the currentpage.
*/
public int getcurrentpage () {
return currentpage;
}
/**
* @param currentpage Current page
*/
public void setcurrentpage (int currentpage) {
This.currentpage = CurrentPage;
Refresh ();
}
/**
* @return Returns the pageSize.
*/
public int getpagesize () {
return pageSize;
}
/**
* @param pageSize the pageSize to set.
*/
public void setpagesize (int pageSize) {
This.pagesize = pageSize;
Refresh ();
}
/**
* @return Returns the totalpages.
*/
public int gettotalpages () {
return totalpages;
}
/**
* @param totalpages the totalpages to set.
*/
public void settotalpages (int totalpages) {
This.totalpages = TotalPages;
Refresh ();
}
/**
* @return Returns the totalrows.
*/
public int gettotalrows () {
return totalrows;
}
/**
* @param totalrows the totalrows to set.
*/
public void settotalrows (int totalrows) {
This.totalrows = totalrows;
Refresh ();
}
Skip to First page
public void-A-I () {
CurrentPage = 1;
This.sethasprevious (FALSE);
Refresh ();
}
Get the previous page (reset the current page)
public void Previous () {
currentpage--;
Refresh ();
}
Get the next page
public void Next () {
System.out.println ("next:totalpages:" + totalpages +
"CurrentPage:" + currentpage);
if (CurrentPage < totalpages) {
currentpage++;
}
Refresh ();
}
Skip to last Page
public void Last () {
CurrentPage = TotalPages;
This.sethasnext (FALSE);
Refresh ();
}
public Boolean ishasnext () {
return hasnext;
}
/**
* @param hasnext the Hasnext to set.
*/
public void Sethasnext (Boolean hasnext) {
This.hasnext = Hasnext;
}
public Boolean ishasprevious () {
return hasprevious;
}
/**
* @param hasprevious the hasprevious to set.
*/
public void Sethasprevious (Boolean hasprevious) {
this.hasprevious = hasprevious;
}
Current 1/3 page
123 Next read the full text