redirectModel.addAttribute("Model", model);
return REDIRECT_PREFIX + "../../my-company/organization-management/manage-users";
通过此方法时,我得到转换异常:无法将
list<?>
转换为string
最佳答案
i)将RedirectAttributes redirectAttributes添加到第一个控制器中的方法参数列表中
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)然后,在第二个控制器中,使用带有@ModelAttribute注释的方法参数来访问重定向属性
@ModelAttribute("userModel") final Object userModel
最后,您的两个控制器方法如下所示:
// Controller1
@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";
}