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
参数添加到您的 Handler Method 然后调用 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屋!
查看全文