How to use Redirect in ModelAndView

后端 未结 2 1052
野的像风
野的像风 2020-12-11 06:12

I Want to redirect my url to http://localhost:8080/ClickBuy/product/details to http://localhost:8080/ClickBuy/home .

I have Define header.jsp and Include it

相关标签:
2条回答
  • 2020-12-11 06:34

    There are different ways to redirect but using Spring ModelView Object is simple

    @RequestMapping(value = "/redirecturl", method = RequestMethod.POST)
        public ModelAndView methodPost() {
                return new ModelAndView( "redirect:/login.html");
    
        }
    
    0 讨论(0)
  • 2020-12-11 06:48

    To Use redirect:/ in ModelAndView return type method, you are try following

    ModelAndView modelAndView =  new ModelAndView("redirect:/abc.htm");
    modelAndView.addObject("modelAttribute" , new ModelAttribute());
    return modelAndView;
    

    You can also return home page using String returntype if you do not need any Model in home page

    @RequestMapping(value = "/home.htm", method = RequestMethod.GET)
       public String homePage() {
          return "home";
       }
    
    0 讨论(0)
提交回复
热议问题