版权声明:转载请注明原始链接 https://blog.csdn.net/sswqzx/article/details/84195158
@CookieValue 获取cookie
测试环境参照:https://blog.csdn.net/sswqzx/article/details/84171999
HelloController2.java
package com.day01springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
/**
* @ Author :ShaoWei Sun.
* @ Date :Created in 20:58 2018/11/16
*/
@Controller
@RequestMapping("hello")
public class HelloController2 {
@RequestMapping("show25")
public String test25(Model model, @CookieValue("JSESSIONID")String jsessionid){
model.addAttribute("msg", "获取cookie,jsessionid:" + jsessionid);
return "hello2";
}
}
测试: