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