此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Framework 6.2.10spring-doc.cadn.net.cn

@CookieValue

您可以使用@CookieValue注释,将 HTTP cookie 的值绑定到方法参数在控制器中。spring-doc.cadn.net.cn

以下示例显示了带有 cookie 的请求:spring-doc.cadn.net.cn

JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84

以下代码示例演示了如何获取 cookie 值:spring-doc.cadn.net.cn

@GetMapping("/demo")
public void handle(@CookieValue("JSESSIONID") String cookie) { (1)
	//...
}
1 获取 cookie 值。
@GetMapping("/demo")
fun handle(@CookieValue("JSESSIONID") cookie: String) { (1)
	//...
}
1 获取 cookie 值。

如果目标方法参数类型不是String. 请参阅类型转换spring-doc.cadn.net.cn