SpringBoot项目@RestController使用 redirect 重定向无效

Spring MVC项目中页面重定向一般使用return "redirect:/other/controller/";即可。

而Spring Boot当我们使用了@RestController注解,上述写法只能返回字符串,解决方法如下:

@RestController
public class LoginController {

  @RequestMapping("/logout")
  void handleLogout(HttpServletResponse response) throws IOException {
    response.sendRedirect("some-url");
  }
}
原文地址:https://www.cnblogs.com/coder-lzh/p/10711864.html