类 ServletModelAttributeMethodProcessor
- java.lang.Object
- org.springframework.web.method.annotation.ModelAttributeMethodProcessor
- org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor
public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodProcessor
A Servlet-specificModelAttributeMethodProcessor
that applies data binding through a WebDataBinder of typeServletRequestDataBinder
.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.
- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.method.annotation.ModelAttributeMethodProcessor
logger
构造器概要
构造器 构造器 说明 ServletModelAttributeMethodProcessor(boolean annotationNotRequired)
Class constructor.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
bindRequestParameters(WebDataBinder binder, NativeWebRequest request)
This implementation downcastsWebDataBinder
toServletRequestDataBinder
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)
从类继承的方法 org.springframework.web.method.annotation.ModelAttributeMethodProcessor
handleReturnValue, isBindExceptionRequired, resolveArgument, supportsParameter, supportsReturnType, validateIfApplicable
构造器详细资料
ServletModelAttributeMethodProcessor
public ServletModelAttributeMethodProcessor(boolean annotationNotRequired)
Class constructor.- 参数:
annotationNotRequired
- if "true", non-simple method arguments and return values are considered model attributes with or without a@ModelAttribute
annotation
方法详细资料
createAttribute
protected final Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception
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. If none of these are true delegate back to the base class.- 覆盖:
createAttribute
在类中ModelAttributeMethodProcessor
- 参数:
attributeName
- the name of the attribute (nevernull
)parameter
- the method parameterbinderFactory
- for creating WebDataBinder instancerequest
- the current request- 返回:
- the created model attribute (never
null
) - 抛出:
Exception
- 另请参阅:
createAttributeFromRequestValue(java.lang.String, java.lang.String, org.springframework.core.MethodParameter, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest)
getRequestValueForAttribute
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.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 request- 返回:
- the request value to try to convert, or
null
if none
getUriTemplateVariables
protected final Map<String,String> getUriTemplateVariables(NativeWebRequest request)
createAttributeFromRequestValue
protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception
Create a model attribute from a String request value (e.g. URI template variable, request parameter) using type conversion.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 (nevernull
)parameter
- the method parameterbinderFactory
- for creating WebDataBinder instancerequest
- the current request- 返回:
- the created model attribute, or
null
if no suitable conversion found - 抛出:
Exception
bindRequestParameters
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request)
This implementation downcastsWebDataBinder
toServletRequestDataBinder
before binding.- 覆盖:
bindRequestParameters
在类中ModelAttributeMethodProcessor
- 参数:
binder
- the data binder instance to use for the bindingrequest
- the current request- 另请参阅:
ServletRequestDataBinderFactory