Spring MVC Cookie example


原文:Spring MVC Cookie example


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
//..

@RequestMapping("/hello.html")
public String hello(HttpServletResponse response) {
    response.addCookie(new Cookie("foo", "bar"));

    //..
}
  
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
//..
@RequestMapping("/hello.html")
public String hello(
    @CookieValue(value = "foo", defaultValue = "hello") String fooCookie) {

    //..
}