spring data mongodb怎么实现引用关系
2016-09-02
展开全部
Student(学生实体)
@Document(collection="student")
public class Student {
@Id
private String studentId;
@Indexed(unique=true)
private String studentName;
private int age;
@DBRef
private List<Course> courses;
//setter,getter方法略
}
Course课程实体
@Document(collection="course")
public class Course {
@Id
private String courseId;
@Indexed(unique=true)
private String courseName;
//setter,getter
@Document(collection="student")
public class Student {
@Id
private String studentId;
@Indexed(unique=true)
private String studentName;
private int age;
@DBRef
private List<Course> courses;
//setter,getter方法略
}
Course课程实体
@Document(collection="course")
public class Course {
@Id
private String courseId;
@Indexed(unique=true)
private String courseName;
//setter,getter
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询