【发布时间】:2015-04-02 08:08:21
【问题描述】:
第一个方法是谷歌端点示例中的原始方法,它返回一个值
第二种方法是我的,它返回null
我不确定,是否可以返回列表?
【问题讨论】:
标签: java google-app-engine google-cloud-endpoints
第一个方法是谷歌端点示例中的原始方法,它返回一个值
第二种方法是我的,它返回null
我不确定,是否可以返回列表?
【问题讨论】:
标签: java google-app-engine google-cloud-endpoints
您可以返回集合(集合、列表等),如 the official docs 所述。建议使用 com.google.api.server.spi.response.CollectionResponse 因为它带来了一些内置的好处,比如分页。
例如
@ApiMethod(name = "getAllTopics", path= "getAllTopics")
public CollectionResponse<Topic> listEvent(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
List<Topic> execute = //fetch from datastore
return CollectionResponse.<Topic> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
【讨论】: