除了使用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}
2、names:${requestScope.names}
3、city:${requestScope.city}
4、gender:${requestScope.gender}
结果: