0


SpringBoot 重定向方式 汇总

参考博客:https://blog.csdn.net/lianghecai52171314/article/details/102576175

Springboot中重定向可以通过以下三种方式实现:

1. 在返回值中加上重定向代码:

redirect:要访问的网址

;

publicStringfun(){//"redirect:要访问的相对网址或绝对网址?参数名="+参数值;return"redirect:要访问的相对网址或绝对网址?参数名="+参数值;}

2. 用modelAndView对象来进行,和上一中方法类似,仅可以跳转项目内页面。

publicModelAndViewfun(){ModelAndView modelAndView =newModelAndView(需要跳转的页面路径);return modelAndView;}

3. 使用response的重定向功能

publicvoidfun(HttpServletResponse response)throwsException{
    response.sendRedirect("https://www.baidu.com");}

注意:此方法可以跳转外网url

标签: 重定向

本文转载自: https://blog.csdn.net/lianghecai52171314/article/details/130228453
版权归原作者 梁云亮 所有, 如有侵权,请联系我们删除。

“SpringBoot 重定向方式 汇总”的评论:

还没有评论