我有一个Managers
的列表,我需要在@Controller
方法中返回。我还有一个用户表单视图,我需要同时返回。 managerList
从之前的@Controller
返回。我可能一直盯着这个屏幕很久,这样做甚至没有意义,但这可以做到吗?
@RequestMapping(value = "/getuserForm", produces = "text/html", method = RequestMethod.GET)
public ModelAndView returnUserForm(
@ModelAttribute("managerList") List<Manager> managerList,
Model model) {
//how to include managerList
return new ModelAndView("userForm");
}
输出将是一个空白用户表单,其中包含一个管理员列表,表示将加载到选择输入中。有任何想法吗? 非常感谢
答案 0 :(得分:1)
您可以使用public ModelAndView(String viewName, Map<String, ?> model)
。在模型中,您可以列出您的列表。
答案 1 :(得分:1)
您可以使用ModelAndView对象的模型贴图
尝试以下代码
@RequestMapping(value = "/getuserForm", produces = "text/html", method = RequestMethod.GET)
public ModelAndView returnUserForm(
@ModelAttribute("managerList") List<Manager> managerList,
Model model) {
//how to include managerList
ModelAndView mnv= new ModelAndView("userForm");
mnv.getModelMap().addAttribute("managerList", managerList);
return mnv;
}
答案 2 :(得分:0)
@RequestMapping(value = "/getuserForm", produces = "text/html", method = RequestMethod.GET)
public ModelAndView returnUserForm(
@ModelAttribute("managerList") List<Manager> managerList,
Model model) {
//how to include managerList
model.addObject("managerList", managerList);
ModelAndView mnv= new ModelAndView("userForm");
mnv.getModelMap().addAttribute("managerList", managerList);
return mnv;
}