我有一个实体课程和另一个学生。一个学生可以选修多种课程。以下是学生和课程的样本结构
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
...
...
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "students_courses", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "course_id"))
private Collection<course> courses;
...
...
}
@Entity
@Table(name="course")
public class Course {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Long id;
Controller
@GetMapping("/student/{studentId}")
public Student findById(@PathVariable int studentId){
Student theStudent = employeeService.findById(studentId);
if(theEmployee==null) {
throw new RuntimeException("Student id not found - " + studentId);
}
return theStudent ;
}
基于上述实体,我如何才能创建一个主-明细表,如下所示。
谢谢和问候,希耶什
暂无答案!
目前还没有任何答案,快来回答吧!