注意:服务器重启后之前存储的session会自动失效
通常用来做缓存,后面被redis取代...
@GetMapping("/t2")
public String down1(HttpServletRequest request) throws Exception {
//存储session
request.getSession().setAttribute("kkkk","986545");
String kkkk = request.getSession().getAttribute("kkkk")==null?"空":request.getSession().getAttribute("kkkk").toString();
return kkkk;
}
@GetMapping("/t3")
public String down2(HttpServletRequest request) throws Exception {
//查询session,删除后不可以直接查出来
String kkkk = request.getSession().getAttribute("kkkk")==null?"空":request.getSession().getAttribute("kkkk").toString();
return kkkk;
}
@GetMapping("/t4")
public String down3(HttpServletRequest request) throws Exception {
//删除session
request.getSession().removeAttribute("kkkk");
return "删除成功";
}