SpringMVC中Model和ModelAndView的EL表达式取值方法
model和modelMap(spring封装),Java.util.Map
ModelMap(视图)
ModelAndViewmodelAndView=newModelAndView();
modelAndView.addObject("name","xxx");
modelAndView.setViewName("/user/index");
returnmodelAndView;
//对于ModelAndView构造函数可以指定返回页面的名称,也可以通过setViewName方法来设置所需要跳转的页面;
在前端用${name}调用
MODLE:
StringretVal="user/index";
Useruser=newUser();
user.setName("XXX");
model.addAttribute("currentUser",user);
returnretVal;
//通过addAttribute()添加属性,(假设user有name属性)在前端用${currentUser.name}调用
Map
ModelAndViewmav=newModelAndView();
Useruser1=newUser();------假设User有name的属性
Mapmap=newHashMap();
map.put("user",user1);//map.put相当于request.setAttribute方法
mav.addObject(map);
mav.setViewName("qweqas");
returnmav;;
//在前端用户${user.name}调用
以上这篇SpringMVC中Model和ModelAndView的EL表达式取值方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语