我更喜欢将键和值分开,否则传递
DataSnapshots。但是,如果您愿意,还可以提取键(
DataSnapshot.getKey())并将其设置在您的Java类中的以下属性上
@Exclude:
public class Student { @Exclude public String key; public String name; public String age;}然后:
Student newStudent = snapshot.getValue(Student.class);newStudent.key = snapshot.getKey();



