spring 中controller间跳转传值

 

/**
* 逛苏宁上移下移
* @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/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值