Springboot 操作Cookie

@RequestMapping("/hello2")
    public String hello2(HttpServletResponse response){
        Cookie cookie=new Cookie("name","瓜田李下3");
        cookie.setMaxAge(60);
        response.addCookie(cookie);
        return "success 2";
    }

    @RequestMapping("/hello3")
    public String hello3(HttpServletRequest request,@CookieValue("name") String name){
        System.out.println(name);
        Cookie[] cookies=request.getCookies();
        for (Cookie cookie:cookies){
            System.out.println(cookie.getName()+"  "+cookie.getValue());
        }

        return "success 3";
    }

 

posted @ 2022-04-07 17:10  凯宾斯基  阅读(757)  评论(0)    收藏  举报