下面三个方法均在该类中:


@Controller
public class TestController {
    ......
}

AI写代码
java
运行
1
2
3
4
1、使用ModelAndView


  @RequestMapping("redirect")
    public ModelAndView redirect(){
        return new ModelAndView("redirect:http://www.baidu.com");
    }

AI写代码
java
运行
1
2
3
4
2、使用SpringMVC


  @RequestMapping("redirect2")
    public String redirect(){
        return"redirect:http://www.baidu.com";
    }

AI写代码
java
运行
1
2
3
4
3、使用HttpServletResponse


   @RequestMapping("/send")
    public void sendInfoToWeiXin(HttpServletResponse response){
        try {
            response.sendRedirect("http://www.baidu.com");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
文档更新时间: 2025-07-13 07:57   作者:admin