簡體   English   中英

Spring重定向請求映射

[英]Spring redirect request mapping

我想重定向我的控制器方法,以便我可以提交一個帶有一個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()
}

這樣的事情怎么樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM