Google Cloud Endpoints返回List

时间:2015-04-02 08:08:22

标签: java google-app-engine google-cloud-endpoints

enter image description here

第一种方法是来自Google端点示例的原始方法,它返回一个值

第二种方法是我的,它返回null

我不确定,是否可以返回List?

1 个答案:

答案 0 :(得分:4)

可以按照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();
    }
相关问题