Top Description Inners Fields Constructors Methods
org.springframework.web.method.annotation

public Class RequestParamMethodArgumentResolver

extends AbstractNamedValueMethodArgumentResolver
implements UriComponentsContributor
Class Inheritance
All Implemented Interfaces
org.springframework.web.method.support.UriComponentsContributor
Imports
java.beans.PropertyEditor, java.util.Collection, .List, .Map, .Optional, jakarta.servlet.http.HttpServletRequest, .Part, org.springframework.beans.BeanUtils, org.springframework.beans.factory.config.ConfigurableBeanFactory, org.springframework.core.MethodParameter, org.springframework.core.convert.ConversionService, .TypeDescriptor, org.springframework.core.convert.converter.Converter, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.bind.MissingServletRequestParameterException, .WebDataBinder, org.springframework.web.bind.annotation.RequestParam, .RequestPart, .ValueConstants, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.support.UriComponentsContributor, org.springframework.web.multipart.MultipartException, .MultipartFile, .MultipartRequest, .MultipartResolver, org.springframework.web.multipart.support.MissingServletRequestPartException, .MultipartResolutionDelegate, org.springframework.web.util.UriComponentsBuilder

Resolves method arguments annotated with @RequestParam, arguments of type MultipartFile in conjunction with Spring's MultipartResolver abstraction, and arguments of type jakarta.servlet.http.Part in conjunction with Servlet multipart requests. This resolver can also be created in default resolution mode in which simple types (int, long, etc.) not annotated with @RequestParam are also treated as request parameters with the parameter name derived from the argument name.

If the method parameter type is Map, the name specified in the annotation is used to resolve the request parameter String value. The value is then converted to a Map via type conversion assuming a suitable Converter or PropertyEditor has been registered. Or if a request parameter name is not specified the RequestParamMapMethodArgumentResolver is used instead to provide access to all request parameters in the form of a map.

A WebDataBinder is invoked to apply type conversion to resolved request header values that don't yet match the method parameter type.

Authors
Arjen Poutsma, Rossen Stoyanchev, Brian Clozel
Since
3.1
See Also
RequestParamMapMethodArgumentResolver

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final TypeDescriptor
private final boolean

Constructor Summary

AccessConstructor and Description
public
RequestParamMethodArgumentResolver(boolean
in default resolution mode a method argument that is a simple type, as defined in BeanUtils#isSimpleProperty, is treated as a request parameter even if it isn't annotated, the request parameter name is derived from the method parameter name.
useDefaultResolution
)

Create a new RequestParamMethodArgumentResolver instance.

public
RequestParamMethodArgumentResolver(ConfigurableBeanFactory
a bean factory used for resolving ${...} placeholder and #{...} SpEL expressions in default values, or null if default values are not expected to contain expressions
beanFactory
,
boolean
in default resolution mode a method argument that is a simple type, as defined in BeanUtils#isSimpleProperty, is treated as a request parameter even if it isn't annotated, the request parameter name is derived from the method parameter name.
useDefaultResolution
)

Create a new RequestParamMethodArgumentResolver instance.

Method Summary

Modifier and TypeMethod and Description
public void
contributeMethodArgument(MethodParameter
the controller method parameter (never null)
parameter
,
Object
the argument value (possibly null)
value
,
UriComponentsBuilder
the builder to update (never null)
builder
,
Map<String, Object>
a map to add URI variables to (never null)
uriVariables
,
ConversionService
a ConversionService to format values as Strings
conversionService
)

Implements org.springframework.web.method.support.UriComponentsContributor.contributeMethodArgument.

Process the given method argument and either update the UriComponentsBuilder or add to the map with URI variables to use to expand the URI after all arguments are processed.

protected AbstractNamedValueMethodArgumentResolver.NamedValueInfo
createNamedValueInfo(MethodParameter
the method parameter
parameter
)

Implements abstract org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.createNamedValueInfo.

Create the NamedValueInfo object for the given method parameter.

protected String
protected void
handleMissingValue(String
the name for the value
name
,
MethodParameter
the method parameter
parameter
,
NativeWebRequest
the current request
request
)

Overrides org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValue.

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value.

protected void
handleMissingValueAfterConversion(String
the name for the value
name
,
MethodParameter
the method parameter
parameter
,
NativeWebRequest
the current request
request
)

Overrides org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValueAfterConversion.

Invoked when a named value is present but becomes null after conversion.

protected void
handleMissingValueInternal(String name, MethodParameter parameter, NativeWebRequest request, boolean missingAfterConversion)

protected Object
resolveName(String
the name of the value being resolved
name
,
MethodParameter
the method parameter to resolve to an argument value (pre-nested in case of a java.util.Optional declaration)
parameter
,
NativeWebRequest
the current request
request
)

Implements abstract org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveName.

Resolve the given parameter type and value name into an argument value.

public boolean
supportsParameter(MethodParameter
the method parameter to check
parameter
)

Implements org.springframework.web.method.support.UriComponentsContributor.supportsParameter, org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Supports the following:

Inherited from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver:
handleMissingValuehandleResolvedValueresolveArgument

Field Detail

STRING_TYPE_DESCRIPTORback to summary
private static final TypeDescriptor STRING_TYPE_DESCRIPTOR
useDefaultResolutionback to summary
private final boolean useDefaultResolution

Constructor Detail

RequestParamMethodArgumentResolverback to summary
public RequestParamMethodArgumentResolver(boolean useDefaultResolution)

Create a new RequestParamMethodArgumentResolver instance.

Parameters
useDefaultResolution:boolean

in default resolution mode a method argument that is a simple type, as defined in BeanUtils#isSimpleProperty, is treated as a request parameter even if it isn't annotated, the request parameter name is derived from the method parameter name.

RequestParamMethodArgumentResolverback to summary
public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory, boolean useDefaultResolution)

Create a new RequestParamMethodArgumentResolver instance.

Parameters
beanFactory:ConfigurableBeanFactory

a bean factory used for resolving ${...} placeholder and #{...} SpEL expressions in default values, or null if default values are not expected to contain expressions

useDefaultResolution:boolean

in default resolution mode a method argument that is a simple type, as defined in BeanUtils#isSimpleProperty, is treated as a request parameter even if it isn't annotated, the request parameter name is derived from the method parameter name.

Method Detail

contributeMethodArgumentback to summary
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService)

Implements org.springframework.web.method.support.UriComponentsContributor.contributeMethodArgument.

Doc from org.springframework.web.method.support.UriComponentsContributor.contributeMethodArgument.

Process the given method argument and either update the UriComponentsBuilder or add to the map with URI variables to use to expand the URI after all arguments are processed.

Parameters
parameter:MethodParameter

the controller method parameter (never null)

value:Object

the argument value (possibly null)

builder:UriComponentsBuilder

the builder to update (never null)

uriVariables:Map<String, Object>

a map to add URI variables to (never null)

conversionService:ConversionService

a ConversionService to format values as Strings

Annotations
@Override
createNamedValueInfoback to summary
protected AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)

Implements abstract org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.createNamedValueInfo.

Doc from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.createNamedValueInfo.

Create the NamedValueInfo object for the given method parameter. Implementations typically retrieve the method annotation by means of MethodParameter#getParameterAnnotation(Class).

Parameters
parameter:MethodParameter

the method parameter

Returns:AbstractNamedValueMethodArgumentResolver.NamedValueInfo

the named value information

Annotations
@Override
formatUriValueback to summary
protected String formatUriValue(ConversionService cs, TypeDescriptor sourceType, Object value)
Annotations
@Nullable
handleMissingValueback to summary
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Overrides org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValue.

Doc from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValue.

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value. Subclasses typically throw an exception in this case.

Parameters
name:String

the name for the value

parameter:MethodParameter

the method parameter

request:NativeWebRequest

the current request

Annotations
@Override
handleMissingValueAfterConversionback to summary
protected void handleMissingValueAfterConversion(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Overrides org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValueAfterConversion.

Doc from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleMissingValueAfterConversion.

Invoked when a named value is present but becomes null after conversion.

Parameters
name:String

the name for the value

parameter:MethodParameter

the method parameter

request:NativeWebRequest

the current request

Annotations
@Override
handleMissingValueInternalback to summary
protected void handleMissingValueInternal(String name, MethodParameter parameter, NativeWebRequest request, boolean missingAfterConversion) throws Exception
resolveNameback to summary
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Implements abstract org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveName.

Doc from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveName.

Resolve the given parameter type and value name into an argument value.

Parameters
name:String

the name of the value being resolved

parameter:MethodParameter

the method parameter to resolve to an argument value (pre-nested in case of a java.util.Optional declaration)

request:NativeWebRequest

the current request

Returns:Object

the resolved argument (may be null)

Annotations
@Override
@Nullable
Exceptions
Exception:
in case of errors
supportsParameterback to summary
public boolean supportsParameter(MethodParameter parameter)

Implements org.springframework.web.method.support.UriComponentsContributor.supportsParameter, org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Supports the following:

Parameters
parameter:MethodParameter

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

the method parameter to check

Returns:boolean

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

true if this resolver supports the supplied parameter; false otherwise

Annotations
@Override
org.springframework.web.method.annotation back to summary

private Class RequestParamMethodArgumentResolver.RequestParamNamedValueInfo

extends NamedValueInfo
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
public

Constructor Detail

RequestParamNamedValueInfoback to summary
public RequestParamNamedValueInfo()
RequestParamNamedValueInfoback to summary
public RequestParamNamedValueInfo(RequestParam annotation)