本文介绍了返回ModelAndView之前可以设置url吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在返回模型之前设置您的网址?
is it possible to set your url before returning your model?
例如,我当前的网址是 http://localhost/home.html 在我的家用控制器上,我返回了另一个页面的模型和视图,例如
For example, my current url is http://localhost/home.htmlat my homecontroller, I return a modelandview for another page, for example
ModelAndView model = new ModelAndView("contact");
model.addObject("contactNo", "12345");
return model;
然后,在返回模型后,我的contact.jsp已加载到浏览器中,但其URL仍然是 http://localhost /home.html ,我想将其更改为 http://localhost/contact.html ,我该怎么做?
then after returning the model, my contact.jsp has been loaded to my browser but it's url is still http://localhost/home.html, I want to change it to http://localhost/contact.html,how can i able to do that?
谢谢
推荐答案
尝试像这样实例化ModelAndView
,
ModelAndView model = new ModelAndView(new RedirectView("contact"));
这篇关于返回ModelAndView之前可以设置url吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!