📄 pagebean.java
字号:
package edu.scfc;
import java.sql.*;
import java.util.*;
public class PageBean {
private int curPage = 1;//当前是第几页
private int maxPage; //一共多少页
private int maxRowCount; //一共有多少行
public int rowsPerpage = 10; //每页多少行
Connection con = null;
public java.util.Vector data;
public PageBean() throws Exception {
this.setPageBean();
}
public void setMaxPage(int maxPage){
this.maxPage = maxPage;
}
public int getMaxPage(){
return this.maxPage;
}
public void setCurPage(int curPage){
this.curPage=curPage;
}
public int getCurPage(){
return this.curPage;
}
public void setMaxRowCount(int maxRowCount){
this.maxRowCount=maxRowCount;
}
public int getMaxRowCount(){
return this.maxRowCount;
}
public PageBean getResult(String page){
//得到要显示在本页显示的数据
try{
PageBean objpageBean = new PageBean();
Vector vc = new Vector();
int pageNum = Integer.parseInt(page);
Statement stmt = con.createStatement();
String strSql="select top " + pageNum * objpageBean.rowsPerpage + " * from TB_ReleaseInform order by ReleaseTime DESC";
ResultSet rs = stmt.executeQuery(strSql);
int i=0;
while(rs.next()){
if(i>(pageNum-1)*objpageBean.rowsPerpage-1){
Object[] obj = new Object[8];
obj[0] = rs.getString("ID").trim();
obj[1] = rs.getString("Title").trim();
obj[2] = rs.getString("Content").trim();
obj[3] = rs.getString("Promulgator").trim();
obj[4] = rs.getString("ReleaseDept").trim();
obj[5] = rs.getString("ReleaseTime").substring(0,19);
obj[6] = rs.getString("BrowerCount");
obj[7] = rs.getString("Statu").trim();
vc.add(obj);
}
i++;
}
rs.close();
stmt.close();
objpageBean.setCurPage(pageNum);
objpageBean.data=vc;
return objpageBean;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public PageBean getResultstatu(String page){
//得到要显示在本页显示的数据
try{
PageBean objpageBean = new PageBean();
Vector vc = new Vector();
int pageNum = Integer.parseInt(page);
Statement stmt = con.createStatement();
String strSql="select top " + pageNum * objpageBean.rowsPerpage + " * from TB_ReleaseInform order by ReleaseTime DESC";
ResultSet rs = stmt.executeQuery(strSql);
int i=0;
while(rs.next()){
if(i>(pageNum-1)*objpageBean.rowsPerpage-1){
Object[] obj = new Object[7];
obj[0] = rs.getString("Title").trim();
obj[1] = rs.getString("Content").trim();
obj[2] = rs.getString("Promulgator").trim();
obj[3] = rs.getString("ReleaseDept").trim();
obj[4] = rs.getString("ReleaseTime").substring(0,19);
obj[5] = rs.getString("BrowerCount");
obj[6] = rs.getString("Statu").trim();
vc.add(obj);
}
i++;
}
rs.close();
stmt.close();
objpageBean.setCurPage(pageNum);
objpageBean.data=vc;
return objpageBean;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public int getAvailableCount() throws Exception {
int ret = 0;
ConnDB objConnDB = new ConnDB();
con = objConnDB.getConnection();
Statement stmt = con.createStatement();
String strSql = "Select * from TB_ReleaseInform";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
ret++;
}
return ret;
}
public void setPageBean() throws Exception {
//得到总行数
this.setMaxRowCount(this.getAvailableCount());
if(this.maxRowCount % this.rowsPerpage==0){
//根据总行数计算总页数
this.maxPage = this.maxRowCount / this.rowsPerpage;
}else{
this.maxPage = this.maxRowCount / this.rowsPerpage + 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -