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

public Class PathVariableMethodArgumentResolver

extends AbstractNamedValueMethodArgumentResolver
implements UriComponentsContributor
Class Inheritance
All Implemented Interfaces
org.springframework.web.method.support.UriComponentsContributor
Imports
java.beans.PropertyEditor, java.util.HashMap, .Map, 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.MissingPathVariableException, .ServletRequestBindingException, .WebDataBinder, org.springframework.web.bind.annotation.PathVariable, .ValueConstants, org.springframework.web.context.request.NativeWebRequest, .RequestAttributes, org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver, org.springframework.web.method.support.ModelAndViewContainer, .UriComponentsContributor, org.springframework.web.servlet.HandlerMapping, .View, org.springframework.web.util.UriComponentsBuilder

Resolves method arguments annotated with an @PathVariable.

An @PathVariable is a named value that gets resolved from a URI template variable. It is always required and does not have a default value to fall back on. See the base class org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver for more information on how named values are processed.

If the method parameter type is Map, the name specified in the annotation is used to resolve the URI variable String value. The value is then converted to a Map via type conversion, assuming a suitable Converter or PropertyEditor has been registered.

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

Authors
Rossen Stoyanchev, Arjen Poutsma, Juergen Hoeller
Since
3.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final TypeDescriptor

Constructor Summary

AccessConstructor and Description
public

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
)

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
handleResolvedValue(Object
the resolved argument value
arg
,
String
the argument name
name
,
MethodParameter
the argument parameter type
parameter
,
ModelAndViewContainer
the ModelAndViewContainer (may be null)
mavContainer
,
NativeWebRequest
the current request
request
)

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

Invoked after a value is resolved.

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
Inherited from org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver:
handleMissingValueresolveArgument

Field Detail

STRING_TYPE_DESCRIPTORback to summary
private static final TypeDescriptor STRING_TYPE_DESCRIPTOR

Constructor Detail

PathVariableMethodArgumentResolverback to summary
public PathVariableMethodArgumentResolver()

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) throws ServletRequestBindingException

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

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
handleResolvedValueback to summary
protected void handleResolvedValue(Object arg, String name, MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request)

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

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

Invoked after a value is resolved.

Parameters
arg:Object

the resolved argument value

name:String

the argument name

parameter:MethodParameter

the argument parameter type

mavContainer:ModelAndViewContainer

the ModelAndViewContainer (may be null)

request:NativeWebRequest

the current request

Annotations
@Override
@SuppressWarnings:unchecked
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
@SuppressWarnings:unchecked
@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.

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

Whether this contributor supports the given method parameter.

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.servlet.mvc.method.annotation back to summary

private Class PathVariableMethodArgumentResolver.PathVariableNamedValueInfo

extends NamedValueInfo
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Constructor Detail

PathVariableNamedValueInfoback to summary
public PathVariableNamedValueInfo(PathVariable annotation)