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

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

 

Java代码

@RequestMapping("/test")
public String test(Map<String,Object> map,Model model,ModelMap modelMap){
    map.put("names", Arrays.asList("caoyc","zhh","cjx"));
    model.addAttribute("time", new Date());
    modelMap.addAttribute("city", "ChengDu");
    modelMap.put("gender", "male");
    return "hello";
}

  

JSP页面

 

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

 

结果:

SpringMVC 向页面传值-Map、Model和ModelMap

 

 【推荐】:我们一般使用Map就可以了

 

本文转自:http://www.cnblogs.com/caoyc/p/5635878.html

相关文章:

  • 2022-12-23
  • 2021-08-06
  • 2022-02-25
  • 2021-07-15
  • 2022-12-23
  • 2022-01-05
  • 2022-02-23
猜你喜欢
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案