如何将多个实体从客户端传递到Google Cloud endpoints ?
例如,在服务器的Endpoint api源文件中轻松完成传递单个实体:
public class SomeEndpoint {
...
@ApiMethod(...)
public MyEntity someMethod(MyEntity someEntity) {
...
}
...
}
然后在客户端我可以轻松打电话
endpoint.someMethod(someEntity).execute()
但是,如果我想将两个实体传递给 endpoints 怎么办?,如下所示:
@ApiMethod(...)
public MyEntity otherMethod(MyEntity someEntity, MyEntity someOtherEntity) {
...
}
这不起作用,GPE只生成一个带有单个MyEntity参数的 endpoints 库 .
是否可以传递多个Entity参数?
谢谢 .
2 回答
您不能在请求正文中发送多个实体类型 . 您需要创建一个包含这两个实体的包装器实体,例如:
但是,这不是您的示例所示(实体是相同的类型) . 在集合实体中使用
List<MyEntity>
或Map<String, MyEntity>
,例如:使用'named'注释...
对于Android,客户端代码看起来像这样