0

使用 Restful 服务器模块,我执行以下操作:

GET /api/v1/(ClassName)?(Field)=(Val)&(Field)=(Val)- 搜索匹配的数据库记录

api 应该像这样获取与某个产品相关的所有图像的 url: http ://domain.com/api/v1/Product?ArticleID=myID

不幸的是,返回的 XML 没有显示 ProductImages 的完整信息。只是属性href和id。这里的xml:

<?xml version="1.0" encoding="UTF-8"?>
<ArrayList totalSize="1">
<Product href="http://domain.com/api/v1/Product/9.xml">
<ArticleID>myID</ArticleID>
<ID>9</ID>
<ProductImages linktype="has_many" href="http://domain.com/api/v1/Product/9/ProductImages.xml">
<ProductImage href="http://domain.com/api/v1/ProductImage/265.xml" id="265"/>
<ProductImage href="http://domain.com/api/v1/ProductImage/268.xml" id="268"/>
<ProductImage href="http://domain.com/api/v1/ProductImage/271.xml" id="271"/>
</ProductImages>
</Product>
</ArrayList>

ProductImage 实际上有更多的属性,这些属性没有显示在 xml 中。如何使它们可见?执行此操作时,我可以看到所有 ProductImage 属性:http: //domain.com/api/v1/Product/9/ProductImages

我使用 curl 加载网址。在最坏的情况下,我认为我必须从 XML 中获取 ProductImage url(例如http://domain.com/api/v1/ProductImage/271.xml)并进行多次调用。

非常感谢任何帮助,弗洛里安

4

1 回答 1

0

你需要增加relationDepth里面RestfulServer。您可以通过传入relationdepth查询字符串参数来做到这一点。

顺便说一句,它这样工作的原因是通过不必实例化所有图像对象来保持服务器上的低负载。这也意味着带宽也略低。

于 2013-06-18T16:30:33.703 回答