页面
success.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${requestScope.msg}<br/>
${requestScope.clazz}<br/>
</body>
</html>
1、方法参数Map
在处理方法传入形参Map<Stirng, Object>类型的参数
@RequestMapping("/handle01")
public String handle01(Map<String, Object> map){
map.put("msg", "This is map");
map.put("clazz", map.getClass());
return "success.jsp";
}
结果:
2.方法参数Model
@RequestMapping("/handle02")
public String handle02(Model model){
model.addAttribute("msg", "This is model");
model.addAttribute("clazz", model.getClass());
return "success.jsp";
}
结果:
3.方法参数ModelMap
@RequestMapping("/handle03")
public String handle03(ModelMap modelMap){
modelMap.addAttribute("msg", "This is modelMap");
modelMap.addAttribute("clazz", modelMap.getClass());
return "success.jsp";
}
结果:
4.方法返回值ModelAndView
@RequestMapping("/handle04")
public ModelAndView handle04(){
ModelAndView mv = new ModelAndView();
mv.setViewName("success.jsp");
mv.addObject("msg", "This is mv");
return mv;
}
结果:
从上可以看出,对于Map、Model、ModelMap实际上是SpringMVC传递给方法的BindingAwareModelMap对象