我的数据存储表名为 document,其结构如下:Key、Write Ops、ID/Name、html、name。样本数据为:
Key: aglub19hcHBfaWRyDgsSCGRvY3VtZW50GAEM
Write Ops:6
ID/Name:1
html:"<div>something</div>
name: "Untitled name"
其中前三列由 Google App Engine 创建。我使用以下代码从数据存储中获取实体:
int PAGE_SIZE = 20;
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery queryString = datastore.prepare(new Query("document"));
int rowCount = queryString.countEntities();
int offset = 0;
//fetch results from datastore based on offset and page size
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(PAGE_SIZE);
QueryResultList<Entity> results = queryString.asQueryResultList(fetchOptions .offset(offset));
当我尝试使用 .getKey() 方法从实体中检索 Key 列时,会出现问题。它不是从 Key 列返回随机字符串,而是返回 document("1)。有没有办法从结果数组中获取 Keys?