SpringMVC(十一) RequestMapping獲取Cookie值
阿新 • • 發佈:2018-12-14
可以在控制器方法中使用類似@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>