spring 中controller间跳转传值

来源:互联网 发布:软件测试建立文档 编辑:程序博客网 时间:2024/05/16 11:53

 

/*** 逛苏宁上移下移* @throws UnsupportedEncodingException */@RequestMapping("/guang_move")public String guangMove(@ModelAttribute("guang") GuangEntity guang,@ModelAttribute Pager<Map<String, Object>> pager,String type,Model model,RedirectAttributes redirectAttributes) throws UnsupportedEncodingException {// 参数不符合,返回列表页面if (StringUtils.isEmpty(type)) {return "tvShop3/guang_list.htm"; }// 当前移动数据所在环境的检索条件String keyWord="";Map<String, Object> commentMap = new HashMap<String, Object>();if(null != pager.getKeyword()){// 搜索条件中文转码keyWord = java.net.URLDecoder.decode(pager.getKeyword(),"UTF-8");  pager.setKeyword(keyWord);}commentMap.put(pager.getProperty(), keyWord);pager.setQueryParam(commentMap);// 回写搜索条件redirectAttributes.addFlashAttribute("pager", pager);// 整个数据移动this.shopService.guangMove(pager, type,guang);return "redirect:/tvShop3/guang_list.htm";}

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/";}
BY : http://blog.163.com/gu_mei_love/blog/static/183211193201391683957851/


0 0
原创粉丝点击