Java 在google cloud data store中使用实体类从种类检索属性?
有谁能解释一下,我如何在谷歌数据存储中获取单个行的属性,这是我的代码Java 在google cloud data store中使用实体类从种类检索属性?,java,google-app-engine,servlets,google-cloud-datastore,Java,Google App Engine,Servlets,Google Cloud Datastore,有谁能解释一下,我如何在谷歌数据存储中获取单个行的属性,这是我的代码 public Entity useravailable(String name, String pass) { DatastoreService entityStore = DatastoreServiceFactory.getDatastoreService(); Key k = KeyFactory.createKey("databasecont", name); try { Entit
public Entity useravailable(String name, String pass) {
DatastoreService entityStore = DatastoreServiceFactory.getDatastoreService();
Key k = KeyFactory.createKey("databasecont", name);
try {
Entity user = entityStore.get(k);
System.out.println("password of user in db"+userHaveAccount);
if ("password".equals(password)) // Here check the database password with the password("passed as argument to this function")
return userHaveAccount;
else
return null;
}
catch (EntityNotFoundException e1) {
return null;
}
}
在这种情况下,如果我需要在参数已传递(pass)的情况下检查从数据库获取的值(password),如何从数据库检索密码
种类(表名)->databasecont
属性(列)->名称、密码、
key(主键)->name您可以执行以下操作-
String password = (String) entity.getProperty("password");
//The above assumes that the name of the property in the Datastore is "password".
您可以参考API文档 谢谢,它正在工作。我尝试了
Map Map=userHaveAccount.getProperties();String dbvalue=(String)map.get(“密码”)代码>,用于检索所有属性。再次感谢您的回复,这对我来说太有用了