转自:spring mvc controller间跳转 重定向 传参 (转)
return new ModelAndView("redirect:/toList");
这样可以重定向到toList这个方法。
return "redirect:/ toList ";
new ModelAndView("redirect:/toList?param1="+value1+"¶m2="+value2);
attr.addAttribute("param", value);
return "redirect:/namespace/toController";
@RequestMapping("/save")
public String save(@ModelAttribute("form") Bean form,RedirectAttributes attr)
throws Exception {
String code = service.save(form);
if(code.equals("000")){
attr.addFlashAttribute("name", form.getName());
attr.addFlashAttribute("success", "添加成功!");
return "redirect:/index";
}else{
attr.addAttribute("projectName", form.getProjectName());
attr.addAttribute("enviroment", form.getEnviroment());
attr.addFlashAttribute("msg", "添加出错!错误码为:"+rsp.getCode().getCode()+",错误为:"+rsp.getCode().getName());
return "redirect:/maintenance/toAddConfigCenter";
}
}
@RequestMapping("/index")
public String save(@ModelAttribute("form") Bean form,RedirectAttributes attr)
throws Exception {
return "redirect:/main/list";
}
这里的原理是放到session中,session在跳到页面后马上移除对象。所以你刷新一下后这个值就会丢掉。
spring mvc controller间跳转 重定向 传参
原文:http://www.cnblogs.com/drizzlewithwind/p/6092205.html