【问题标题】:Retrieving the Property from the Kind using Entity class in google cloud data store?使用谷歌云数据存储中的实体类从种类中检索属性?
【发布时间】:2017-06-20 13:50:34
【问题描述】:

谁能解释一下,我怎样才能在谷歌数据存储中获取单个行的属性,这是我的代码

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;
    }
}

在if条件下,我需要检查从数据库(密码)获取的值,参数传递(pass),如何从数据库中检索密码?

Kind(表名) -> databasecont,

properities(columns) -> 名称,密码,

键(主键)-> 名称

【问题讨论】:

    标签: java google-app-engine servlets google-cloud-datastore


    【解决方案1】:

    你会做类似的事情 -

    String password = (String) entity.getProperty("password"); 
    
    //The above assumes that the name of the property in the Datastore is "password". 
    

    您可以参考 API 文档here

    【讨论】:

    • 谢谢,它正在工作。我尝试使用 Map<String, Object> map = userHaveAccount.getProperties(); String dbvalue = (String) map.get("password"); ,它用于检索所有属性。再次感谢您的回复,对我来说太有用了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2018-02-20
    • 1970-01-01
    • 2022-01-26
    相关资源
    最近更新 更多