我正在嘗試使用示例GAE/Android應用程序。有地方實體。@Nullable @在GAE/Android中的名稱示例
在生成PlaceEndpoint類有如下方法:
@ApiMethod(name = "listGame")
public CollectionResponse<Place> listPlace(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Game> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Place as Place");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Game>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Game obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Game> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
據我所知cursor
和limit
所有可選PARAMS。
但我無法弄清楚如何使用在客戶端Placeednpoint
類通過他們:
Placeendpoint.Builder builder = new Placeendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
builder = CloudEndpointUtils.updateBuilder(builder);
Placeendpoint endpoint = builder.build();
try {
CollectionResponsePlace placesResponse = endpoint.listPlace().execute();
} catch (Exception e) {
e.printStackTrace();
通常情況下,當PARAMS不可爲空我會通過他們endpoint.listPlace()方法。但是當params可以爲空時,客戶端應用程序不會看到替代構造函數,它會接受params。
我該怎麼通過它們呢?
那麼@Nullable參數是什麼?我可以刪除它嗎? –
我不確定基於java的後端,因爲我使用python。請使用java確認谷歌雲終端的示例代碼。無論您需要通過雲端點從Android發送什麼參數,都需要爲每個參數提供上述的setter方法,並在您的應用引擎後端處理它們。如果您在後端代碼中未使用任何變量,則可以嘗試刪除 –
就是這樣!謝了哥們! –