springboot后台代码如何跳转外部链接呢?

欣喜 SpringBoot 发布时间:2025-03-26 09:48:20 阅读数:10533 1
下文笔者讲述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();
    }
}
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaFramework/SpringBoot/202503/8408.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者