|
对于最新的稳定版本,请使用 Spring Framework 6.2.10! |
@CookieValue
您可以使用@CookieValue注释,将 HTTP cookie 的值绑定到方法参数
在控制器中。
考虑使用以下 cookie 的请求:
JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84
以下示例演示如何获取 cookie 值:
-
Java
-
Kotlin
@GetMapping("/demo")
public void handle(@CookieValue("JSESSIONID") String cookie) { (1)
//...
}
| 1 | 获取JSESSIONID饼干。 |
@GetMapping("/demo")
fun handle(@CookieValue("JSESSIONID") cookie: String) { (1)
//...
}
| 1 | 获取JSESSIONID饼干。 |
如果目标方法参数类型不是String,则自动应用类型转换。
请参阅类型转换。