Java 如何从firestore中的文档中获取特定数据并将其传递给android中的局部变量
我希望将存储在firestore文档中的模型中的数据获取到局部变量 这是我的员工模型。类Java 如何从firestore中的文档中获取特定数据并将其传递给android中的局部变量,java,android,google-cloud-firestore,Java,Android,Google Cloud Firestore,我希望将存储在firestore文档中的模型中的数据获取到局部变量 这是我的员工模型。类 还有我的Firestore截图,请帮忙!谢谢您缺少的是从文档中获取模型 if(documentSnapshot.exists()){ EmployeeModel model = documentSnapshot.toObject(EmployeeModel.class); // 只需将if语句后的一行添加到现有代码中,其余的就可以了。请将您的数据库结构添加为屏幕截图,并添加Employee
还有我的Firestore截图,请帮忙!谢谢您缺少的是从文档中获取模型
if(documentSnapshot.exists()){
EmployeeModel model = documentSnapshot.toObject(EmployeeModel.class);
//
只需将
if语句
后的一行添加到现有代码中,其余的就可以了。请将您的数据库结构添加为屏幕截图,并添加EmployeeModel
类的内容。如果这样做有效,请接受答案并向上投票itString username=model.getUsername();
public class EmployeeModel {
public static final String MFIELD_USERNAME = "username";
public static final String MFIELD_EMAIL = "email";
public static final String MFIELD_PASSWORD = "password";
public static final String MFIELD_LOCATION = "location";
public static final String MFIELD_PHONENUMBER = "phonenumber";
public static final String MFIELD_GENDER = "gender";
public static final String MFIELD_TYPE = "type";
private String username;
private String email;
private String password;
private String location;
private String phonenumber;
private String gender;
private String type;
private @ServerTimestamp Date timestamp;
public EmployeeModel() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public EmployeeModel(String username, String email, String password, String location, String phonenumber, String gender, String type, Date timestamp) {
this.username = username;
this.email = email;
this.password = password;
this.location = location;
this.phonenumber = phonenumber;
this.gender = gender;
this.type = type;
this.timestamp = timestamp;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}}
if(documentSnapshot.exists()){
EmployeeModel model = documentSnapshot.toObject(EmployeeModel.class);
//