Improve ExtendedWebExchangeDataBinder implementation
Close gh-28646
This commit is contained in:
@@ -84,8 +84,8 @@ public class WebExchangeDataBinder extends WebDataBinder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method to obtain the values for data binding. By default this
|
||||
* method delegates to {@link #extractValuesToBind(ServerWebExchange)}.
|
||||
* Obtain the values for data binding. By default, this delegates to
|
||||
* {@link #extractValuesToBind(ServerWebExchange)}.
|
||||
* @param exchange the current exchange
|
||||
* @return a map of bind values
|
||||
* @since 5.3
|
||||
|
||||
@@ -18,14 +18,11 @@ package org.springframework.web.reactive;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.validation.support.BindingAwareConcurrentModel;
|
||||
import org.springframework.web.bind.support.WebBindingInitializer;
|
||||
import org.springframework.web.bind.support.WebExchangeDataBinder;
|
||||
@@ -127,21 +124,9 @@ public class BindingContext {
|
||||
|
||||
@Override
|
||||
public Mono<Map<String, Object>> getValuesToBind(ServerWebExchange exchange) {
|
||||
Map<String, String> vars = exchange.getAttributeOrDefault(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap());
|
||||
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
|
||||
Mono<MultiValueMap<String, String>> formData = exchange.getFormData();
|
||||
Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData();
|
||||
|
||||
return Mono.zip(Mono.just(vars), Mono.just(queryParams), formData, multipartData)
|
||||
.map(tuple -> {
|
||||
Map<String, Object> result = new TreeMap<>();
|
||||
result.putAll(tuple.getT1());
|
||||
tuple.getT2().forEach((key, values) -> addBindValue(result, key, values));
|
||||
tuple.getT3().forEach((key, values) -> addBindValue(result, key, values));
|
||||
tuple.getT4().forEach((key, values) -> addBindValue(result, key, values));
|
||||
return result;
|
||||
});
|
||||
return super.getValuesToBind(exchange).doOnNext(map ->
|
||||
map.putAll(exchange.<Map<String, String>>getAttributeOrDefault(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user