具体就表现在Model只是用来传输数据的,并不会进行业务的寻址。但是,ModelAndView却是可以进行业务寻址的,就是设置对应的要请求的静态文件,这里的静态文件指的是类似jsp的文件。
示例:
一:ModelAndView
controller代码:
@RequestMapping("/item/paramshtml/{cid}")
public ModelAndView findItemparamshtmlBycid(@PathVariable long cid){
String html =itemService.findItemParamsHtmlBycid(cid);
ModelAndView mv = new ModelAndView();
mv.addObject("myhtml",html);
mv.setViewName("itemParams");
return m
}
jsp接收参数代码:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${myhtml}
</body>
</html>
二 :Model
controller:
@RequestMapping("/item/paramshtml/{cid}")
public String findItemparamshtmlBycid(@PathVariable long cid,Model model){
String html =itemService.findItemParamsHtmlBycid(cid);
model.addAttribute("myhtml",html);
return "itemParams";
}
参数的接收方式同modelandview。