Spring MVC 向页面传值-Map、Model和ModelMap

来源:互联网 发布:防小三软件 编辑:程序博客网 时间:2024/04/28 22:45

  除了使用ModelAndView方式外。还可以使用Map、Model和ModelMap来向前台页面创造

  使用后面3种方式,都是在方法参数中,指定一个该类型的参数。例如:

 

Java代码

复制代码
1 @RequestMapping("/test")2 public String test(Map<String,Object> map,Model model,ModelMap modelMap){3 4     map.put("names", Arrays.asList("caoyc","zhh","cjx"));5     model.addAttribute("time", new Date());6     modelMap.addAttribute("city", "ChengDu");7     modelMap.put("gender", "male");8     return "hello";9 }
复制代码

  

JSP页面

 

1 1、time:${requestScope.time}2 <br/>2、names:${requestScope.names }3 <br/>3、city:${requestScope.city }4 <br/>4、gender:${requestScope.gender }

 

 

结果:

0 0
原创粉丝点击