我想重定向我的 Controller 方法,以便我可以使用一个 url 提交一个表单,然后在浏览器中显示一个默认 url,像这样我需要更改返回类型 postForms,创建一个新模型并查看/重定向 View :
@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()
}
最佳答案
这样的事情怎么样:
@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";
}
关于java - Spring重定向请求映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9837413/