Spring 4 中重定向RedirectAttributes的使用
Posted on 2019-01-11 15:26 work hard work smart 阅读(281) 评论(0) 编辑 收藏 举报RedirectAttributes 的使用
@RequestMapping(value = "/redirecttest", produces = "application/json;charset=utf-8",method = RequestMethod.GET) public String redirectest(HttpServletResponse response, RedirectAttributes attributes ) throws IOException { Logs.info("redirectest"); attributes.addFlashAttribute("param1","value1"); attributes.addAttribute("param2","value2"); return "redirect:/redirectaccept"; } @RequestMapping(value = "/redirectaccept", produces = "application/json;charset=utf-8",method = RequestMethod.GET) @ResponseBody public String redirecaccept(HttpServletResponse response, @ModelAttribute("param1") String param1, @RequestParam("param2") String param2 ) { Logs.info("redirecaccept1, param1 " + param1 + " param2: " +param2 ); return "ok"; }
1、显示参数
attributes.addAttribute("param2","value2");
相当于才url后面增加param2=value2
2、隐藏参数
attributes.addFlashAttribute("param1","value1");
本质上是将参数保存在session中,接收到后再将session删除。
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!