2015-04-02 142 views
1

enter image description here谷歌云终点返回列表

第一种方法是从谷歌端点样品原来的方法,它返回一个值

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

我不是当然,是否有可能返回列表?

回答

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(); 
    }