使用Hibernate分页问题
使用hibernate调用自己的分页类 第一页数据出来了 但是没有下一页的数据 页码也没有 走断点总记录数和页码的分组数都计算出来了
这是分页类
package cn.jbit.renting.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Java Bean
* @author Administrator
*
*/
public class Pager implements Serializable{
//public static final int PAGE_RECORD = 6;
public static final int GROUP_RECORD = 5;//显示几组
public static int page_record;//每页显示几条数据
private int currentPage; // 当前页码
private int pageCount; // 总页数
private int recordCount; // 总记录数
private int currentGroup; // 当前组数
private int groupCount; // 总组数
private List<Integer> groupList; // 页面中需要的分组页索引
public int prevPage;
public int nextPage;
public int getPage_record() {
return page_record;
}
public void setPage_record(int page_record) {
this.page_record = page_record;
}
// 构造函数
public Pager(int page){
currentPage = page;
}
// 获取当前页页码
public int getCurrentPage(){
return currentPage;
}
// 获取下一页页码
public int getNextPage(){
if(currentPage < pageCount)
return currentPage+1;
else
return pageCount;
}
// 获取上一页页码
public int getPrevPage(){
if(currentPage <= 1)
return 1;
else
return currentPage - 1;
}
// 获取当前组数
public int getCurrentGroup(){
return currentGroup;
}
public List<Integer> getGroupList(){
// 计算当前组数
currentGroup = (int)Math.ceil((float)currentPage / GROUP_RECORD);
groupList = new ArrayList<Integer>();
int start = (currentGroup-1) * GROUP_RECORD;
int end = (start + GROUP_RECORD) < pageCount ? start + GROUP_RECORD : pageCount;
for (int i = start + 1; i <= end; i++) {
groupList.add(i);
}
return groupList;
}
// 获取总页数
public int getPageCount(){
return pageCount;
}
// 设置总记录数
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
pageCount = (int)Math.ceil(((float)recordCount / page_record));
}
// 获取总记录数
public int getRecordCount() {
return recordCount;
}
}
方法调用
/***
* 分页
*/
public List<House> SearchpageHouse(Pager pager) {
if(pager.getRecordCount() == 0){
pager.setRecordCount(getHouse().size());//总共多少条记录
}
String hql="from House";
Query query=session.createQuery(hql);
int start=(pager.getCurrentPage() - 1) * Pager.page_record;//起始位置
query.setFirstResult(start);
query.setMaxResults(start + Pager.page_record);//结束为止
List<House> list=query.list();
return list;
}
servlet里的调用
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
response.setContentType("text/html;UTF-8");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
// HouseBiz house=new HouseBizImpl();
// List<House> houses=house.getHouse();
// request.setAttribute("houses", houses);
// request.getRequestDispatcher("MyJsp.jsp").forward(request, response);
HouseBiz hb=new HouseBizImpl();
String page=request.getParameter("page");