如何为我的领域对象设置标识符?

时间:2015-12-22 03:51:08

标签: java android realm

如何设置我的领域对象的标识符..我需要在我的Android应用程序的第二个活动中使用它进行查询。感谢。

学校对象:

public class School extends RealmObject {

@Required
private String SchoolID;
private String SchoolName;
private RealmList<Student> Students;


getters/setters

public RealmList<Student> getStudents() {
    return Students;
}

public void setStudents(RealmList<Student> students) {
    Students = students;
}

学生对象:

public class Student extends RealmObject{

@Required
private String StudentID;
private String StudentName;

getters/setters

}

1 个答案:

答案 0 :(得分:0)

您可以使用@PrimaryKeyhttps://realm.io/docs/java/latest/#primary-keys

public class Student extends RealmObject {

@PrimaryKey
private String StudentID;
private String StudentName;

// getters/setters

}