springboot后台代码如何跳转外部链接呢?
下文笔者讲述SpringBoot中跳转外部链接的方法及示例分享,如下所示
SpringBoot跳转外部链接的实现思路
在SpringBoot后台 方式1: 返回new ModelAndView("redirect:http://www.java265.com") 即可实现跳转 方式2: response.sendRedirect("http://www.java265.com"); 方式3: return "redirect:http://www.java265.com";例:SpringBoot跳转外部链接的示例
1.使用ModelAndView
@RequestMapping("redirect")
public ModelAndView redirect(){
return new ModelAndView("redirect:http://www.java265.com");
}
2.使用SpringMVC
@RequestMapping("redirect2")
public String redirect(){
return "redirect:http://www.java265.com";
}
3.使用HttpServletResponse
@RequestMapping("/send")
public void sendInfoToWeiXin(HttpServletResponse response){
try {
response.sendRedirect("http://www.java265.com");
} catch (IOException e) {
e.printStackTrace();
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


