使用方法如下:
@RequestMapping("/retrieveType")
public ModelAndView retrieveType(ModelAndView modelAndView){
List<Type> typeList = typeService.retrieveType();
//将typeList传到前台
// model.addAttribute("typeList",typeList);
modelAndView.setViewName("type");
modelAndView.addObject("typeList",typeList);
// model.addAttribute("typeList",typeList);
StringBuilder builder = new StringBuilder();
for(Type type:typeList){
if(type!=null){
builder.append(type.toString()).append("<br>");
}
}
return modelAndView;
}
这之中要注意的是,setViewName的作用不止是你需要返回的页面,也是你Modal传入的页面,以上面例子来说,如果在除type.html其他的页面中使用typeList都是获取不到的。