1.使用 ModelAndView

@GetMapping("/demo1")
    public ModelAndView demo1(){
        String url = "redirect:https://www.cctv.com";
        return new ModelAndView(url);
    }

2.通过 redirect 返回 string 类型跳转

 @GetMapping("/demo2")
    public String demo2(){
        return "redirect:https://www.baidu.com";
    }

3.使用状态码 302 跳转

  @GetMapping("/demo3")
   public void demo3(HttpServletResponse response){
        response.setStatus(302);
        response.setHeader("location","https://www.bilibili.com");
   }

备注:只供自己学习参考使用

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐