第一个方法是来自Google端点示例的原始方法,它返回一个值
第二种方法是我的,返回null
我不确定,是否可以返回 List?
最佳答案
您可以按照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();
}
关于java - Google Cloud Endpoints 返回列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407997/