Skip to content

Commit c85d768

Browse files
committed
WebExchangeDataBinder uses the new "requestParams"
1 parent 7d9e8de commit c85d768

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@ public WebExchangeDataBinder(Object target, String objectName) {
6464

6565
/**
6666
* Bind the URL query parameters or form data of the body of the given request
67-
* to this binder's target. The request body is parsed if the content-type
68-
* is "application/x-www-form-urlencoded".
67+
* to this binder's target. The request body is parsed if the Content-Type
68+
* is {@code "application/x-www-form-urlencoded"}.
6969
* @param exchange the current exchange.
70-
* @return a {@code Mono<Void>} to indicate the result
70+
* @return a {@code Mono<Void>} when binding is complete
7171
*/
7272
public Mono<Void> bind(ServerWebExchange exchange) {
73-
ServerHttpRequest request = exchange.getRequest();
74-
Mono<MultiValueMap<String, String>> queryParams = Mono.just(request.getQueryParams());
75-
Mono<MultiValueMap<String, String>> formParams =
76-
exchange.getFormData().defaultIfEmpty(new LinkedMultiValueMap<>());
77-
78-
return Mono.zip(this::mergeParams, queryParams, formParams)
73+
return exchange.getRequestParams()
7974
.map(this::getParamsToBind)
8075
.doOnNext(values -> values.putAll(getMultipartFiles(exchange)))
8176
.doOnNext(values -> values.putAll(getExtraValuesToBind(exchange)))
@@ -85,15 +80,8 @@ public Mono<Void> bind(ServerWebExchange exchange) {
8580
});
8681
}
8782

88-
@SuppressWarnings("unchecked")
89-
private MultiValueMap<String, String> mergeParams(Object[] paramMaps) {
90-
MultiValueMap<String, String> result = new LinkedMultiValueMap<>();
91-
Arrays.stream(paramMaps).forEach(map -> result.putAll((MultiValueMap<String, String>) map));
92-
return result;
93-
}
94-
9583
private Map<String, Object> getParamsToBind(MultiValueMap<String, String> params) {
96-
Map<String, Object> valuesToBind = new TreeMap<>();
84+
Map<String, Object> result = new TreeMap<>();
9785
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
9886
String name = entry.getKey();
9987
List<String> values = entry.getValue();
@@ -102,14 +90,14 @@ private Map<String, Object> getParamsToBind(MultiValueMap<String, String> params
10290
}
10391
else {
10492
if (values.size() > 1) {
105-
valuesToBind.put(name, values);
93+
result.put(name, values);
10694
}
10795
else {
108-
valuesToBind.put(name, values.get(0));
96+
result.put(name, values.get(0));
10997
}
11098
}
11199
}
112-
return valuesToBind;
100+
return result;
113101
}
114102

115103
/**

0 commit comments

Comments
 (0)