| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 934 人关注过本帖
标题:关于分页不足的地方请指出
只看楼主 加入收藏
yangli
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-2-10
收藏
 问题点数:0 回复次数:1 
关于分页不足的地方请指出
对于分页的实现应该具有这样的一个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&currenpageNumber=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&currenpageNumber=${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&currenpageNumber=${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&currenpageNumber=${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]]
搜索更多相关主题的帖子: import yangli DoctypeDao model java 
2008-02-10 01:37
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
得分:0 
注意一下层分离,代码重用

2008-02-13 06:48
快速回复:关于分页不足的地方请指出
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057481 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved