0%

java分页实现

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.tradingplatform.dto;

import java.util.List;

/**
* 分页原理页面传送数据的Dto
* @param <T>:传送的数据的类型
*/
public class PageJumpDataDto<T> {
private int currentPage=1; //当前页
private int totalPage=0; //总共页
private int totalRecord=0; //总记录数
private List<T> listData; //数据
private int pageSize=6; //每页记录数

public PageJumpDataDto() {}

public PageJumpDataDto(int currentPage, int totalPage, int totalRecord, List<T> listData, int pageSize) {
super();
this.currentPage = currentPage;
this.totalPage = totalPage;
this.totalRecord = totalRecord;
this.listData = listData;
this.pageSize = pageSize;
}

public PageJumpDataDto(int currentPage, List<T> listData) {
if(listData==null) return;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public PageJumpDataDto(int currentPage, List<T> listData,int pageSize) {
if(listData==null) return;
this.pageSize=pageSize;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}

public List<T> getListData() {
return listData;
}

public void setListData(List<T> listData) {
this.listData = listData;
}

public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

}