Skip to content

Commit 5261717

Browse files
committed
fix PageRequest bug
1 parent a6c49df commit 5261717

File tree

8 files changed

+180
-9
lines changed

8 files changed

+180
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.codingapi.springboot</groupId>
1313
<artifactId>springboot-parent</artifactId>
14-
<version>0.1.1</version>
14+
<version>0.1.2</version>
1515

1616
<url>https://github.com/codingapi/springboot-framewrok</url>
1717
<name>springboot-parent</name>

springboot-example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.codingapi.springboot</groupId>
66
<artifactId>springboot-parent</artifactId>
7-
<version>0.1.1</version>
7+
<version>0.1.2</version>
88
</parent>
99
<artifactId>springboot-example</artifactId>
1010

springboot-starter-data-permission/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>0.1.1</version>
9+
<version>0.1.2</version>
1010
</parent>
1111

1212

springboot-starter-security-jwt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>0.1.1</version>
9+
<version>0.1.2</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security-jwt</artifactId>

springboot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.codingapi.springboot</groupId>
66
<artifactId>springboot-parent</artifactId>
7-
<version>0.1.1</version>
7+
<version>0.1.2</version>
88
</parent>
99
<artifactId>springboot-starter</artifactId>
1010

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package com.codingapi.springboot.framework;
22

3+
import com.codingapi.springboot.framework.properties.BootProperties;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
import org.springframework.context.annotation.Bean;
36
import org.springframework.context.annotation.Configuration;
47

58
@Configuration
69
public class AutoConfiguration {
710

811

12+
@Bean
13+
@ConfigurationProperties(prefix = "codingapi.boot")
14+
public BootProperties bootProperties(){
15+
return new BootProperties();
16+
}
17+
918
}
Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,165 @@
11
package com.codingapi.springboot.framework.dto.request;
22

3-
import lombok.Getter;
4-
import lombok.Setter;
3+
import org.springframework.data.domain.Pageable;
54
import org.springframework.data.domain.Sort;
65

7-
@Setter
8-
@Getter
6+
import java.util.Optional;
7+
98
public class PageRequest extends org.springframework.data.domain.PageRequest {
109

1110
private int current;
1211
private int pageSize;
1312

13+
public final static String CURRENT_FIX_VALUE = "CURRENT_FIX_VALUE";
14+
15+
private org.springframework.data.domain.PageRequest pageRequest;
16+
1417
public PageRequest(int current, int pageSize, Sort sort) {
1518
super(current, pageSize, sort);
1619
this.current = current;
1720
this.pageSize = pageSize;
21+
pageRequest = PageRequest.of(current, pageSize, sort);
1822
}
1923

2024
public PageRequest() {
2125
this(0,20,Sort.unsorted());
2226
}
2327

28+
private void initPage(){
29+
int fixValue=0;
30+
try {
31+
fixValue = Integer.parseInt(System.getProperty(CURRENT_FIX_VALUE));
32+
}catch (Exception e){}
33+
pageRequest = PageRequest.of(current-fixValue, pageSize, pageRequest.getSort());
34+
}
35+
36+
public int getCurrent() {
37+
return current;
38+
}
39+
40+
public void setCurrent(int current) {
41+
this.current = current;
42+
this.initPage();
43+
}
44+
45+
@Override
46+
public int getPageSize() {
47+
return pageSize;
48+
}
49+
50+
public void setPageSize(int pageSize) {
51+
this.pageSize = pageSize;
52+
this.initPage();
53+
}
54+
55+
public static org.springframework.data.domain.PageRequest of(int page, int size) {
56+
return org.springframework.data.domain.PageRequest.of(page, size);
57+
}
58+
59+
public static org.springframework.data.domain.PageRequest of(int page, int size, Sort sort) {
60+
return org.springframework.data.domain.PageRequest.of(page, size, sort);
61+
}
62+
63+
public static org.springframework.data.domain.PageRequest of(int page, int size, Sort.Direction direction, String... properties) {
64+
return org.springframework.data.domain.PageRequest.of(page, size, direction, properties);
65+
}
66+
67+
public static org.springframework.data.domain.PageRequest ofSize(int pageSize) {
68+
return org.springframework.data.domain.PageRequest.ofSize(pageSize);
69+
}
70+
71+
@Override
72+
public Sort getSort() {
73+
return pageRequest.getSort();
74+
}
75+
76+
@Override
77+
public org.springframework.data.domain.PageRequest next() {
78+
return pageRequest.next();
79+
}
80+
81+
@Override
82+
public org.springframework.data.domain.PageRequest previous() {
83+
return pageRequest.previous();
84+
}
85+
86+
@Override
87+
public org.springframework.data.domain.PageRequest first() {
88+
return pageRequest.first();
89+
}
90+
91+
@Override
92+
public boolean equals(Object obj) {
93+
return pageRequest.equals(obj);
94+
}
95+
96+
@Override
97+
public org.springframework.data.domain.PageRequest withPage(int pageNumber) {
98+
return pageRequest.withPage(pageNumber);
99+
}
100+
101+
@Override
102+
public org.springframework.data.domain.PageRequest withSort(Sort.Direction direction, String... properties) {
103+
return pageRequest.withSort(direction, properties);
104+
}
105+
106+
@Override
107+
public org.springframework.data.domain.PageRequest withSort(Sort sort) {
108+
return pageRequest.withSort(sort);
109+
}
110+
111+
@Override
112+
public int hashCode() {
113+
return pageRequest.hashCode();
114+
}
115+
116+
@Override
117+
public String toString() {
118+
return pageRequest.toString();
119+
}
120+
121+
@Override
122+
public int getPageNumber() {
123+
return pageRequest.getPageNumber();
124+
}
125+
126+
@Override
127+
public long getOffset() {
128+
return pageRequest.getOffset();
129+
}
130+
131+
@Override
132+
public boolean hasPrevious() {
133+
return pageRequest.hasPrevious();
134+
}
135+
136+
@Override
137+
public Pageable previousOrFirst() {
138+
return pageRequest.previousOrFirst();
139+
}
140+
141+
public static Pageable unpaged() {
142+
return Pageable.unpaged();
143+
}
144+
145+
@Override
146+
public boolean isPaged() {
147+
return pageRequest.isPaged();
148+
}
149+
150+
@Override
151+
public boolean isUnpaged() {
152+
return pageRequest.isUnpaged();
153+
}
154+
155+
@Override
156+
public Sort getSortOr(Sort sort) {
157+
return pageRequest.getSortOr(sort);
158+
}
159+
160+
@Override
161+
public Optional<Pageable> toOptional() {
162+
return pageRequest.toOptional();
163+
}
24164
}
25165

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codingapi.springboot.framework.properties;
2+
3+
import com.codingapi.springboot.framework.dto.request.PageRequest;
4+
5+
public class BootProperties {
6+
7+
private int pageCurrentFixValue = 1;
8+
9+
10+
public int getPageCurrentFixValue() {
11+
return pageCurrentFixValue;
12+
}
13+
14+
public void setPageCurrentFixValue(int pageCurrentFixValue) {
15+
this.pageCurrentFixValue = pageCurrentFixValue;
16+
System.setProperty(PageRequest.CURRENT_FIX_VALUE,String.valueOf(pageCurrentFixValue));
17+
}
18+
19+
public BootProperties() {
20+
System.setProperty(PageRequest.CURRENT_FIX_VALUE,String.valueOf(pageCurrentFixValue));
21+
}
22+
}

0 commit comments

Comments
 (0)