如何在ModelAndView中使用重定向 [英] How to use Redirect in ModelAndView

查看:942
本文介绍了如何在ModelAndView中使用重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已经定义了header.jsp并将其包含在我的所有页面中.当我单击其他任何位置的home链接时,请从当前url添加/home.因此它显示404错误.

I have Define header.jsp and Include it in all my Pages.When I click home link from anywhere else url add /home from current url.So it shows 404 error.

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

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

How can I use redirect:/ in ModelAndView return type method???

推荐答案

要在ModelAndView返回类型方法中使用redirect:/,请尝试遵循

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;

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

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

这篇关于如何在ModelAndView中使用重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆