@Controller
public class TestController {
…
}
1、使用ModelAndView
@RequestMapping("redirect")
public ModelAndView redirect(){
return new ModelAndView("redirect:http://www.baidu.com");
}
2、使用SpringMVC
@RequestMapping("redirect2")
public String redirect(){
return"redirect:http://www.baidu.com";
}
3、使用HttpServletResponse
@RequestMapping("/send")
public void sendInfoToWeiXin(HttpServletResponse response){
try {
response.sendRedirect("http://www.baidu.com");
} catch (IOException e) {
e.printStackTrace();
}
}