这两者之间有什么区别,它们都暴露了变量JSP
。第一种方法是标记为@ModelAttribute
的方法。第二个将所需的对象放入ModelAndView
。目标是为JSP
检索此变量。@ModelAttribute方法和放入ModelAndView之间有区别吗?
1)
@ModelAttribute("store_location_types")
public StoreLocationType[] getStoreLocationTypes() {
return StoreLocationType.values();
}
2)
public ModelAndView handlePage(Model m) {
ModelAndView mav = new ModelAndView("my.jsp");
mav.addObject("store_location_types", StoreLocationType.values();
//...
return mav;
}