springmvc在controller方法里面跳转外网的方法

1.return new ModelAndView(new RedirectView("https://www.baidu.com"));

2.return  "redirect:https://www.baidu.com/";

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring MVC提供了多种页面的方法,其中常用的有以下几种: 1. 使用String类型返回值:在Controller的处理方法中,返回一个字符串类型的视图名,Spring MVC会根据这个视图名自动查找对应的视图,然后返回给浏览器。例如: ```java @RequestMapping("/index") public String index() { return "index"; // 视图名为index } ``` 2. 使用ModelAndView类型返回值:在Controller的处理方法中,返回一个ModelAndView类型的对象,该对象包含要到的视图名以及要传递给视图的数据。Spring MVC会根据该对象中的视图名自动查找对应的视图,然后返回给浏览器。例如: ```java @RequestMapping("/index") public ModelAndView index() { ModelAndView mav = new ModelAndView("index"); // 视图名为index mav.addObject("message", "Hello, World!"); // 向视图中传递数据 return mav; } ``` 3. 使用重定向:在Controller的处理方法中,使用RedirectView或redirect:前缀来指定要到的URL。Spring MVC会将该URL返回给浏览器,然后浏览器会向该URL发起新的请求。例如: ```java @RequestMapping("/index") public String index() { return "redirect:/home"; // 使用重定向到/home } 或者 @RequestMapping("/index") public RedirectView index() { RedirectView redirectView = new RedirectView(); redirectView.setUrl("/home"); // 使用RedirectView到/home return redirectView; } ``` 4. 使用forward:在Controller的处理方法中,使用forward:前缀来指定要到的URL。Spring MVC会将该URL发给浏览器,然后浏览器会向该URL发起新的请求。例如: ```java @RequestMapping("/index") public String index() { return "forward:/home"; // 使用forward到/home } ``` 以上就是Spring MVC中常用的页面的方法

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值