2012-03-23 139 views
0

我想重定向我的控制器方法,以便我可以使用一個url提交表單,然後在瀏覽器中顯示一個默認url,像這樣的somethign我需要更改返回類型postForms,創建一個新的模型和視圖/ RedirectView的:Spring重定向請求映射

@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() 
} 

回答

3

怎麼是這樣的:

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