Top Description Methods
org.springframework.web.bind.annotation

public @Interface RequestAttribute

extends Annotation
Annotations
@Target:PARAMETER
@Retention:RUNTIME
@Documented
Imports
java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target, org.springframework.core.annotation.AliasFor

Annotation to bind a method parameter to a request attribute.

The main motivation is to provide convenient access to request attributes from a controller method with an optional/required check and a cast to the target method parameter type.

Author
Rossen Stoyanchev
Since
4.3
See Also
RequestMapping, SessionAttribute

Method Summary

Modifier and TypeMethod and Description
public String
name()

The name of the request attribute to bind to.

public boolean
required()

Whether the request attribute is required.

public String
value()

Alias for name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

nameback to summary
public String name()

The name of the request attribute to bind to.

The default name is inferred from the method parameter name.

Annotations
@AliasFor:value
requiredback to summary
public boolean required()

Whether the request attribute is required.

Defaults to true, leading to an exception being thrown if the attribute is missing. Switch this to false if you prefer a null or Java 8 java.util.Optional if the attribute doesn't exist.

valueback to summary
public String value()

Alias for name.

Annotations
@AliasFor:name