gpt4 book ai didi

java - Spring重定向请求映射

转载 作者:行者123 更新时间:2023-12-01 14:07:44 27 4
gpt4 key购买 nike

我想重定向我的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com