Skip to content

Commit 66cd979

Browse files
committed
Support @ModelAttribute(binding=false) with WebFlux
Prior to this commit, @ModelAttribute(binding=false) was honored with Spring Web MVC but not with WebFlux. This commit adds support for disabling binding via @ModelAttribute with WebFlux by adding a check to resolveArgument(...) in ModelAttributeMethodArgumentResolver. Closes gh-26856
1 parent 5667d45 commit 66cd979

File tree

2 files changed

+276
-134
lines changed

2 files changed

+276
-134
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
*
6161
* @author Rossen Stoyanchev
6262
* @author Juergen Hoeller
63+
* @author Sam Brannen
6364
* @since 5.0
6465
*/
6566
public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentResolverSupport {
@@ -117,7 +118,7 @@ public Mono<Object> resolveArgument(
117118

118119
return valueMono.flatMap(value -> {
119120
WebExchangeDataBinder binder = context.createDataBinder(exchange, value, name);
120-
return bindRequestParameters(binder, exchange)
121+
return (bindingDisabled(parameter) ? Mono.empty() : bindRequestParameters(binder, exchange))
121122
.doOnError(bindingResultSink::tryEmitError)
122123
.doOnSuccess(aVoid -> {
123124
validateIfApplicable(binder, parameter);
@@ -143,6 +144,16 @@ public Mono<Object> resolveArgument(
143144
});
144145
}
145146

147+
/**
148+
* Determine if binding should be disabled for the supplied {@link MethodParameter},
149+
* based on the {@link ModelAttribute#binding} annotation attribute.
150+
* @since 5.3.7
151+
*/
152+
private boolean bindingDisabled(MethodParameter parameter) {
153+
ModelAttribute modelAttribute = parameter.getParameterAnnotation(ModelAttribute.class);
154+
return (modelAttribute != null && !modelAttribute.binding());
155+
}
156+
146157
/**
147158
* Extension point to bind the request to the target object.
148159
* @param binder the data binder instance to use for the binding

0 commit comments

Comments
 (0)