提交 c85d768b 编写于 作者: R Rossen Stoyanchev

WebExchangeDataBinder uses the new "requestParams"

上级 7d9e8def
...@@ -64,18 +64,13 @@ public class WebExchangeDataBinder extends WebDataBinder { ...@@ -64,18 +64,13 @@ public class WebExchangeDataBinder extends WebDataBinder {
/** /**
* Bind the URL query parameters or form data of the body of the given request * Bind the URL query parameters or form data of the body of the given request
* to this binder's target. The request body is parsed if the content-type * to this binder's target. The request body is parsed if the Content-Type
* is "application/x-www-form-urlencoded". * is {@code "application/x-www-form-urlencoded"}.
* @param exchange the current exchange. * @param exchange the current exchange.
* @return a {@code Mono<Void>} to indicate the result * @return a {@code Mono<Void>} when binding is complete
*/ */
public Mono<Void> bind(ServerWebExchange exchange) { public Mono<Void> bind(ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest(); return exchange.getRequestParams()
Mono<MultiValueMap<String, String>> queryParams = Mono.just(request.getQueryParams());
Mono<MultiValueMap<String, String>> formParams =
exchange.getFormData().defaultIfEmpty(new LinkedMultiValueMap<>());
return Mono.zip(this::mergeParams, queryParams, formParams)
.map(this::getParamsToBind) .map(this::getParamsToBind)
.doOnNext(values -> values.putAll(getMultipartFiles(exchange))) .doOnNext(values -> values.putAll(getMultipartFiles(exchange)))
.doOnNext(values -> values.putAll(getExtraValuesToBind(exchange))) .doOnNext(values -> values.putAll(getExtraValuesToBind(exchange)))
...@@ -85,15 +80,8 @@ public class WebExchangeDataBinder extends WebDataBinder { ...@@ -85,15 +80,8 @@ public class WebExchangeDataBinder extends WebDataBinder {
}); });
} }
@SuppressWarnings("unchecked")
private MultiValueMap<String, String> mergeParams(Object[] paramMaps) {
MultiValueMap<String, String> result = new LinkedMultiValueMap<>();
Arrays.stream(paramMaps).forEach(map -> result.putAll((MultiValueMap<String, String>) map));
return result;
}
private Map<String, Object> getParamsToBind(MultiValueMap<String, String> params) { private Map<String, Object> getParamsToBind(MultiValueMap<String, String> params) {
Map<String, Object> valuesToBind = new TreeMap<>(); Map<String, Object> result = new TreeMap<>();
for (Map.Entry<String, List<String>> entry : params.entrySet()) { for (Map.Entry<String, List<String>> entry : params.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
List<String> values = entry.getValue(); List<String> values = entry.getValue();
...@@ -102,14 +90,14 @@ public class WebExchangeDataBinder extends WebDataBinder { ...@@ -102,14 +90,14 @@ public class WebExchangeDataBinder extends WebDataBinder {
} }
else { else {
if (values.size() > 1) { if (values.size() > 1) {
valuesToBind.put(name, values); result.put(name, values);
} }
else { else {
valuesToBind.put(name, values.get(0)); result.put(name, values.get(0));
} }
} }
} }
return valuesToBind; return result;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册