Class AbstractNamedValueMethodArgumentResolver
java.lang.Object
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver
- All Implemented Interfaces:
- HandlerMethodArgumentResolver
- Direct Known Subclasses:
- 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.
- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classRepresents the information about a named value, including name, whether it's required and a default value.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfocreateNamedValueInfo(MethodParameter parameter) Create theAbstractNamedValueMethodArgumentResolver.NamedValueInfoobject for the given method parameter.protected voidhandleMissingValue(String name, MethodParameter parameter) Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)returnednulland there is no default value.protected voidhandleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)returnednulland there is no default value.protected voidhandleMissingValueAfterConversion(String name, MethodParameter parameter, NativeWebRequest request) Invoked when a named value is present but becomesnullafter conversion.protected voidhandleResolvedValue(@Nullable Object arg, String name, MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest) Invoked after a value is resolved.resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) Resolves a method parameter into an argument value from a given request.resolveName(String name, MethodParameter parameter, NativeWebRequest request) Resolve the given parameter type and value name into an argument value.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.method.support.HandlerMethodArgumentResolversupportsParameter
- 
Constructor Details- 
AbstractNamedValueMethodArgumentResolverpublic AbstractNamedValueMethodArgumentResolver()
- 
AbstractNamedValueMethodArgumentResolverCreate a newAbstractNamedValueMethodArgumentResolverinstance.- Parameters:
- beanFactory- a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions in default values, or- nullif default values are not expected to contain expressions
 
 
- 
- 
Method Details- 
resolveArgumentpublic final @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception Description copied from interface:HandlerMethodArgumentResolverResolves a method parameter into an argument value from a given request. AModelAndViewContainerprovides access to the model for the request. AWebDataBinderFactoryprovides a way to create aWebDataBinderinstance when needed for data binding and type conversion purposes.- Specified by:
- resolveArgumentin interface- HandlerMethodArgumentResolver
- Parameters:
- parameter- the method parameter to resolve. This parameter must have previously been passed to- HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)which must have returned- true.
- mavContainer- the ModelAndViewContainer for the current request
- webRequest- the current request
- binderFactory- a factory for creating- WebDataBinderinstances
- Returns:
- the resolved argument value, or nullif not resolvable
- Throws:
- Exception- in case of errors with the preparation of argument values
 
- 
createNamedValueInfoprotected 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).- Parameters:
- parameter- the method parameter
- Returns:
- the named value information
 
- 
resolveNameprotected abstract @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception Resolve the given parameter type and value name into an argument value.
- 
handleMissingValueprotected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception Invoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)returnednulland there is no default value. Subclasses typically throw an exception in this case.- Parameters:
- name- the name for the value
- parameter- the method parameter
- request- the current request
- Throws:
- Exception
- Since:
- 4.3
 
- 
handleMissingValueInvoked when a named value is required, butresolveName(String, MethodParameter, NativeWebRequest)returnednulland there is no default value. Subclasses typically throw an exception in this case.- Parameters:
- name- the name for the value
- parameter- the method parameter
- Throws:
- ServletException
 
- 
handleMissingValueAfterConversionprotected void handleMissingValueAfterConversion(String name, MethodParameter parameter, NativeWebRequest request) throws Exception Invoked when a named value is present but becomesnullafter conversion.- Parameters:
- name- the name for the value
- parameter- the method parameter
- request- the current request
- Throws:
- Exception
- Since:
- 5.3.6
 
- 
handleResolvedValueprotected void handleResolvedValue(@Nullable Object arg, String name, MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest) Invoked after a value is resolved.- Parameters:
- arg- the resolved argument value
- name- the argument name
- parameter- the argument parameter type
- mavContainer- the- ModelAndViewContainer(may be- null)
- webRequest- the current request
 
 
-