Skip to content

Commit 058ce36

Browse files
committed
Improve ExtendedWebExchangeDataBinder implementation
Close gh-28646
1 parent 2afe560 commit 058ce36

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public Mono<Void> bind(ServerWebExchange exchange) {
8484
}
8585

8686
/**
87-
* Protected method to obtain the values for data binding. By default this
88-
* method delegates to {@link #extractValuesToBind(ServerWebExchange)}.
87+
* Obtain the values for data binding. By default, this delegates to
88+
* {@link #extractValuesToBind(ServerWebExchange)}.
8989
* @param exchange the current exchange
9090
* @return a map of bind values
9191
* @since 5.3

spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818

1919
import java.util.Collections;
2020
import java.util.Map;
21-
import java.util.TreeMap;
2221

2322
import reactor.core.publisher.Mono;
2423

25-
import org.springframework.http.codec.multipart.Part;
2624
import org.springframework.lang.Nullable;
2725
import org.springframework.ui.Model;
28-
import org.springframework.util.MultiValueMap;
2926
import org.springframework.validation.support.BindingAwareConcurrentModel;
3027
import org.springframework.web.bind.support.WebBindingInitializer;
3128
import org.springframework.web.bind.support.WebExchangeDataBinder;
@@ -127,21 +124,9 @@ public ExtendedWebExchangeDataBinder(@Nullable Object target, String objectName)
127124

128125
@Override
129126
public Mono<Map<String, Object>> getValuesToBind(ServerWebExchange exchange) {
130-
Map<String, String> vars = exchange.getAttributeOrDefault(
131-
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap());
132-
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
133-
Mono<MultiValueMap<String, String>> formData = exchange.getFormData();
134-
Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData();
135-
136-
return Mono.zip(Mono.just(vars), Mono.just(queryParams), formData, multipartData)
137-
.map(tuple -> {
138-
Map<String, Object> result = new TreeMap<>();
139-
result.putAll(tuple.getT1());
140-
tuple.getT2().forEach((key, values) -> addBindValue(result, key, values));
141-
tuple.getT3().forEach((key, values) -> addBindValue(result, key, values));
142-
tuple.getT4().forEach((key, values) -> addBindValue(result, key, values));
143-
return result;
144-
});
127+
return super.getValuesToBind(exchange).doOnNext(map ->
128+
map.putAll(exchange.<Map<String, String>>getAttributeOrDefault(
129+
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap())));
145130
}
146131
}
147132

0 commit comments

Comments
 (0)