类 AbstractNamedValueMethodArgumentResolver
- java.lang.Object
- org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver
- 所有已实现的接口:
HandlerMethodArgumentResolver
- 直接已知子类:
AbstractCookieValueMethodArgumentResolver
,ExpressionValueMethodArgumentResolver
,MatrixVariableMethodArgumentResolver
,PathVariableMethodArgumentResolver
,RequestAttributeMethodArgumentResolver
,RequestHeaderMethodArgumentResolver
,RequestParamMethodArgumentResolver
,SessionAttributeMethodArgumentResolver
public abstract class AbstractNamedValueMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and path variables are examples of named values. Each may have a name, a required flag, and a default value.Subclasses define how to do the following:
- Obtain named value information for a method parameter
- Resolve names into argument values
- Handle missing argument values when argument values are required
- Optionally handle a resolved value
A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions. For this to work a
ConfigurableBeanFactory
must be supplied to the class constructor.A
WebDataBinder
is created to apply type conversion to the resolved argument value if it doesn't match the method parameter type.- 从以下版本开始:
- 3.1
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static class
AbstractNamedValueMethodArgumentResolver.NamedValueInfo
Represents the information about a named value, including name, whether it's required and a default value.
构造器概要
构造器 构造器 说明 AbstractNamedValueMethodArgumentResolver()
AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory)
Create a newAbstractNamedValueMethodArgumentResolver
instance.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo
createNamedValueInfo(MethodParameter parameter)
Create theAbstractNamedValueMethodArgumentResolver.NamedValueInfo
object for the given method parameter.protected void
handleMissingValue(String name, MethodParameter parameter)
Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)
returnednull
and there is no default value.protected void
handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)
returnednull
and there is no default value.protected void
handleResolvedValue(Object arg, String name, MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
Invoked after a value is resolved.Object
resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
Resolves a method parameter into an argument value from a given request.protected abstract Object
resolveName(String name, MethodParameter parameter, NativeWebRequest request)
Resolve the given parameter type and value name into an argument value.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.web.method.support.HandlerMethodArgumentResolver
supportsParameter
构造器详细资料
AbstractNamedValueMethodArgumentResolver
public AbstractNamedValueMethodArgumentResolver()
AbstractNamedValueMethodArgumentResolver
public AbstractNamedValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory)
Create a newAbstractNamedValueMethodArgumentResolver
instance.- 参数:
beanFactory
- a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions in default values, ornull
if default values are not expected to contain expressions
方法详细资料
resolveArgument
@Nullable public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception
从接口复制的说明:HandlerMethodArgumentResolver
Resolves a method parameter into an argument value from a given request. AModelAndViewContainer
provides access to the model for the request. AWebDataBinderFactory
provides a way to create aWebDataBinder
instance when needed for data binding and type conversion purposes.- 指定者:
resolveArgument
在接口中HandlerMethodArgumentResolver
- 参数:
parameter
- the method parameter to resolve. This parameter must have previously been passed toHandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returnedtrue
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestbinderFactory
- a factory for creatingWebDataBinder
instances- 返回:
- the resolved argument value, or
null
if not resolvable - 抛出:
Exception
- in case of errors with the preparation of argument values
createNamedValueInfo
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)
Create theAbstractNamedValueMethodArgumentResolver.NamedValueInfo
object for the given method parameter. Implementations typically retrieve the method annotation by means ofMethodParameter.getParameterAnnotation(Class)
.- 参数:
parameter
- the method parameter- 返回:
- the named value information
resolveName
@Nullable protected abstract Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception
Resolve the given parameter type and value name into an argument value.
handleMissingValue
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception
Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)
returnednull
and there is no default value. Subclasses typically throw an exception in this case.- 参数:
name
- the name for the valueparameter
- the method parameterrequest
- the current request- 抛出:
Exception
- 从以下版本开始:
- 4.3
handleMissingValue
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletException
Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)
returnednull
and there is no default value. Subclasses typically throw an exception in this case.- 参数:
name
- the name for the valueparameter
- the method parameter- 抛出:
ServletException
handleResolvedValue
protected void handleResolvedValue(@Nullable Object arg, String name, MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
Invoked after a value is resolved.- 参数:
arg
- the resolved argument valuename
- the argument nameparameter
- the argument parameter typemavContainer
- theModelAndViewContainer
(may benull
)webRequest
- the current request