public class ModelAttributeMethodArgumentResolver extends java.lang.Object implements HandlerMethodArgumentResolver
@ModelAttribute
annotated method arguments.
Model attributes are sourced from the model, or created using a default
constructor and then added to the model. Once created the attribute is
populated via data binding to the request (form data, query params).
Validation also may be applied if the argument is annotated with
@javax.validation.Valid
or Spring's own
@org.springframework.validation.annotation.Validated
.
When this handler is created with useDefaultResolution=true
any non-simple type argument and return value is regarded as a model
attribute with or without the presence of an @ModelAttribute
.
Modifier and Type | Field and Description |
---|---|
private ReactiveAdapterRegistry |
adapterRegistry |
private boolean |
useDefaultResolution |
Constructor and Description |
---|
ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry registry)
Class constructor.
|
ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry registry,
boolean useDefaultResolution)
Class constructor with a default resolution mode flag.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkErrorsArgument(MethodParameter methodParam) |
protected java.lang.Object |
createAttribute(java.lang.String attributeName,
java.lang.Class<?> attributeType,
MethodParameter parameter,
BindingContext context,
ServerWebExchange exchange) |
ReactiveAdapterRegistry |
getAdapterRegistry()
Return the configured
ReactiveAdapterRegistry . |
private <any> |
getAttributeMono(java.lang.String attributeName,
java.lang.Class<?> attributeType,
MethodParameter param,
BindingContext context,
ServerWebExchange exchange) |
private java.lang.String |
getAttributeName(java.lang.Class<?> valueType,
MethodParameter parameter) |
<any> |
resolveArgument(MethodParameter parameter,
BindingContext context,
ServerWebExchange exchange)
The returned
Mono may produce one or zero values if the argument
does not resolve to any value, which will result in null passed
as the argument value. |
boolean |
supportsParameter(MethodParameter parameter) |
protected void |
validateIfApplicable(WebExchangeDataBinder binder,
MethodParameter parameter) |
private final ReactiveAdapterRegistry adapterRegistry
private final boolean useDefaultResolution
public ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry registry)
registry
- for adapting to other reactive types from and to Monopublic ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry registry, boolean useDefaultResolution)
registry
- for adapting to other reactive types from and to MonouseDefaultResolution
- if "true", non-simple method arguments and
return values are considered model attributes with or without a
@ModelAttribute
annotation present.public ReactiveAdapterRegistry getAdapterRegistry()
ReactiveAdapterRegistry
.public boolean supportsParameter(MethodParameter parameter)
supportsParameter
in interface HandlerMethodArgumentResolver
public <any> resolveArgument(MethodParameter parameter, BindingContext context, ServerWebExchange exchange)
HandlerMethodArgumentResolver
Mono
may produce one or zero values if the argument
does not resolve to any value, which will result in null
passed
as the argument value.resolveArgument
in interface HandlerMethodArgumentResolver
parameter
- the method parametercontext
- the binding context to useexchange
- the current exchangeprivate java.lang.String getAttributeName(java.lang.Class<?> valueType, MethodParameter parameter)
private <any> getAttributeMono(java.lang.String attributeName, java.lang.Class<?> attributeType, MethodParameter param, BindingContext context, ServerWebExchange exchange)
protected java.lang.Object createAttribute(java.lang.String attributeName, java.lang.Class<?> attributeType, MethodParameter parameter, BindingContext context, ServerWebExchange exchange)
protected boolean checkErrorsArgument(MethodParameter methodParam)
protected void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter)