类 AbstractNamedValueMethodArgumentResolver
- java.lang.Object
- org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver
- 所有已实现的接口:
HandlerMethodArgumentResolver
public abstract class AbstractNamedValueMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
Abstract base class to resolve method arguments from a named value, e.g. message headers or destination variables. Named values could have one or more of a name, a required flag, and a default value.Subclasses only need to define specific steps such as how to obtain named value details from a method parameter, how to resolve to argument values, or how to handle missing values.
A default value string can contain ${...} placeholders and Spring Expression Language
#{...}expressions which will be resolved if aConfigurableBeanFactoryis supplied to the class constructor.A
ConversionServiceis used to convert a resolved String argument value to the expected target method parameter type.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static classAbstractNamedValueMethodArgumentResolver.NamedValueInfoRepresents a named value declaration.
构造器概要
构造器 限定符 构造器 说明 protectedAbstractNamedValueMethodArgumentResolver(ConversionService conversionService, ConfigurableBeanFactory beanFactory)Constructor with aConversionServiceand aBeanFactory.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfocreateNamedValueInfo(MethodParameter parameter)Create theAbstractNamedValueMethodArgumentResolver.NamedValueInfoobject for the given method parameter.protected abstract voidhandleMissingValue(String name, MethodParameter parameter, Message<?> message)Invoked when a value is required, butresolveArgumentInternal(org.springframework.core.MethodParameter, org.springframework.messaging.Message<?>, java.lang.String)returnednulland there is no default value.protected voidhandleResolvedValue(Object arg, String name, MethodParameter parameter, Message<?> message)Invoked after a value is resolved.ObjectresolveArgument(MethodParameter parameter, Message<?> message)Resolves a method parameter into an argument value from a given message.protected abstract ObjectresolveArgumentInternal(MethodParameter parameter, Message<?> message, String name)Resolves 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.messaging.handler.invocation.HandlerMethodArgumentResolver
supportsParameter
构造器详细资料
AbstractNamedValueMethodArgumentResolver
protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionService, @Nullable ConfigurableBeanFactory beanFactory)
Constructor with aConversionServiceand aBeanFactory.- 参数:
conversionService- conversion service for converting String values to the target method parameter typebeanFactory- a bean factory for resolving${...}placeholders and#{...}SpEL expressions in default values
方法详细资料
resolveArgument
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception
从接口复制的说明:HandlerMethodArgumentResolverResolves a method parameter into an argument value from a given message.- 指定者:
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.message- the currently processed message- 返回:
- the resolved argument value, or
null - 抛出:
Exception- in case of errors with the preparation of argument values
createNamedValueInfo
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)
Create theAbstractNamedValueMethodArgumentResolver.NamedValueInfoobject for the given method parameter. Implementations typically retrieve the method annotation by means ofMethodParameter.getParameterAnnotation(Class).- 参数:
parameter- the method parameter- 返回:
- the named value information
resolveArgumentInternal
@Nullable protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) throws Exception
Resolves the given parameter type and value name into an argument value.- 参数:
parameter- the method parameter to resolve to an argument valuemessage- the current requestname- the name of the value being resolved- 返回:
- the resolved argument. May be
null - 抛出:
Exception- in case of errors
handleMissingValue
protected abstract void handleMissingValue(String name, MethodParameter parameter, Message<?> message)
Invoked when a value is required, butresolveArgumentInternal(org.springframework.core.MethodParameter, org.springframework.messaging.Message<?>, java.lang.String)returnednulland there is no default value. Sub-classes can throw an appropriate exception for this case.- 参数:
name- the name for the valueparameter- the target method parametermessage- the message being processed
handleResolvedValue
protected void handleResolvedValue(@Nullable Object arg, String name, MethodParameter parameter, Message<?> message)
Invoked after a value is resolved.- 参数:
arg- the resolved argument valuename- the argument nameparameter- the argument parameter typemessage- the message