如何使用 Jersey JAX-RS 返回结果集?

发布于 2024-10-01 04:06:05 字数 260 浏览 1 评论 0原文

我正在运行查询以从数据库返回州、城市和邮政编码。我如何让 JAX-RS (泽西岛) 像这样返回这个;

<State>
   <City>
      <Zip></Zip>
   </City>
</State>

等等......

我是否需要构建一个与我的xml结构匹配的对象,然后将其传递给JAX-RS,或者JAX-RS可以根据结果集为我构建它吗?

I am running a query to return State, City, and Zip from my database. How do I get JAX-RS (Jersey) to return this like this;

<State>
   <City>
      <Zip></Zip>
   </City>
</State>

and so on......

Do I need to build an object that matches my xml structure, then pass that to JAX-RS, or can JAX-RS build it for me based on the resultset?

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

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

发布评论

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

评论(2

白鸥掠海 2024-10-08 04:06:05

不,Jersey 无法直接从 ResultSet 创建输出。那是因为它不知道数据应该如何表示。您必须编写一个类来保存结果。您可以在该类上使用 JAXB 注释来更好地控制 XML 的外观。

No, Jersey can't create the output directly from a ResultSet. That's because it has no idea how the data is supposed to be represented. You'll have to write a class to hold the results. You can use JAXB annotations on that class to provide greater control over how the XML looks.

霞映澄塘 2024-10-08 04:06:05

您可以在 JAX-RS 服务中使用 POJO。然后使用 JPA 将对象映射到数据库,并使用 JAXB 将它们映射到 XML。有关示例,请参阅:

You could use POJOs in your JAX-RS service. Then use JPA to map the objects to the database, and JAXB to map them to XML. For an example see:

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