接着上篇文档 SpringBoot官方demo运行 继续研究 返回cookies信息的get接口开发。
1.环境准备
在源代码包 java文件下面新建包 com.course.server,包下面新建 MyGetMethod.java文件。
MyGetMethod 方法上方引用 @RestController
2.获取cookies信息
创建方法 getCookies ,方法如下
@RequestMapping(value = "/getCookies",method = RequestMethod.GET)
public String getCookies(HttpServletResponse response){
//HttpServerletRequeat 装请求信息的类
//HttpServerletResponse 装响应信息的类
Cookie cookie = new Cookie("login","true");
response.addCookie(cookie);
return "恭喜你获得cookies成功";
}
RequestMapping 对应的 value = "/getCookies", 是访问路径,启动 Application应用。
3.必须携带cookies信息才能访问的get请求
创建方法 getwithcookies ,方法如下:
@RequestMapping(value = "/get/with/cookies",method = RequestMethod.GET)
public St