gpt4 book ai didi

java - Spring : Could not determine type for: java. util.List

转载 作者:行者123 更新时间:2023-12-01 23:49:48 30 4
gpt4 key购买 nike

我有以下场景:我有一个 Student 类和 students 表。我有类(class)类(class)和类(class)表。每个学生和类(class)都有唯一的 ID。我想将一个列表放入学生类中,该列表由类(class) ID 映射。

我尝试了很多注释和关系,但没有成功

@Entity
@Table(name = "courses")
public class Course {

private long id;
private String name;

public Course() {

}

public Course(String name, int size) {
this.name = name;
this.size = size;
}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@Column(name = "name", nullable = false)
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}
@Entity
@Table(name = "students")
public class Student {

private long id;
private String name;
@OneToMany(cascade = CascadeType.ALL)
private List<Course> courses = new ArrayList<>();

public Student() {

}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@Column(name = "name", nullable = false)
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Course> getCourses() {
return courses;
}

public void setCourses(List<Course> courses) {
this.courses = courses;
}
}

你能帮我实现这个目标吗,因为我是 Spring 的新手

最佳答案

声明一对多关系时使用以下内容

@Column(name="course_id")
private Set<Course> courses;

关于java - Spring : Could not determine type for: java. util.List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58224041/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com