此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
@CookieValue
您可以使用@CookieValue
注解将 HTTP Cookie 的值绑定到方法参数
在控制器中。
以下示例显示了一个带有 Cookie 的请求:
JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84
以下代码示例演示如何获取 Cookie 值:
-
Java
-
Kotlin
@GetMapping("/demo")
public void handle(@CookieValue("JSESSIONID") String cookie) { (1)
//...
}
1 | 获取 cookie 值。 |
@GetMapping("/demo")
fun handle(@CookieValue("JSESSIONID") cookie: String) { (1)
//...
}
1 | 获取 cookie 值。 |
如果目标方法参数 type 不是String
.请参阅类型转换。