1
1
package com .codingapi .springboot .framework .dto .request ;
2
2
3
+ import jakarta .servlet .http .HttpServletRequest ;
3
4
import lombok .Getter ;
4
5
import org .springframework .beans .BeanUtils ;
5
6
import org .springframework .data .domain .Example ;
6
7
import org .springframework .data .domain .Pageable ;
7
8
import org .springframework .data .domain .Sort ;
9
+ import org .springframework .web .context .request .RequestContextHolder ;
10
+ import org .springframework .web .context .request .ServletRequestAttributes ;
8
11
9
12
import java .beans .PropertyDescriptor ;
10
13
import java .util .HashMap ;
@@ -16,15 +19,22 @@ public class PageRequest extends org.springframework.data.domain.PageRequest {
16
19
@ Getter
17
20
private int current ;
18
21
private int pageSize ;
22
+
19
23
private final Map <String ,Object > filters = new HashMap <>();
20
24
25
+ @ Getter
26
+ private final HttpServletRequest servletRequest ;
27
+
21
28
private org .springframework .data .domain .PageRequest pageRequest ;
22
29
23
30
public PageRequest (int current , int pageSize , Sort sort ) {
24
31
super (current > 0 ? current -- : 0 , pageSize , sort );
25
32
this .current = current ;
26
33
this .pageSize = pageSize ;
27
34
this .pageRequest = PageRequest .of (current , pageSize , sort );
35
+
36
+ ServletRequestAttributes attributes = (ServletRequestAttributes ) RequestContextHolder .currentRequestAttributes ();
37
+ this .servletRequest = attributes .getRequest ();
28
38
}
29
39
30
40
public PageRequest () {
@@ -35,6 +45,15 @@ public void setCurrent(int current) {
35
45
this .current = current > 0 ? current - 1 : 0 ;
36
46
}
37
47
48
+ public String getParameter (String key ){
49
+ return servletRequest .getParameter (key );
50
+ }
51
+
52
+ public String getParameter (String key ,String defaultValue ){
53
+ String result = servletRequest .getParameter (key );
54
+ return result == null ? defaultValue : result ;
55
+ }
56
+
38
57
@ Override
39
58
public int getPageSize () {
40
59
return pageSize ;
0 commit comments