繁体   English   中英

如何在ModelAndView中使用Redirect

[英]How to use Redirect in ModelAndView

我想将我的网址重定向到http:// localhost:8080 / ClickBuy / product / detailshttp:// localhost:8080 / ClickBuy / home

我已经定义了header.jsp并将其包含在我的所有Pages中。当我从其他任何地方点击主页链接url add / home从当前url.So它显示404错误。

调节器

public ModelAndView allProduct()
{   
ModelAndView model=new ModelAndView("pl");
model.addObject("data", pd.getAllProducts());
return model;
}

如何在ModelAndView中使用redirect:/返回类型方法???

要在ModelAndView返回类型方法中使用重定向:/,请尝试以下操作

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

如果您不需要主页中的任何模型,也可以使用String returntype返回主页

@RequestMapping(value = "/home.htm", method = RequestMethod.GET)
   public String homePage() {
      return "home";
   }

有不同的重定向方法,但使用Spring ModelView Object很简单

@RequestMapping(value = "/redirecturl", method = RequestMethod.POST)
    public ModelAndView methodPost() {
            return new ModelAndView( "redirect:/login.html");

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM