1. 程式人生 > >SpringMVC(十一) RequestMapping獲取Cookie值

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>