是否可以同时使用 @RequestMapping
和@ModelAttribute
Spring MVC Controller 中相同方法的注释?
例如,我想获得类似的东西:
@ModelAttribute("export_profiles")
@RequestMapping(value = "/profiles_list", method = RequestMethod.GET)
public @ResponseBody
ExportProfile[] getExportProfilesList() {
edService.getProfiles();
}
我想使用这种方法,因为在我的页面中我必须加载 ExportProfile
的列表为option
进入 select
。在同一页面中,我可以创建/删除导出配置文件,因此我必须刷新选择中的配置文件列表,并且我想使用对相同方法的 ajax 调用异步执行此操作。
是否可以使用单一方法来设置模型属性并处理异步请求?或者我必须使用两种不同的方法?
最佳答案
What I want to do is to set an ExportProfile array as model attribute, to populate a select the first time I load the page
你可以像这样设置页面的属性......
public String myMethodThatInitiatesPage(Model model) {
model.addAttribute("exportProfiles", edService.getProfiles())
return "yrViewName";
}
关于java - 在方法上同时使用 @RequestMapping 和 @ModelAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929030/