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删除。