Spring MVC 向页面传值
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 }
结果: