public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodProcessor
ModelAttributeMethodProcessor
that applies data
binding through a WebDataBinder of type ServletRequestDataBinder
.
Also adds a fall-back strategy to instantiate the model attribute from a URI template variable or from a request parameter if the name matches the model attribute name and there is an appropriate type conversion strategy.
logger
Constructor and Description |
---|
ServletModelAttributeMethodProcessor(boolean annotationNotRequired)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
bindRequestParameters(WebDataBinder binder,
NativeWebRequest request)
This implementation downcasts
WebDataBinder to
ServletRequestDataBinder before binding. |
protected Object |
createAttribute(String attributeName,
MethodParameter parameter,
WebDataBinderFactory binderFactory,
NativeWebRequest request)
Instantiate the model attribute from a URI template variable or from a
request parameter if the name matches to the model attribute name and
if there is an appropriate type conversion strategy.
|
protected Object |
createAttributeFromRequestValue(String sourceValue,
String attributeName,
MethodParameter parameter,
WebDataBinderFactory binderFactory,
NativeWebRequest request)
Create a model attribute from a String request value (e.g.
|
protected String |
getRequestValueForAttribute(String attributeName,
NativeWebRequest request)
Obtain a value from the request that may be used to instantiate the
model attribute through type conversion from String to the target type.
|
protected Map<String,String> |
getUriTemplateVariables(NativeWebRequest request) |
constructAttribute, constructAttribute, handleReturnValue, isBindExceptionRequired, isBindExceptionRequired, resolveArgument, supportsParameter, supportsReturnType, validateIfApplicable, validateValueIfApplicable
public ServletModelAttributeMethodProcessor(boolean annotationNotRequired)
annotationNotRequired
- if "true", non-simple method arguments and
return values are considered model attributes with or without a
@ModelAttribute
annotationprotected final Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception
createAttribute
in class ModelAttributeMethodProcessor
attributeName
- the name of the attribute (never null
)parameter
- the method parameter declarationbinderFactory
- for creating WebDataBinder instancerequest
- the current requestnull
)BindException
- in case of constructor argument binding failureException
- in case of constructor invocation failurecreateAttributeFromRequestValue(java.lang.String, java.lang.String, org.springframework.core.MethodParameter, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest)
@Nullable protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request)
The default implementation looks for the attribute name to match a URI variable first and then a request parameter.
attributeName
- the model attribute namerequest
- the current requestnull
if noneprotected final Map<String,String> getUriTemplateVariables(NativeWebRequest request)
@Nullable protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception
The default implementation converts only if there a registered
Converter
that can perform the conversion.
sourceValue
- the source value to create the model attribute fromattributeName
- the name of the attribute (never null
)parameter
- the method parameterbinderFactory
- for creating WebDataBinder instancerequest
- the current requestnull
if no suitable
conversion foundException
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request)
WebDataBinder
to
ServletRequestDataBinder
before binding.bindRequestParameters
in class ModelAttributeMethodProcessor
binder
- the data binder instance to use for the bindingrequest
- the current requestServletRequestDataBinderFactory