SessionAttributes注解:
a、该注解只能应用在类上;
b、该注解用于将Map、ModelMap、Model或ModelAndView中的数据暂存到HttpSession中以使其可以在多个请求之间共用数据;
@Controller @SessionAttributes(value = { "id" }) publicclass StudentController { @RequestMapping(value = "/student/login.do") public String login(Map<String, Object> map) { map.put("id", "29ec591c-ecb5-430e-9f86-1ef8a0b3d611"); return"result"; }
}
@Controller @SessionAttributes({"userInfo"}) publicclass UserInfoController { @RequestMapping("/userinfo/toView.do") public ModelAndView editView() { ModelAndView mv = new ModelAndView("to"); UserInfo userInfo = new UserInfo(); userInfo.setUserName("admin"); userInfo.setPassword("123456"); userInfo.setMobile("18838218972"); userInfo.setAddress("河南省郑州市高新区升龙又一城"); mv.addObject("userInfo", userInfo); returnmv; } }
通过这样注解后,我们就能在jsp页面上,用EL表达式来获取对应的数值,并且在一个session中有效