SpringMVC(十一) RequestMapping获取Cookie值

可以在控制器方法中使用类似@CookieValue("JSESSIONID") String sessionID的方式,来获取请求中的Cookie的值。

样例控制器代码

复制代码
package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RequestCookieTest {

@RequestMapping("testRequestCookie")
public String testCookie(@CookieValue("JSESSIONID") String sessionID){
System.out.println(sessionID);
return "success";
}
}
复制代码

样例视图代码:

<a href="testRequestCookie">TestRequestCookie Video11</a>
https://github.com/godmaybelieve
原文地址:https://www.cnblogs.com/yuyu666/p/10117675.html