public abstract class AbstractNamedValueMethodArgumentResolver extends java.lang.Object implements HandlerMethodArgumentResolver
Subclasses define how to do the following:
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.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractNamedValueMethodArgumentResolver.NamedValueInfo
Represents the information about a named value, including name, whether it's required and a default value.
|
Constructor and Description |
---|
AbstractNamedValueMethodArgumentResolver() |
AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory)
Create a new
AbstractNamedValueMethodArgumentResolver instance. |
Modifier and Type | Method and Description |
---|---|
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo |
createNamedValueInfo(MethodParameter parameter)
Create the
AbstractNamedValueMethodArgumentResolver.NamedValueInfo object for the given method parameter. |
protected void |
handleMissingValue(java.lang.String name,
MethodParameter parameter)
Invoked when a named value is required, but
resolveName(String, MethodParameter, NativeWebRequest)
returned null and there is no default value. |
protected void |
handleMissingValue(java.lang.String name,
MethodParameter parameter,
NativeWebRequest request)
Invoked when a named value is required, but
resolveName(String, MethodParameter, NativeWebRequest)
returned null and there is no default value. |
protected void |
handleResolvedValue(java.lang.Object arg,
java.lang.String name,
MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
Invoked after a value is resolved.
|
java.lang.Object |
resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
Resolves a method parameter into an argument value from a given request.
|
protected abstract java.lang.Object |
resolveName(java.lang.String name,
MethodParameter parameter,
NativeWebRequest request)
Resolve the given parameter type and value name into an argument value.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
supportsParameter
public AbstractNamedValueMethodArgumentResolver()
public AbstractNamedValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory)
AbstractNamedValueMethodArgumentResolver
instance.beanFactory
- a bean factory to use for resolving ${...} placeholder
and #{...} SpEL expressions in default values, or null
if default
values are not expected to contain expressions@Nullable public final java.lang.Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws java.lang.Exception
HandlerMethodArgumentResolver
ModelAndViewContainer
provides access to the model for the
request. A WebDataBinderFactory
provides a way to create
a WebDataBinder
instance when needed for data binding and
type conversion purposes.resolveArgument
in interface HandlerMethodArgumentResolver
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 requestwebRequest
- the current requestbinderFactory
- a factory for creating WebDataBinder
instancesnull
if not resolvablejava.lang.Exception
- in case of errors with the preparation of argument valuesprotected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)
AbstractNamedValueMethodArgumentResolver.NamedValueInfo
object for the given method parameter. Implementations typically
retrieve the method annotation by means of MethodParameter.getParameterAnnotation(Class)
.parameter
- the method parameter@Nullable protected abstract java.lang.Object resolveName(java.lang.String name, MethodParameter parameter, NativeWebRequest request) throws java.lang.Exception
name
- the name of the value being resolvedparameter
- the method parameter to resolve to an argument value
(pre-nested in case of a Optional
declaration)request
- the current requestnull
)java.lang.Exception
- in case of errorsprotected void handleMissingValue(java.lang.String name, MethodParameter parameter, NativeWebRequest request) throws java.lang.Exception
resolveName(String, MethodParameter, NativeWebRequest)
returned null
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 requestjava.lang.Exception
protected void handleMissingValue(java.lang.String name, MethodParameter parameter) throws ServletException
resolveName(String, MethodParameter, NativeWebRequest)
returned null
and there is no default value. Subclasses typically throw an exception in this case.name
- the name for the valueparameter
- the method parameterServletException
protected void handleResolvedValue(@Nullable java.lang.Object arg, java.lang.String name, MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
arg
- the resolved argument valuename
- the argument nameparameter
- the argument parameter typemavContainer
- the ModelAndViewContainer
(may be null
)webRequest
- the current request