redirectModel.addAttribute("Model", model);
return REDIRECT_PREFIX + "../../my-company/organization-management/manage-users";
当我通过这个时,我得到转换异常:无法转换 list<?>
至string
i) 将RedirectAttributesredirectAttributes添加到第一个 Controller 中的方法参数列表
public String test(
@ModelAttribute("userModel") final Object UserModel,
final BindingResult bindingResult,
final Model model,
final RedirectAttributes redirectAttributes)
ii) Inside the method added code to add flash attribute to redirectAttributes
redirectAttributes.addFlashAttribute("userModel", mapping1FormObject);
iii) 然后,在第二个 Controller 中使用@ModelAttribute注释的方法参数来访问重定向属性
@ModelAttribute("userModel") final Object userModel
最后你的两个 Controller 方法如下所示:// Controller 1
@RequestMapping(value = { "/page1" }, method = RequestMethod.POST)
public String test1(
@ModelAttribute("userModel") final Object userModel,
final BindingResult bindingResult,
final Model model,
final RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("userModel", mapping1FormObject);
return "redirect:page2";
}
//Controller2
@RequestMapping(value = "/page2", method = RequestMethod.GET)
public String test2(
@ModelAttribute("userModel") final Object userModel,
final BindingResult bindingResult,
final Model model) {
return "new/view";
}
我是一名优秀的程序员,十分优秀!