【发布时间】:2013-12-07 11:58:45
【问题描述】:
我正在尝试开发示例 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 所有可选参数。
但是我不知道如何在客户端使用 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();
通常,当参数不可为空时,我会将它们传递给 endpoint.listPlace() 方法。但是当参数可以为空时,客户端应用程序看不到可以接受参数的替代构造函数。
那我应该如何通过它们呢?
【问题讨论】:
标签: android google-app-engine google-cloud-endpoints