说我有这三个实体
@Entity
public class Student {
@Id
@Column
long studentId;
@Column
String name;
}
@Entity
public class Exam{
@Id
@Column
long examId;
}
@Entity
public class StudentExam {
@Id
@Column
long studentExamId;
@ManyToOne
@JoinColumn("student_id")
Student student;
@ManyToOne
@JoinColumn("exam_id")
Exam exam;
@Column
int score;
}
我有这个pojo课
public class StudentExamDTO {
ExamDTO exam;
StudentDTO student;
int bestScore;
}
其中ExamDTO和StudentDTO是简单的非实体模型。最高分数是学生在给定考试中获得的最高分数。
我想要的是一个简单的请求,可以使用Spring-Boot存储库接口直接返回ExamStudentDTO
public interface ExamRepository extends JpaRepository<ExamStudent, Long> {
@Query("select new StudentExam(...) ..")
Object getStudentExam(@Param("examId")long examId, @Param("studentId")long studentId);
}
有没有办法像Object [“ column”]那样访问数据?如果是这样,是否可以直接在StudentExamDTO类上获取结果?