【问题标题】:Google Cloud Endpoints return ListGoogle Cloud Endpoints 返回列表
【发布时间】:2015-04-02 08:08:21
【问题描述】:

第一个方法是谷歌端点示例中的原始方法,它返回一个值

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

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

【问题讨论】:

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


    【解决方案1】:

    可以返回集合(集合、列表等),如 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();
        }
    

    【讨论】:

      猜你喜欢
      • 2013-12-13
      • 2016-10-01
      • 2016-05-18
      • 1970-01-01
      • 2018-12-18
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多