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";
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM