2015-04-02 72 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(); 
    }