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就可以了。