📄 pageview.java
字号:
package common;
import java.sql.*;
/**
* Title: PageView
* Description: 分页
* Copyright: Copyright (c) 2002
* Company: nettech
* @author pwbell
* @version 1.0
*/
public final class PageView {
private ResultSet myResults;
private int currentPageNo; // 当前页码
private int pageSize; // 每页记录数
private int recordCount; // 总记录数
private int pageCount; // 总页码数
public PageView(ResultSet rs) {
myResults = rs;
currentPageNo = 1;
pageSize = 15;
// compute record count
if(myResults != null) {
try {
myResults.last();
recordCount = myResults.getRow();
} catch(SQLException ex) {
System.err.println("PageView.getRecordCount():" + ex.getMessage());
}
} else {
recordCount = 0;
}
}
/**
* 取得给定页码的纪录集
*/
public ResultSet getPage(int pageNo){
if(recordCount < 1)
return null;
this.setPageCount();
try {
if(pageNo > pageCount)
currentPageNo = pageCount; //输入页码数大于总页码数的处理
else if(pageNo < 1)
currentPageNo = 1;
else
currentPageNo = pageNo;
if (pageCount > 0) {
//将记录指针定位到待显示页的第一条记录上
myResults.absolute((currentPageNo - 1) * pageSize + 1);
}
} catch (SQLException ex) {
System.out.print("PageView.getPage():" + ex.getMessage());
}
return myResults;
}
public int getRecordCount() {
return this.recordCount;
}
/**
* 设定每页显示记录数目(默认为每页显示15条记录)
*/
public void setPageSize(int size) {
this.pageSize = size;
if(this.pageSize < 1)
this.pageSize = 15;
}
public int getPageSize() {
return this.pageSize;
}
public int getPageCount() {
return this.pageCount;
}
private void setPageCount() {
if((recordCount % pageSize) == 0) {
this.pageCount = recordCount / pageSize;
} else {
this.pageCount = recordCount / pageSize + 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -