⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagedao.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
字号:
/*
 *
 */
package com.oa.module.communicate.comm.chat;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.Query;


/**
 * 即时通讯 分页
 * @author admin
 *
 */
public class PageDAO {

    public int currentpage = 1; // 当前是第几页

    public int pagecount = 0; // 一共有多少页

    public int rscount = 0; // 一共有多少行

    public int pagesize = 8; // 每页有多少行[默认为8行]

    public int getCurrentpage() {
        return currentpage;
    }

    public void setCurrentpage(int currentpage) {
        this.currentpage = currentpage;
    }

    public int getPagecount() {
        return pagecount;
    }

    public void setPagecount(int pagecount) {
        this.pagecount = pagecount;
    }

    public int getPagesize() {
        return pagesize;
    }

    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }

    public int getRscount() {
        return rscount;
    }

    public void setRscount(int rscount) {
        this.rscount = rscount;
    }

    /**
     * 传入query获取总记录数
     * @param query 
     */
    public int getRsCount(Query query) {
        try {
        	List list = query.list();
            if (list != null && list.size() > 0) {
                this.rscount = list.size();
            } else {
                this.rscount = 0;
            }
            
        } catch (Exception ex) {
            this.rscount = 0;
        }finally{
        	//HibernateSessionFactory.closeSession();
        }
        return this.rscount;
    }

    /**
     * 获取总页数
     * 
     * @return int
     */
    public int getPageCount() {
        try {
            this.pagecount = ((this.rscount - 1) / this.pagesize) + 1;
        } catch (Exception ex) {
            this.pagecount = 0;
        }
        return this.pagecount;
    }

    /**
     * 获取当前页码的设置
     * 
     * @return int
     */
    public int getCurrentPage(HttpServletRequest request) {
        try {
            if (request.getParameter("currentpage") != null
                    && Integer.parseInt(request.getParameter("currentpage")) > 1) {
                this.currentpage = Integer.parseInt(request
                        .getParameter("currentpage"));
            } else {
                this.currentpage = 1;
            }
        } catch (Exception ex) {
            this.currentpage = 1;
        }
        return this.currentpage;
    }

    /**
     * 生成分页工具条
     * 
     * @param fileName
     * @return String
     */
    public String pagetool(String fileName) {
        StringBuffer str = new StringBuffer();
        String temp = "";
        if (fileName.indexOf("?") == -1) {
            temp = "?";
        } else {
            temp = "&";
        }
        int ProPage = this.currentpage - 1;
        int Nextpage = this.currentpage + 1;
        str.append("<form mothed='post' name='pageform' action='" + fileName
                + "'>");
        str
                .append("<table width='100%' border='0' cellspacing='0' cellpadding='0' class='tr3 f_one'>");
        str.append("<tr>");
        str.append("<td width='5%'>&nbsp;</td>");
        str.append("<td height='26'>");
        str.append("共有记录" + this.rscount + "条&nbsp;&nbsp;&nbsp;");
        str.append("共" + this.pagecount + "页&nbsp;&nbsp;&nbsp;");
        str.append("每页" + this.pagesize + "记录&nbsp;&nbsp;&nbsp;");
        str.append("现在" + this.currentpage + "/" + this.pagecount + "页");
        str.append("</td><td>");
        if (this.currentpage > 1) {
            str.append("<a href='" + fileName + temp + "currentpage=1'>首页</a>");
            str.append("&nbsp;&nbsp;&nbsp;");
            str.append("<a href='" + fileName + temp + "currentpage=" + ProPage
                    + "'>上一页</a>");
            str.append("&nbsp;&nbsp;&nbsp;");
        } else {
            str.append("首页");
            str.append("&nbsp;&nbsp;&nbsp;");
            str.append("上一页");
            str.append("&nbsp;&nbsp;&nbsp;");
        }
        if (this.currentpage < this.pagecount) {
            str.append("<a href='" + fileName + temp + "currentpage="
                    + Nextpage + "'>下一页</a>");
            str.append("&nbsp;&nbsp;&nbsp;");
        } else {
            str.append("下一页");
            str.append("&nbsp;&nbsp;&nbsp;");
        }
        if (this.pagecount > 1 && this.currentpage != this.pagecount) {
            str.append("<a href='" + fileName + temp + "currentpage="
                    + pagecount + "'>尾页</a>");
            str.append("&nbsp;&nbsp;&nbsp;");
        } else {
            str.append("尾页");
            str.append("&nbsp;&nbsp;&nbsp;");
        }
        str.append("转到");
        str
                .append("<select name='currentpage' onchange='javascript:submit()'>");
        for (int j = 1; j <= pagecount; j++) {
            str.append("<option value='" + j + "'");
            if (currentpage == j) {
                str.append("selected");
            }
            str.append(">");
            str.append("" + j + "");
            str.append("</option>");
        }
        str.append("</select>页");
        str.append("</td><td width='5%'>&nbsp;</td></tr></table></form>");
        return str.toString();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -