天天看點

Spring Boot項目 restful接口 跳轉處理

方案一: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​​

方案二: 某網友回複 "restful的傳回值作為json格式傳回,應該沒有直接跳轉的。你前台擷取到傳回的結果,根據結果再用js跳轉"

問下關于RESTFUL的頁面跳轉

繼續閱讀