Spring MVC @RestController 和重定向

2024-04-08

我有一个使用 Spring MVC @RestController 实现的 REST 端点。有时,取决于我的控制器中的输入参数,我需要在客户端上发送 http 重定向。

Spring MVC @RestController 是否可行?如果可以,您能举个例子吗?


Add an HttpServletResponse参数传递给您的处理程序方法,然后调用response.sendRedirect("some-url");

就像是:

@RestController
public class FooController {

  @RequestMapping("/foo")
  void handleFoo(HttpServletResponse response) throws IOException {
    response.sendRedirect("some-url");
  }

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring MVC @RestController 和重定向 的相关文章

随机推荐