Skip to content

Commit e00cd43

Browse files
committed
fix #177
1 parent 1e448e9 commit e00cd43

6 files changed

Lines changed: 54 additions & 25 deletions

File tree

springboot-starter/src/main/java/com/codingapi/springboot/framework/context/CurrentPageOffsetContext.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codingapi.springboot.framework.dto.offset;
2+
3+
public interface ICurrentOffset {
4+
5+
void setCurrent(int current);
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codingapi.springboot.framework.dto.offset;
2+
3+
public interface ICurrentPageOffset {
4+
5+
int getCurrentPage(ICurrentOffset target, int current);
6+
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.codingapi.springboot.framework.dto.offset.context;
2+
3+
4+
import com.codingapi.springboot.framework.dto.offset.ICurrentOffset;
5+
import com.codingapi.springboot.framework.dto.offset.ICurrentPageOffset;
6+
import com.codingapi.springboot.framework.dto.request.PageRequest;
7+
import lombok.Getter;
8+
import lombok.Setter;
9+
10+
public class CurrentPageOffsetContext implements ICurrentPageOffset {
11+
12+
@Getter
13+
private static final CurrentPageOffsetContext instance = new CurrentPageOffsetContext();
14+
15+
private CurrentPageOffsetContext(){}
16+
17+
@Setter
18+
private ICurrentPageOffset currentPageOffset = new ICurrentPageOffset(){
19+
@Override
20+
public int getCurrentPage(ICurrentOffset target, int current) {
21+
if(target instanceof PageRequest){
22+
return current;
23+
}
24+
return current - 1;
25+
}
26+
};
27+
28+
public int getCurrentPage(ICurrentOffset target, int current) {
29+
return currentPageOffset.getCurrentPage(target,current);
30+
}
31+
32+
}

springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/PageRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.codingapi.springboot.framework.dto.request;
22

3-
import com.codingapi.springboot.framework.context.CurrentPageOffsetContext;
3+
import com.codingapi.springboot.framework.dto.offset.ICurrentOffset;
4+
import com.codingapi.springboot.framework.dto.offset.context.CurrentPageOffsetContext;
45
import lombok.Getter;
56
import lombok.Setter;
67
import org.springframework.data.domain.Sort;
78

8-
public class PageRequest extends org.springframework.data.domain.PageRequest {
9+
public class PageRequest extends org.springframework.data.domain.PageRequest implements ICurrentOffset {
910

1011
@Getter
1112
private int current;
@@ -33,7 +34,7 @@ public PageRequest() {
3334
}
3435

3536
public void setCurrent(int current) {
36-
this.current = CurrentPageOffsetContext.getInstance().getCurrentPage(current);
37+
this.current = CurrentPageOffsetContext.getInstance().getCurrentPage(this,current);
3738
}
3839

3940
public String getStringFilter(String key) {

springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/SearchRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import com.alibaba.fastjson.JSON;
44
import com.alibaba.fastjson.JSONArray;
55
import com.alibaba.fastjson.JSONObject;
6-
import com.codingapi.springboot.framework.context.CurrentPageOffsetContext;
6+
import com.codingapi.springboot.framework.dto.offset.ICurrentOffset;
7+
import com.codingapi.springboot.framework.dto.offset.context.CurrentPageOffsetContext;
78
import jakarta.servlet.http.HttpServletRequest;
89
import lombok.Getter;
910
import lombok.Setter;
@@ -21,7 +22,7 @@
2122
/**
2223
* HttpServletRequest 请求参数解析成 PageRequest对象
2324
*/
24-
public class SearchRequest {
25+
public class SearchRequest implements ICurrentOffset {
2526

2627
@Getter
2728
private int current;
@@ -41,7 +42,7 @@ public SearchRequest() {
4142
}
4243

4344
public void setCurrent(int current) {
44-
this.current = CurrentPageOffsetContext.getInstance().getCurrentPage(current);
45+
this.current = CurrentPageOffsetContext.getInstance().getCurrentPage(this,current);
4546
this.removeKeys.add("current");
4647
}
4748

0 commit comments

Comments
 (0)