-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPage.java
More file actions
61 lines (54 loc) · 1.22 KB
/
Page.java
File metadata and controls
61 lines (54 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.ddbs.util;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Page {
private int pageSize;//每页显示的记录数
private int pageCount;//总页数
private int curPage;//当前页
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
//计算总页数
public void setPageCount(ResultSet rs) {
try {
rs.last();//将游标移动到最后一行
int lastrow=rs.getRow();//显示当前行号:从一开始
if(lastrow%pageSize==0){
pageCount=lastrow/pageSize;
}else{
pageCount=lastrow/pageSize+1;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public int getPageCount() {
return pageCount;
}
//设置要显示的页
public void setCurPage(int row) {
if (row<=1)
curPage=1;
else if(row>=pageCount){
curPage=pageCount;
}else{
curPage=row;
}
}
public int getCurPage() {
return curPage;
}
//根据页数设置结果集
public ResultSet setResultset(ResultSet rs){
try {
//System.out.println("根据页数设置结果集:"+(curPage-1)*pageSize+1+"curPage,,pageSize::"+curPage+"--"+pageSize);
rs.absolute((curPage-1)*pageSize+1);//将游标移动到指定行
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
}