Struts2式的FlashAttribute
为了防止用户刷新重复提交,save操作之后一般会redirect到另一个页面,同时带点操作成功的提示信息。因为是Redirect,Request里的attribute不会传递过去,如果放在session中,则需要在显示后及时清理,不然下面每一页都带着这个信息也不对。Spring在3.1才提供了这个能力。
public String save(@ModelAttribute("group") Group group, RedirectAttributes redirectAttributes) {
accountManager.saveGroup(group);
redirectAttributes.addFlashAttribute("message", "修改权限组成功");
return "redirect:/account/group/";
}
摘录自:https://github.com/springside/springside4/wiki/SpringMVC
本文介绍了一种类似于Struts2框架中处理用户操作后反馈信息的方法,利用Spring框架提供的RedirectAttributes来实现在重定向时临时保存提示信息,确保用户在刷新页面时不会重复提交表单。
2320

被折叠的 条评论
为什么被折叠?



