标签:let array ring pre arraylist ret app 框架 att
为什么大多程序在controller中给jsp传值时使用model.addAttribute()而不使用httpServeletRequest.setAttribute()?
事实上model数据,最终spring也是写到HttpServletRequest属性中,只是用model更符合mvc设计,减少各层间耦合。
@RequestMapping(value="/list",method=RequestMethod.GET) public String list(Model model) { //前台输出必须使用形如${ul.value.属性名 }的形式 model.addAttribute("userList",userList); return "user/userList"; } @RequestMapping(value="/userlist",method=RequestMethod.GET) public String list(HttpServletRequest request) { //前台输出必须使用形如${user.id }的形式 List<User> userList = new ArrayList<User>(); userList.add(new User("1","yonghu1","121","1@qq.com")); userList.add(new User("2","yonghu2","122","2@qq.com")); userList.add(new User("3","yonghu3","123","3@qq.com")); request.setAttribute("userList", userList); return "user/userList"; }
Java SpringMVC框架学习(二)httpServeltRequest和Model传值的区别
标签:let array ring pre arraylist ret app 框架 att
原文地址:https://www.cnblogs.com/cnki/p/9059262.html