关于分页不足的地方请指出
对于分页的实现应该具有这样的一个JAVABEAN ;package com.yangli.oa.model.utils;
import
import javax.servlet.http.HttpServletRequest;
import com.yangli.oa.model.dao.DoctypeDao;
public class PageBean implements Serializable {
/**
* @author yangli
*
*/
private static final long serialVersionUID = 1642421144068117709L;
private DoctypeDao doctypedao = new DoctypeDao();
/**
* currenpageNumber 当前页号
*
* maxpageNumber 最大页号获得方法应为数据库的最大记录/每页记录数 具体实现方法 当前类的getMaxpageNumber方法
*
* pageNumber 每页记录数
*
* IcurrenpageNumber 用于从页面获得的currenpageNumber 进行Integer 转换 所得 具体实现 为类的构造方法
*/
private Integer currenpageNumber;
private Integer maxpageNumber;
private Integer pageNumber;
Integer IcurrenpageNumber;
public PageBean(HttpServletRequest request, Integer pageNumber) {
String currenpageNumber = request.getParameter("currenpageNumber");
try {
IcurrenpageNumber = Integer.parseInt(currenpageNumber);
} catch (NumberFormatException e) {
// 如果 currenpageNumber 为null值 进行下面设置
IcurrenpageNumber = this.currenpageNumber;
}
this.pageNumber = pageNumber;
this.currenpageNumber = IcurrenpageNumber;
}
public Integer getPageNumber() {
return pageNumber;
}
public void setPageNumber(Integer pageNumber) {
this.pageNumber = pageNumber;
}
public Integer getCurrenpageNumber() {
if (currenpageNumber == null || currenpageNumber < 1) {
currenpageNumber = 1;
}
return currenpageNumber;
}
public void setCurrenpageNumber(Integer currenpageNumber) {
this.currenpageNumber = currenpageNumber;
}
public Integer getMaxpageNumber() {
if (doctypedao.getMaxpagenumber() != 0) {
if (doctypedao.getMaxpagenumber() % this.getPageNumber() != 0) {
maxpageNumber = doctypedao.getMaxpagenumber()
/ this.getPageNumber() + 1;
} else {
maxpageNumber = doctypedao.getMaxpagenumber()
/ this.getPageNumber();
}
} else {
maxpageNumber = 1;
}
return maxpageNumber;
}
public void setMaxpageNumber(Integer maxpageNumber) {
this.maxpageNumber = maxpageNumber;
}
}
//DAO类中应有这样的两种方法
@SuppressWarnings("unchecked")
public List<Doctype> findDoctypeByPage(PageBean page) {
Integer Arg1 = page.getCurrenpageNumber();
Integer Arg2 = page.getPageNumber();
Session session = HibernateSessionFactory.getSession();
Criteria c = session.createCriteria(Doctype.class);
c.setFirstResult(Arg1 * Arg2 - Arg2);
c.setMaxResults(Arg2);
return c.list();
}
public Integer getMaxpagenumber() {
Session session = HibernateSessionFactory.getSession();
Query query = session.createQuery("select count(*)from Doctype");
return (Integer) query.uniqueResult();
}
//一个公共的分页JSP page.jsp
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@include file="/common/taglib.jsp"%>
<td width="62%">
<p align="right">
<font color="#008080">共</font><font color="#800000">
${page.maxpageNumber }</font><font color="#008080"> 页 <font
color="#008080">/ 当前第</font><font color="#800000">
${page.currenpageNumber }</font><font color="#008080"> 页 <c:if
test="${page.currenpageNumber == 1}">
首页
</c:if> <c:if test="${page.currenpageNumber!=1 }">
<a
href="${pageContext.request.contextPath }/doctype.do?method=list¤pageNumber=1">首页</a>
</c:if> <c:if test="${page.currenpageNumber==1 }">
上一页
</c:if> <c:if test="${page.currenpageNumber!=1 }">
<a
href="${pageContext.request.contextPath }/doctype.do?method=list¤pageNumber=${page.currenpageNumber-1}">上一页
</a>
</c:if> <c:if test="${page.currenpageNumber==page.maxpageNumber }">
下一页
</c:if> <c:if test="${page.currenpageNumber!=page.maxpageNumber }">
<a
href="${pageContext.request.contextPath }/doctype.do?method=list¤pageNumber=${page.currenpageNumber+1 }">下一页</a>
</c:if> <c:if test="${page.currenpageNumber ==page.maxpageNumber }">
尾页
</c:if> <c:if test="${page.currenpageNumber !=page.maxpageNumber }">
<a
href="${pageContext.request.contextPath }/doctype.do?method=list¤pageNumber=${page.maxpageNumber }">尾页 </a>
</c:if>
</td>
//页面上只需用jsp include就可以直接使用了!
<jsp:include flush="true" page="/common/page.jsp"></jsp:includ
[[it] 本帖最后由 yangli 于 2008-2-10 01:39 编辑 [/it]]