例如当前test库中的grade集合中有两条文档数据,如下图所示:
相关的两个实体映射类如下:
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
@Data
@Document(value = "grade")
public class Grade {
@Id
private Integer id;
@Field(value = "grade_name")
private String gradeName;
@Field(value = "students")
private List<Student> students;
}
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Field;
@Data
public class Student {
@Field(value = "student_id")
private int studentId;
@Field(value