springmvc controller跳转到controller

版权声明:此文章为许诗宇所写,如需转载,请写下转载文章的地址 https://blog.csdn.net/xushiyu1996818/article/details/82621593

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";
  }

猜你喜欢

转载自blog.csdn.net/xushiyu1996818/article/details/82621593