Class RequestParamArgumentResolver
java.lang.Object
org.springframework.web.service.invoker.AbstractNamedValueArgumentResolver
org.springframework.web.service.invoker.RequestParamArgumentResolver
- All Implemented Interfaces:
HttpServiceArgumentResolver
HttpServiceArgumentResolver
for @RequestParam
annotated arguments.
When "content-type"
is set to
"application/x-www-form-urlencoded"
, request parameters are encoded
in the request body. Otherwise, they are added as URL query parameters.
The argument may be:
Map<String, ?>
orMultiValueMap<String, ?>
with multiple request parameter and value(s).Collection
or an array of request parameters.- An individual request parameter.
Individual request parameters may be Strings or Objects to be converted to
String values through the configured ConversionService
.
If the value is required but null
, IllegalArgumentException
is raised. The value is not required if:
RequestParam.required()
is set tofalse
RequestParam.defaultValue()
provides a fallback value- The argument is declared as
Optional
- Since:
- 6.0
- Author:
- Rossen Stoyanchev
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.web.service.invoker.AbstractNamedValueArgumentResolver
AbstractNamedValueArgumentResolver.NamedValueInfo
-
Field Summary
Fields inherited from class org.springframework.web.service.invoker.AbstractNamedValueArgumentResolver
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addRequestValue
(String name, Object value, MethodParameter parameter, HttpRequestValues.Builder requestValues) Add the given, single request value.createNamedValueInfo
(MethodParameter parameter) Return information about the request value, ornull
if the parameter does not represent a request value of interest.createNamedValueInfo
(MethodParameter parameter, HttpRequestValues.Metadata metadata) Variant ofAbstractNamedValueArgumentResolver.createNamedValueInfo(MethodParameter)
that also provides access to the static values set from@HttpExchange
attributes.boolean
Return the setting forfavorSingleValue
.protected boolean
Whether the content type is form data, or it is a multipart request.void
setFavorSingleValue
(boolean favorSingleValue) Whether to format multiple values (for example, collection, array) as a single String value through the configuredConversionService
unless the content type is form data, or it is a multipart request.protected boolean
supportsMultipleValues
(MethodParameter parameter, HttpRequestValues.Metadata metadata) Determine whether the resolver should send multi-value request parameters as individual values.Methods inherited from class org.springframework.web.service.invoker.AbstractNamedValueArgumentResolver
resolve
-
Constructor Details
-
RequestParamArgumentResolver
-
-
Method Details
-
setFavorSingleValue
public void setFavorSingleValue(boolean favorSingleValue) Whether to format multiple values (for example, collection, array) as a single String value through the configuredConversionService
unless the content type is form data, or it is a multipart request.By default, this is
false
in which case formatting is not applied, and a separate parameter with the same name is created for each value.- Since:
- 6.2
-
isFavorSingleValue
public boolean isFavorSingleValue()Return the setting forfavorSingleValue
.- Since:
- 6.2
-
createNamedValueInfo
@Nullable protected AbstractNamedValueArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter, HttpRequestValues.Metadata metadata) Description copied from class:AbstractNamedValueArgumentResolver
Variant ofAbstractNamedValueArgumentResolver.createNamedValueInfo(MethodParameter)
that also provides access to the static values set from@HttpExchange
attributes.- Overrides:
createNamedValueInfo
in classAbstractNamedValueArgumentResolver
-
createNamedValueInfo
protected AbstractNamedValueArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter) Description copied from class:AbstractNamedValueArgumentResolver
Return information about the request value, ornull
if the parameter does not represent a request value of interest.- Specified by:
createNamedValueInfo
in classAbstractNamedValueArgumentResolver
-
supportsMultipleValues
protected boolean supportsMultipleValues(MethodParameter parameter, HttpRequestValues.Metadata metadata) Determine whether the resolver should send multi-value request parameters as individual values. If not, they are formatted to a single String value. The default implementation usesisFavorSingleValue()
to decide unless the content type is form data, or it is a multipart request.- Since:
- 6.2
-
isFormOrMultipartContent
Whether the content type is form data, or it is a multipart request.- Since:
- 6.2
-
addRequestValue
protected void addRequestValue(String name, Object value, MethodParameter parameter, HttpRequestValues.Builder requestValues) Description copied from class:AbstractNamedValueArgumentResolver
Add the given, single request value. This may be called multiples times if the request value is multivalued.If the resolver was created with a
ConversionService
, the value will have been converted to a String and may be cast down.- Specified by:
addRequestValue
in classAbstractNamedValueArgumentResolver
- Parameters:
name
- the request value namevalue
- the valueparameter
- the method parameter type, nested if Map, List/array, or OptionalrequestValues
- builder to add the request value to
-