<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
原生的:${type}
Hello ${requestScope.type}.
Hello ${sessionScope.type}.
</body>
</html>
@RequestMapping("/servletApi/session")
public String session01(HttpSession session){
session.setAttribute("type","servletApi-session");
return "main";
}
session参数可全局使用
@Autowired
private HttpSession session;
@RequestMapping("/autowired/session")
public String session02(){
session.setAttribute("type","autowired-session");
return "main";
}
用在类上面的,写入session的。
当我们在model中设置了一个参数的时候,会将model里面的参数复制一份放到session中(model中复制一份覆盖掉session中的)。
如果下一次请求model没有,model也会将session中的值复制一份放到model中(session中复制一份覆盖掉model中的)。
依赖于方法的model。
@SessionAttributes("type")
public class DAMController {
@RequestMapping("/modelAndView")
public ModelAndView map(){
ModelAndView modelAndView = new ModelAndView("main");
modelAndView.addObject("type","modelAndView");
return modelAndView;
}
}
用在参数上面的,读取session的。
可以获取到上一个放进去的相应参数。
@RequestMapping("/annotation/session")
public String session03(value = "type",required = false) String type){
System.out.println(type);
return "main";
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务