JAVA后端重定向
目录
JAVA后端重定向
JAVA后端重定向页面的几种方式
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");
}
备注:只供自己学习参考使用