ReqPage.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:3k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.affair.affairreq;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- /**
- * 事务列表 页面 分页
- * @author student
- *
- */
- public class ReqPage {
- private SessionFactory sf;
- Session session = null;
- private int count;
- private int currentPage;
- private int allcount;
- private String path;
- public ReqPage(){
- }
- public ReqPage getPage(int currentPage,int count,String sql){
- this.currentPage = currentPage;
- this.count= count;
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- session = sf.openSession();
- conn = session.connection();
- try {
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- while(rs.next()){
- this.allcount =rs.getInt(1);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return this;
- }
- public int getAllcount() {
- return allcount;
- }
- public void setAllcount(int allcount) {
- this.allcount = allcount;
- }
- public int getCount() {
- return count;
- }
- public void setCount(int count) {
- this.count = count;
- }
- public int getCurrentPage() {
- return currentPage;
- }
- public void setCurrentPage(int currentPage) {
- this.currentPage = currentPage;
- }
- public int getAllPage(){
- return (this.allcount-1)/this.count+1;
- }
- public String getPath() {
- return path;
- }
- public void setPath(String path) {
- this.path = path;
- }
- public String getPageBar(){
- StringBuffer bar = new StringBuffer();
- bar.append("<%");
- bar.append("String contextPath = request.getContextPath();");
- bar.append("%>");
- bar.append("<link href='<%=request.getContextPath()%>/Css_file/oa.css' type='text/css' rel='stylesheet' />");
- bar.append("<tr border='0'>");
- bar.append("<div class='tableHead'><span align="left" style='margin-left:10px'>当前"+this.currentPage+"/"+this.getAllPage()+"共"+this.allcount+"条记录</span>");
- bar.append("<span align=right style='margin-right:10px;margin-left:100px'>");
- if(this.currentPage<=1){
- bar.append("首页 上页 ");
- }else{
- bar.append("<a href=""+path+"currentPage=1">首页</a> ");
- bar.append("<a href=""+path+"currentPage="+(this.currentPage-1)+"">上页</a> ");
- }
- if(this.currentPage>=this.getAllPage()){
- bar.append("下页 尾页");
- }else{
- bar.append("<a href=""+path+"currentPage="+(this.currentPage+1)+"">下页</a> ");
- bar.append("<a href=""+path+"currentPage="+(this.getAllPage())+"">尾页</a>");
- }
- bar.append(" <select style='width:35' name="page" onchange="forward(this.value)">");
- for(int i=1;i<=this.getAllPage();i++){
- if(i==this.currentPage){
- bar.append("<option value='"+i+"' selected>"+i+"</option>");
- }else{
- bar.append("<option value='"+i+"'>"+i+"</option>");
- }
- }
- bar.append("</select></span></div>");
- bar.append("</tr>");
- bar.append("<script>");
- bar.append("function forward(page){")
- .append(" location.href='"+path+"currentPage='+page;")
- .append("}");
- bar.append("</script>");
- return bar.toString();
- }
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- }