转自:https://www.cnblogs.com/EasonJim/p/7459486.html
Spring MVC项目中页面重定向一般使用return "redirect:/other/controller/";即可。而Spring Boot使用了@RestController注解,上述写法只能返回字符串,解决方法如下:
将一个HttpServletResponse参数添加到处理程序方法然后调用response.sendRedirect("some-url");
@RestController public class FooController { @RequestMapping("/foo") void handleFoo(HttpServletResponse response) throws IOException { response.sendRedirect("some-url"); } }
参考:
https://stackoverflow.com/questions/29085295/spring-mvc-restcontroller-and-redirect
本文介绍在SpringBoot项目中如何实现页面重定向。由于使用@RestController注解导致无法直接使用传统的redirect方式,文中提供了一种解决方案,即通过添加HttpServletResponse参数到处理程序方法并调用sendRedirect方法来实现。

1088





