@PathVariable supports 'required' attribute (for model attribute methods)
Issue: SPR-14646
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation which indicates that a method parameter should be bound to a URI template
|
||||
* variable. Supported for {@link RequestMapping} annotated handler methods in Servlet
|
||||
@@ -32,6 +34,7 @@ import java.lang.annotation.Target;
|
||||
* then the map is populated with all path variable names and values.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
* @see RequestMapping
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
|
||||
@@ -42,8 +45,26 @@ import java.lang.annotation.Target;
|
||||
public @interface PathVariable {
|
||||
|
||||
/**
|
||||
* The URI template variable to bind to.
|
||||
* Alias for {@link #name}.
|
||||
*/
|
||||
@AliasFor("name")
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The name of the path variable to bind to.
|
||||
* @since 4.3.3
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Whether the path variable is required.
|
||||
* <p>Defaults to {@code true}, leading to an exception being thrown if the path
|
||||
* variable is missing in the incoming request. Switch this to {@code false} if
|
||||
* you prefer a {@code null} or Java 8 {@code java.util.Optional} in this case.
|
||||
* e.g. on a {@code ModelAttribute} method which serves for different requests.
|
||||
* @since 4.3.3
|
||||
*/
|
||||
boolean required() default true;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user