springmvc数据处理模型
1、ModelAndView
实现:
@RequestMapping("/testModelAndView")
public ModelAndView testModelAndView() {
modelAndView.addObject("name", "hy");
return modelAndView;
}
页面获取:
<% System.out.println(request.getAttribute("name")); %>
name: ${requestScope.name }
2、Map
使用map作为参数,向map中放值,参数也可以是model、modelmap
@RequestMapping("/testMap")
public String testMap(Map<String,Object> map) {
map.put("user", new User("ht", "123456", "ht@sina.com"));
return SUCCESS;
}
页面获取:
user: ${requestScope.user }
3、SessionSttributes
使用这个注解可以将值放在session域中
@SessionAttributes(names={"user"},types={User.class})
当向请求域中放user的时候也会同时向session里面放一份
页面:
session user: ${sessionScope.user }
邮箱:wangh_2@sina.com
浙公网安备 33010602011771号