动态更改RESTEasy服务返回类型

发布于 2024-09-24 22:22:57 字数 114 浏览 0 评论 0原文

我可以在 RESTEasy 服务中更改 @Produces 注释参数的值吗?
我的任务是将多种格式的报告集成到现有的报告系统中。 因此动态更改@Produces注释参数会对我有很大帮助。
提前致谢!

Am I able to change the value of @Produces annotation parameter in my RESTEasy services??
The task I'm given is to integrate multiple format reporting to an existing reporting system.
So changing the @Produces annotation parameter dynamically would help me a lot.
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2024-10-01 22:22:57

让你的方法返回一个 Response 对象并尝试这样的事情;

int status = 200;
String type = MediaType.APPLICATION_XML;
String response = "<hello>world</hello>";
return Response.status(status).type(type).entity(response).build();

我认为响应中的类型将覆盖您注释的内容,但我还没有测试过。

Make your method return a Response object and try something like this;

int status = 200;
String type = MediaType.APPLICATION_XML;
String response = "<hello>world</hello>";
return Response.status(status).type(type).entity(response).build();

I think the type in the response will override what you annotated, but I haven't tested it.

江湖正好 2024-10-01 22:22:57

您可以在@Produces 中指定多个条目。您的请求应提及您想要哪种格式(如 mime 类型)作为结果。

例子:

@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })

You can specify several entries in @Produces. Your request should mention which format (as mime type) do you want as the result.

Example:

@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文