Skip to content

Commit 5c448ff

Browse files
committedApr 24, 2024
1 parent 5040bd6 commit 5c448ff

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed
 

Diff for: ‎pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.2.4</version>
9+
<version>3.2.5</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.2.0</version>
15+
<version>3.2.1</version>
1616

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

Diff for: ‎springboot-starter-data-fast/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.2.0</version>
8+
<version>3.2.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

Diff for: ‎springboot-starter-security/pom.xml

+1-1
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>3.2.0</version>
9+
<version>3.2.1</version>
1010
</parent>
1111

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

Diff for: ‎springboot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.2.0</version>
8+
<version>3.2.1</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

Diff for: ‎springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/SearchRequest.java

+57-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.alibaba.fastjson.JSONArray;
55
import com.alibaba.fastjson.JSONObject;
66
import jakarta.servlet.http.HttpServletRequest;
7+
import lombok.Getter;
8+
import lombok.Setter;
79
import org.springframework.data.domain.Sort;
810
import org.springframework.util.StringUtils;
911
import org.springframework.web.context.request.RequestContextHolder;
@@ -15,7 +17,7 @@
1517
import java.util.List;
1618

1719
/**
18-
* HttpServletRequest 请求参数解析成 PageRequest对象
20+
* HttpServletRequest 请求参数解析成 PageRequest对象
1921
*/
2022
public class SearchRequest {
2123

@@ -50,6 +52,15 @@ public void addSort(Sort sort) {
5052

5153
public void removeFilter(String key) {
5254
pageRequest.removeFilter(key);
55+
this.removeKeys.add(key);
56+
}
57+
58+
public String getParameter(String key) {
59+
return request.getParameter(key);
60+
}
61+
62+
public String[] getParameterValues(String key) {
63+
return request.getParameterValues(key);
5364
}
5465

5566
public PageRequest addFilter(String key, Relation relation, Object... value) {
@@ -69,7 +80,6 @@ public PageRequest orFilters(Filter... filters) {
6980
}
7081

7182

72-
7383
private String decode(String value) {
7484
return new String(Base64.getDecoder().decode(value));
7585
}
@@ -85,14 +95,20 @@ public ClassContent(Class<?> clazz, PageRequest pageRequest) {
8595
this.pageRequest = pageRequest;
8696
}
8797

98+
public void addFilter(String key, Relation relation, String value) {
99+
Class<?> keyClass = getKeyType(key);
100+
Object v = parseObject(value, keyClass);
101+
pageRequest.addFilter(key, relation, v);
102+
}
103+
88104
public void addFilter(String key, String value) {
89105
Class<?> keyClass = getKeyType(key);
90106
Object v = parseObject(value, keyClass);
91107
pageRequest.addFilter(key, Relation.EQUAL, v);
92108
}
93109

94110
private Object parseObject(String value, Class<?> keyClass) {
95-
if(value.getClass().equals(keyClass)) {
111+
if (value.getClass().equals(keyClass)) {
96112
return value;
97113
}
98114
return JSON.parseObject(value, keyClass);
@@ -124,12 +140,37 @@ private Class<?> getKeyType(String key) {
124140

125141
}
126142

143+
@Setter
144+
@Getter
145+
static class ParamOperation {
146+
private String key;
147+
private String type;
148+
149+
public Relation getOperation() {
150+
return Relation.valueOf(type);
151+
}
152+
}
153+
154+
private List<ParamOperation> loadParamOperations() {
155+
String params = request.getParameter("params");
156+
if (StringUtils.hasLength(params)) {
157+
params = decode(params);
158+
if (JSON.isValid(params)) {
159+
removeKeys.add("params");
160+
return JSON.parseArray(params, ParamOperation.class);
161+
}
162+
}
163+
return null;
164+
}
165+
127166
public PageRequest toPageRequest(Class<?> clazz) {
128167
pageRequest.setCurrent(current);
129168
pageRequest.setPageSize(pageSize);
130169

131170
ClassContent content = new ClassContent(clazz, pageRequest);
132171

172+
List<ParamOperation> loadParams = loadParamOperations();
173+
133174
String sort = request.getParameter("sort");
134175
if (StringUtils.hasLength(sort)) {
135176
sort = decode(sort);
@@ -169,7 +210,19 @@ public PageRequest toPageRequest(Class<?> clazz) {
169210
if (!removeKeys.contains(key)) {
170211
String value = request.getParameter(key);
171212
if (StringUtils.hasLength(value)) {
172-
content.addFilter(key, value);
213+
if (loadParams != null) {
214+
ParamOperation operation = loadParams.stream()
215+
.filter(paramOperation -> paramOperation.getKey().equals(key))
216+
.findFirst()
217+
.orElse(null);
218+
if (operation != null) {
219+
content.addFilter(key, operation.getOperation(), value);
220+
} else {
221+
content.addFilter(key, value);
222+
}
223+
} else {
224+
content.addFilter(key, value);
225+
}
173226
}
174227
}
175228
});

0 commit comments

Comments
 (0)