这是使用GAE中的持久性设置和获取字符串值的正确方法吗?

时间:2012-02-22 21:57:42

标签: java google-app-engine

这是使用GAE中的持久性来设置和获取字符串值的正确方法吗?

我收到错误:

com.google.appengine.api.datastore.EntityNotFoundException: No entity was found matching the key: jsonString("jsonString")

添加到商店:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

Key key = KeyFactory.createKey("jsonString", "jsonString");
Entity urlEntity = new Entity("jsonString" , key);
urlEntity.setProperty("urlVal", urlVal);

com.google.appengine.api.datastore.Key urlEntityKey = datastore.put(urlEntity);  

从商店回来:

    Key key = KeyFactory.createKey("jsonString", "jsonString");
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    Entity entity = datastore.get(key);

1 个答案:

答案 0 :(得分:0)

请查看以下代码,您还可以查看文档here,找到有关如何使用应用引擎数据存储API的更多详细信息。另请查看Datastore Overview文档中的说明。

DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity e = new Entity("data");
e.setProperty("jsonString", "myValue");
Key key = ds.put(e);
Entity entity = ds.get(key);
System .out.println(entity);