forked from Jaehyunleejava/BoardSpringMVC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageMaker.java
More file actions
144 lines (85 loc) · 2.77 KB
/
PageMaker.java
File metadata and controls
144 lines (85 loc) · 2.77 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.jh.vo;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
public class PageMaker {
private int totalCount; //총 데이터 개수
private int startPage; // 누르는 보여지는 시작페이지
private int endPage; // 누르는 보여지는 마지막페이지
private boolean prev; // 이전페이지 링크
private boolean next; // 이후페이지 링크
private int displayPageNum = 10; //보여지는 페이지 수
private Criteria cri;
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
calcData();
}
public int getStartPage() {
return startPage;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public int getEndPage() {
return endPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public boolean isPrev() {
return prev;
}
public void setPrev(boolean prev) {
this.prev = prev;
}
public boolean isNext() {
return next;
}
public void setNext(boolean next) {
this.next = next;
}
public int getDisplayPageNum() {
return displayPageNum;
}
public void setDisplayPageNum(int displayPageNum) {
this.displayPageNum = displayPageNum;
}
public Criteria getCri() {
return cri;
}
public void setCri(Criteria cri) {
this.cri = cri;
}
private void calcData() {
//예를들어, 현재페이지가 3페이지이고 displayPageNum 10개를 보여줄수 있다.
//endPage는 ceil(3/10) * 10 = 10이다.
endPage = (int)(Math.ceil(cri.getPage() / (double) displayPageNum)* displayPageNum);
startPage = (endPage - displayPageNum) +1;
//총 마지막 보여지는 페이지 버튼링크
int tempEndPage = (int) (Math.ceil(totalCount / (double) cri.getPerPageNum())); //여기서 perPageNum은 10이다.
if(endPage > tempEndPage) {
endPage = tempEndPage;
}
prev = startPage == 1 ? false : true;
//9(현재페이지) * 10(보여지는 페이지) >= 122(총 데이터 개수) 이면 다음링크 없음.
next = endPage * cri.getPerPageNum() >= totalCount ? false : true;
}
public String makeQuery(int page) {
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.queryParam("page",page)
.queryParam("perPageNum", cri.getPerPageNum())
.build();
return uriComponents.toUriString();
}
public String makeSearch(int page) {
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.queryParam("page",page)
.queryParam("perPageNum", cri.getPerPageNum())
.queryParam("searchType", ((SearchCriteria)cri).getSearchType())
.queryParam("keyword", ((SearchCriteria)cri).getKeyword())
.build();
return uriComponents.toUriString();
}
}