1 不带参数
使用ModelAndView
return new ModelAndView("redirect:/toList.do");
2 带参数
使用ModelAndView
return new ModelAndView("redirect:/toList.do?user=1");
3 带参数推荐
@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.do";
}
}
@RequestMapping("/index")
public String save(@ModelAttribute("form") Bean form,RedirectAttributes attr) throws Exception {
return "redirect:/main/list.do";
}