File tree Expand file tree Collapse file tree
springboot-starter/src/main/java/com/codingapi/springboot/framework Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .dto .offset ;
2+
3+ public interface ICurrentOffset {
4+
5+ void setCurrent (int current );
6+
7+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .dto .offset ;
2+
3+ public interface ICurrentPageOffset {
4+
5+ int getCurrentPage (ICurrentOffset target , int current );
6+
7+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11package 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 ;
45import lombok .Getter ;
56import lombok .Setter ;
67import 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 ) {
Original file line number Diff line number Diff line change 33import com .alibaba .fastjson .JSON ;
44import com .alibaba .fastjson .JSONArray ;
55import 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 ;
78import jakarta .servlet .http .HttpServletRequest ;
89import lombok .Getter ;
910import lombok .Setter ;
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
You can’t perform that action at this time.
0 commit comments