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

public @Interface CookieValue

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

Annotation to indicate that a method parameter is bound to an HTTP cookie.

The method parameter may be declared as type jakarta.servlet.http.Cookie or as cookie value type (String, int, etc.).

Note that with spring-webmvc 5.3.x and earlier, the cookie value is URL decoded. This will be changed in 6.0 but in the meantime, applications can also declare parameters of type jakarta.servlet.http.Cookie to access the raw value.

Authors
Juergen Hoeller, Sam Brannen
Since
3.0
See Also
RequestMapping, RequestParam, RequestHeader, org.springframework.web.bind.annotation.RequestMapping

Method Summary

Modifier and TypeMethod and Description
public String
defaultValue()

The default value to use as a fallback.

public String
name()

The name of the cookie to bind to.

public boolean
required()

Whether the cookie is required.

public String
value()

Alias for name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

defaultValueback to summary
public String defaultValue()

The default value to use as a fallback.

Supplying a default value implicitly sets required to false.

nameback to summary
public String name()

The name of the cookie to bind to.

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

Whether the cookie is required.

Defaults to true, leading to an exception being thrown if the cookie is missing in the request. Switch this to false if you prefer a null value if the cookie is not present in the request.

Alternatively, provide a defaultValue, which implicitly sets this flag to false.

valueback to summary
public String value()

Alias for name.

Annotations
@AliasFor:name