使用redirectAttributes.addFlashAttribute(" object",objectvalue);
就像这样,它成功地将对象值重定向到下一个控制器,但是当我们在下一个控制器中返回视图时,它会在浏览器的html页面中显示结果。然后,当我们刷新或重新加载页面然后值消失时,问题就开始了。
我的代码是
@RequestMapping(value = "/addRoom", method = RequestMethod.POST)
public String saveRoom(Room room,
ModelMap model, RedirectAttributes ra) {
amenitiesService.saveRoom(room);
Floor floor = amenitiesService.getFloorInfo(room.getFloorId());
String floorName = floor.getFloorName();
ra.addFlashAttribute(room);
ra.addFlashAttribute("floorName", floorName);
ra.addFlashAttribute("message","Room information is saved successfully.");
return "redirect:/redirectedUrl";
}
@RequestMapping(value = "/redirectedUrl")
public String redirecturl(Room room, ModelMap model) {
return ADMIN_VIEW + SAVE_ROOM;
}
请任何人建议我如何将对象值重定向到下一个控制器,永久性不是临时可见的,如闪存属性
答案 0 :(得分:0)
使用它可能是工作
@RequestMapping(value = "/redirectedUrl")
public String redirecturl(Room room, ModelMap model, RedirectAttributes re) {
String name=(String)re.getFlashAttributes("floorName");
return ADMIN_VIEW + SAVE_ROOM;
}