问题描述
如何将多个实体从客户端传递到Google Cloud Endpoint?
How can I pass more than one Entity from a client to a Google Cloud Endpoint?
例如,在服务器中的Endpoint api源文件中轻松地传递单个实体:
For example, passing a single Entity is easily done in an Endpoint api source file in the server:
public class SomeEndpoint {
...
@ApiMethod(...)
public MyEntity someMethod(MyEntity someEntity) {
...
}
...
}
然后在我可以轻松致电给客户的客户中
then in a client I could easily call
endpoint.someMethod(someEntity).execute()
但是,如果我想将两个实体传递给端点怎么办?
But, what if I want to pass two entities to an endpoint?, like this:
@ApiMethod(...)
public MyEntity otherMethod(MyEntity someEntity, MyEntity someOtherEntity) {
...
}
这不起作用,GPE仅使用单个MyEntity参数生成一个端点库.
this doesn't work, GPE only generates an endpoint library with a single MyEntity argument.
是否可以传递多个Entity参数?
Is it possible to pass multiple Entity arguments?
谢谢.
推荐答案
您不能在请求的正文中发送多个实体类型.您需要创建一个包含这两个实体的包装器实体,例如:
You can't send multiple entity types in the body of your request. You'll need to create a wrapper entity that contains those two entities, e.g.:
class MyWrapperEntity {
MyEntity someEntity;
MyOtherEntity someOtherEntity;
// ...
}
但是,那不是您的示例所显示的(实体是同一类型).在集合实体内部使用List<MyEntity>
或Map<String, MyEntity>
代替,例如:
However, that's not what your example shows (the entities are the same type). Use a List<MyEntity>
or Map<String, MyEntity>
inside of a collection entity instead, e.g.:
class MyEntityCollection {
List<MyEntity> items;
// ...
}
这篇关于Google Cloud Endpoints中的多个实体参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!