Skip to content

Commit 62f24ee

Browse files
committed
add PageRequest servletRequest
1 parent bcec7c6 commit 62f24ee

File tree

1 file changed

+19
-0
lines changed
  • springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.codingapi.springboot.framework.dto.request;
22

3+
import jakarta.servlet.http.HttpServletRequest;
34
import lombok.Getter;
45
import org.springframework.beans.BeanUtils;
56
import org.springframework.data.domain.Example;
67
import org.springframework.data.domain.Pageable;
78
import org.springframework.data.domain.Sort;
9+
import org.springframework.web.context.request.RequestContextHolder;
10+
import org.springframework.web.context.request.ServletRequestAttributes;
811

912
import java.beans.PropertyDescriptor;
1013
import java.util.HashMap;
@@ -16,15 +19,22 @@ public class PageRequest extends org.springframework.data.domain.PageRequest {
1619
@Getter
1720
private int current;
1821
private int pageSize;
22+
1923
private final Map<String,Object> filters = new HashMap<>();
2024

25+
@Getter
26+
private final HttpServletRequest servletRequest;
27+
2128
private org.springframework.data.domain.PageRequest pageRequest;
2229

2330
public PageRequest(int current, int pageSize, Sort sort) {
2431
super(current > 0 ? current-- : 0, pageSize, sort);
2532
this.current = current;
2633
this.pageSize = pageSize;
2734
this.pageRequest = PageRequest.of(current, pageSize, sort);
35+
36+
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
37+
this.servletRequest = attributes.getRequest();
2838
}
2939

3040
public PageRequest() {
@@ -35,6 +45,15 @@ public void setCurrent(int current) {
3545
this.current = current > 0 ? current - 1 : 0;
3646
}
3747

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+
3857
@Override
3958
public int getPageSize() {
4059
return pageSize;

0 commit comments

Comments
 (0)