【问题标题】:Spring redirect request mappingSpring重定向请求映射
【发布时间】:2012-04-07 21:46:54
【问题描述】:

我想重定向我的控制器方法,这样我就可以提交一个带有一个 url 的表单,然后在浏览器中显示一个默认 url,像这样我需要更改返回类型 postForms,创建一个新模型并查看/重定向视图:

@RequestMapping(value = "/Home", method = RequestMethod.GET)
public String getHome( Model model){
  //view name append with .jsp
  return "myHome"; 
}

@RequestMapping(value = "/FormA", method = RequestMethod.POST)
public String postFormA(Email Email, Model model){
  //do stuff then
  //redirect to different requestMapping broswer url "/Home"
  getHome()    
}

@RequestMapping(value = "/FormB", method = RequestMethod.POST)
public String postFormB( Model model){
  //do stuff then
  //redirect to different requestMapping and display in broswer url "/Home"
  getHome()
}

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    这样的事情怎么样:

    @RequestMapping(value = "/Home", method = RequestMethod.GET)
    public ModelAndView getHome(){
      //view name append with .jsp
      return new ModelAndView("myHome"); 
    }
    
    @RequestMapping(value = "/FormA", method = RequestMethod.POST)
    public String postFormA(Email Email, Model model){
      //do stuff then
      //redirect to different requestMapping broswer url "/Home"
      return "redirect:/Home";
    }
    
    @RequestMapping(value = "/FormB", method = RequestMethod.POST)
    public String postFormB( Model model){
      //do stuff then
      //redirect to different requestMapping and display in broswer url "/Home"
      return "redirect:/Home";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 2018-11-12
      • 2019-11-25
      • 2023-01-05
      • 1970-01-01
      • 2017-04-08
      • 2012-07-02
      • 2016-12-09
      相关资源
      最近更新 更多