Spring MVC @RestController并重定向 [英] Spring MVC @RestController and redirect
本文介绍了Spring MVC @RestController并重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用Spring MVC @RestController实现的REST端点.有时,取决于我控制器中的输入参数,我需要在客户端上发送http重定向.
I have a REST endpoint implemented with Spring MVC @RestController. Sometime, depends on input parameters in my controller I need to send http redirect on client.
Spring MVC @RestController是否有可能,如果可以,请举个例子吗?
Is it possible with Spring MVC @RestController and if so, could you please show an example ?
推荐答案
将HttpServletResponse
参数添加到处理程序方法中,然后调用response.sendRedirect("some-url");
Add an HttpServletResponse
parameter to your Handler Method then call response.sendRedirect("some-url");
类似的东西:
@RestController
public class FooController {
@RequestMapping("/foo")
void handleFoo(HttpServletResponse response) throws IOException {
response.sendRedirect("some-url");
}
}
这篇关于Spring MVC @RestController并重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文