jsp hibernate的分页代码第1/3页
程序员文章站
2022-06-21 23:50:19
可见使用hibernate,在进行查询分页的操作上,是具有非常大的灵活性,hibernate会首先尝试用特定数据库的分页sql,如果没用,再尝试scrollable,如果不...
可见使用hibernate,在进行查询分页的操作上,是具有非常大的灵活性,hibernate会首先尝试用特定数据库的分页sql,如果没用,再尝试scrollable,如果不行,最后采用rset.next()移动的办法。
(一)pager类
* @(#)pager.java 2005-5-3
*
* copyright (c) 2005, jeffrey hsu
*/
package com.jeffrey.messagelove;
/**
* pager holds the page info.
*/
public class pager {
private int totalrows = 0; // 记录总数
private int totalpages = 0; // 总页数
private int pagesize = 10; // 每页显示数据条数,默认为10条记录
private int currentpage = 1; // 当前页数
private boolean hasprevious = false; // 是否有上一页
private boolean hasnext = false; // 是否有下一页
public pager() {
}
/**
* initialize pager
* @param totalrows total record rows
* @param pagesize total record is hold by every page
*/
public void init(int totalrows, int pagesize) {
this.totalrows = totalrows;
this.pagesize = pagesize;
totalpages = ((totalrows + pagesize) - 1) / pagesize;
refresh(); // 刷新当前页面信息
}
/**
* @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();
}
// 跳到第一页
public void first() {
currentpage = 1;
this.sethasprevious(false);
refresh();
}
// 取得上一页(重新设定当前页面即可)
public void previous() {
currentpage--;
refresh();
}
// 取得下一页
public void next() {
system.out.println("next: totalpages: " + totalpages +
" currentpage : " + currentpage);
if (currentpage < totalpages) {
currentpage++;
}
refresh();
}
// 跳到最后一页
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;
}
(一)pager类
* @(#)pager.java 2005-5-3
*
* copyright (c) 2005, jeffrey hsu
*/
package com.jeffrey.messagelove;
/**
* pager holds the page info.
*/
public class pager {
private int totalrows = 0; // 记录总数
private int totalpages = 0; // 总页数
private int pagesize = 10; // 每页显示数据条数,默认为10条记录
private int currentpage = 1; // 当前页数
private boolean hasprevious = false; // 是否有上一页
private boolean hasnext = false; // 是否有下一页
public pager() {
}
/**
* initialize pager
* @param totalrows total record rows
* @param pagesize total record is hold by every page
*/
public void init(int totalrows, int pagesize) {
this.totalrows = totalrows;
this.pagesize = pagesize;
totalpages = ((totalrows + pagesize) - 1) / pagesize;
refresh(); // 刷新当前页面信息
}
/**
* @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();
}
// 跳到第一页
public void first() {
currentpage = 1;
this.sethasprevious(false);
refresh();
}
// 取得上一页(重新设定当前页面即可)
public void previous() {
currentpage--;
refresh();
}
// 取得下一页
public void next() {
system.out.println("next: totalpages: " + totalpages +
" currentpage : " + currentpage);
if (currentpage < totalpages) {
currentpage++;
}
refresh();
}
// 跳到最后一页
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;
}
1