package nm;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Pageable {
// ��ҳ��С
private int pageSize;
// ����������
private int totalRows;
// ������ҳ��
private int totalPages;
// ��ǰҳ
private static int currentPage;
// ��ݿ��α�ָ�����
private int rowsCount;
// ���캯��
public Pageable(ResultSet rs) {
try {
// ����ݿ��α�ָ��������
rs.last();
} catch (SQLException e) {
e.printStackTrace();
}
try {
// �õ�����������
this.setTotalRows(rs.getRow());
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
// ����ݿ��α�ָ�������ǰ
rs.beforeFirst();
} catch (SQLException e2) {
e2.printStackTrace();
}
}
/**
* ���÷�ҳ��С
*/
public void setPageSize(int pageSize) {
if (pageSize > 0) {
this.pageSize = pageSize;
} else {
this.pageSize = 1;
}
this.setTotalPages();
}
/**
* ת��ָ��ҳ
*/
public void gotoPage(int page) {
switch (page) {
case -1:
this.setCurrentPage(1);
break;
case -2:
if (this.getCurrentPage() != 1) {
this.setCurrentPage(this.getCurrentPage() - 1);
} else {
this.setCurrentPage(1);
}
break;
case -3:
if (this.getCurrentPage() != this.getTotalPages()) {
this.setCurrentPage(this.getCurrentPage() + 1);
} else {
this.setCurrentPage(this.getTotalPages());
}
break;
case -4:
this.setCurrentPage(this.getTotalPages());
break;
default:
this.setCurrentPage(page);
}
}
/**
* ���õ�ǰҳ
*/
public void setCurrentPage(int page) {
// ���ҳ��Ϊ0���߸���ʱ,��ǰҳΪ��1ҳ
if (page <= 0)
Pageable.currentPage = 1;
// ���ҳ�Ŵ���ʵ����ҳ��ʱ,��ǰҳΪ��ҳ��
if (page > this.getTotalPages())
Pageable.currentPage = this.getTotalPages();
// �����������,��ǰҳ��Ϊ���ҳ��
else
Pageable.currentPage = page;
// ������ݿ��α�ָ��λ��
this.setRowsCount((Pageable.currentPage - 1) * this.getPageSize() + 1);
}
/**
* ���ص�ǰҳ�ļ�¼����
*/
public int getCurrentPageRowsCount() {
if (this.getPageSize() == 0)
return this.getTotalRows();
if (this.getTotalRows() == 0)
return 0;
if (this.getCurrentPage() != this.getTotalPages())
return this.getPageSize();
return this.getTotalRows() - (this.getTotalPages() - 1)
* this.getPageSize();
}
/**
* ���ط�ҳ��С
*/
public int getPageSize() {
return this.pageSize;
}
/**
* �����ܼ�¼����
*/
public int getTotalRows() {
return totalRows;
}
/**
* �����ܼ�¼����
*/
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
/**
* �����α�ָ���е�λ��
*/
public int getRowsCount() {
return rowsCount;
}
/**
* �����α�ָ���е�λ��
*/
public void setRowsCount(int rowsCount) {
this.rowsCount = rowsCount;
}
/**
* ���ص�ǰҳ��
*/
public int getCurrentPage() {
return currentPage;
}
/**
* ������ҳ��
*/
public int getTotalPages() {
return this.totalPages;
}
/**
* ������ҳ��
*/
public void setTotalPages() {
if (this.getTotalRows() == 0) {
this.totalPages = 0;
} else if (this.getPageSize() == 0) {
this.totalPages = 1;
} else {
if (this.getTotalRows() % this.getPageSize() != 0)
this.totalPages = this.getTotalRows() / this.getPageSize() + 1;
else
this.totalPages = this.getTotalRows() / this.getPageSize();
}
}
/**
* ת����ǰҳ�ĵ�һ���¼
*/
public void pageFirst() throws java.sql.SQLException {
this.setRowsCount((this.getCurrentPage() - 1) * this.getPageSize() + 1);
}
/**
* ת����ǰҳ�����һ���¼
*/
public void pageLast() throws java.sql.SQLException {
this.setRowsCount((this.getCurrentPage() - 1) * this.getPageSize()
+ this.getCurrentPageRowsCount());
}
// /**
// * �������һ��
// * @return
// * @throws SQLException
// */
// public boolean next() throws SQLException {
// return rs.next();
// }
// ����
// public String getString(String columnName) throws SQLException {
// try {
// return rs.getString(columnName);
// } catch (SQLException e) {//������Ϊ�����һЩ�����Ϣ�����ݱ��ڵ���
// throw new SQLException(e.toString() + " columnName=" + columnName
// + " SQL=");
// }
// }
// ֻ����Pageable�ӿ�������ķ�������Ҫ�Լ���д�������?
/**
* ����ע�Ϳɲο�Pageable.java
*/
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
公告管理系统 (104个子文件)
User.class 5KB
Notice.class 5KB
CheckPowerAction.class 4KB
UserEditAction.class 4KB
NewUserAction.class 3KB
DisplayTag.class 3KB
DBUtil.class 3KB
AdminLoginAction.class 3KB
UserLoginAction.class 3KB
UserSearchAction.class 3KB
Pageable.class 3KB
NoticeModifyAction.class 2KB
NewNoticeAction.class 2KB
DB.class 2KB
UserInfoForm.class 2KB
NewNoticeForm.class 2KB
NoticeModifyForm.class 2KB
HelloTag.class 1KB
AdminLogoffAction.class 1KB
UserLogoffAction.class 1KB
AdminLoginForm.class 856B
UserLoginForm.class 851B
Constants.class 484B
.classpath 1KB
myStyleClass.css 35B
Entries 227B
Entries 142B
Entries 141B
Entries 47B
user.frm 9KB
notice.frm 8KB
logo2.gif 38KB
logo3.gif 36KB
logo.gif 36KB
struts.jar 531KB
mysql-connector-java-3.1.12-bin.jar 436KB
antlr.jar 350KB
commons-beanutils.jar 184KB
commons-digester.jar 164KB
commons-validator.jar 82KB
jakarta-oro.jar 64KB
commons-logging.jar 37KB
commons-fileupload.jar 22KB
Pageable.java 5KB
User.java 4KB
CheckPowerAction.java 4KB
Notice.java 4KB
DBUtil.java 3KB
DisplayTag.java 3KB
UserEditAction.java 2KB
NewUserAction.java 2KB
AdminLoginAction.java 2KB
UserLoginAction.java 2KB
UserSearchAction.java 2KB
NoticeModifyAction.java 2KB
NewNoticeAction.java 1KB
NewNoticeForm.java 1KB
NoticeModifyForm.java 1KB
DB.java 1KB
UserInfoForm.java 1KB
HelloTag.java 1KB
AdminLogoffAction.java 666B
UserLogoffAction.java 663B
AdminLoginForm.java 611B
UserLoginForm.java 608B
Constants.java 313B
newnotice.jsp 2KB
useredit.jsp 2KB
userlist.jsp 2KB
newuser.jsp 2KB
noticemodify.jsp 2KB
adminlogin.jsp 1KB
userlogin.jsp 1KB
noticelist.jsp 526B
messagepage.jsp 494B
taglibs.jsp 319B
footer.jsp 255B
header2.jsp 242B
header3.jsp 242B
header.jsp 241B
.struts-config.mex 10KB
MANIFEST.MF 39B
.mymetadata 291B
.mystrutsdata 342B
db.opt 65B
.project 1KB
ApplicationResources_zh.properties 4KB
ApplicationResources_zh.properties 4KB
Repository 19B
Repository 19B
Repository 18B
Repository 17B
Root 38B
Root 38B
Root 38B
Root 38B
struts-html.tld 72KB
struts-nested.tld 70KB
struts-logic.tld 14KB
struts-bean.tld 9KB
共 104 条
- 1
- 2
资源评论
zizi2008han
- 粉丝: 1
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功