spring-framework / org.springframework.web.bind.annotation / PathVariable

PathVariable

@Target([AnnotationTarget.VALUE_PARAMETER]) class PathVariable

Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods in Servlet environments.

If the method parameter is java.util.Map or org.springframework.util.MultiValueMap then the map is populated with all path variable names and values.

Author
Arjen Poutsma

Author
Juergen Hoeller

Since
3.0

See Also
RequestMappingorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

Constructors

<init>

PathVariable(value: String, name: String, required: Boolean)

Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods in Servlet environments.

If the method parameter is java.util.Map or org.springframework.util.MultiValueMap then the map is populated with all path variable names and values.

Properties

name

val name: String

The name of the path variable to bind to.

required

val required: Boolean

Whether the path variable is required.

Defaults to true, leading to an exception being thrown if the path variable is missing in the incoming request. Switch this to false if you prefer a null or Java 8 java.util.Optional in this case. e.g. on a ModelAttribute method which serves for different requests.

value

val value: String

Alias for #name.