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就可以了。
|
|
来自: 忠波irlphwt1ng > 《springmvc》