因为HTTP的重定向参数是以字符串传递的,并不能有效的传递对象,我们需要用到RedirectAttributes来进行传递,详情如代码所示。
//如果要在重定向的时候传递对象,我们需要利用RedirectAttributes来进行传递。
@RequestMapping("/getRoleFromListData2")
public String getRoleFromListData2(@RequestBody List<Role> list, RedirectAttributes ra){
Role role = list.get(0);
ra.addFlashAttribute("role",role);
//因为http的重定向参数是以字符串传递的,并不能有效的传递对象。
//使用addFlashAttribute方法后,springMVC会将数据保存到Session中,重定向之后就会将其清除
return "redirect:./showRoleJsonInfo2.do";
}
下面正常接收就可以了。
@RequestMapping("/showRoleJsonInfo2")
public ModelAndView showRoleJsonInfo2(Role role){
System.out.println(role);
ModelAndView mv = new ModelAndView();
mv.setView(new MappingJackson2JsonView());
mv.addObject("role",role);
return mv;
}