spring mvc-向页面传值-Map、Model和ModelMap


https://www.cnblogs.com/caoyc/p/5635878.html

 

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

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

@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 }

 

结果:

 

一般使用Map就可以了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM