我正试图在spring boot上编写一个自定义查询。但我面临着这个错误。如何解决此问题。我的数据库中有三个表。学生、老师和班级。我想把班上所有的学生都叫来。还有全班的老师。我正在尝试编写自定义联接查询。问题在哪里?我也面临着这些问题:
第1:113行:意外标记:类第1:119行:意外标记:类id
这是我的模型:
学生:
@Entity
public class Student {
@Id
private int s_id;
@NotNull
private String s_name;
@NotNull
private Date admission_date;
@ManyToOne
private Class class_id;
public Student(String s_name) {
this.s_name = s_name;
}
public int getS_id() {
return s_id;
}
public void setS_id(int s_id) {
this.s_id = s_id;
}
public String getS_name() {
return s_name;
}
public void setS_name(String s_name) {
this.s_name = s_name;
}
public Date getAdmission_date() {
return admission_date;
}
public void setAdmission_date(Date admission_date) {
this.admission_date = admission_date;
}
public Class getClass_id() {
return class_id;
}
public void setClass_id(Class class_id) {
this.class_id = class_id;
}
}
老师:
@Entity
public class Teacher {
@Id
private int t_id;
@NotNull
private String t_name;
public Teacher(String t_name) {
super();
this.t_name = t_name;
}
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable
private Set<Class> classes;
public int getT_id() {
return t_id;
}
public void setT_id(int t_id) {
this.t_id = t_id;
}
public String getT_name() {
return t_name;
}
public void setT_name(String t_name) {
this.t_name = t_name;
}
public Set<Class> getClasses() {
return classes;
}
public void setClasses(Set<Class> classes) {
this.classes = classes;
}
}
类别:
@Entity
public class Class {
@Id
private int class_id;
@NotNull
private String class_name;
@NotNull
private String course_name;
@ManyToMany(mappedBy = "classes")
private Set<Teacher> teachers;
public int getClass_id() {
return class_id;
}
public void setClass_id(int class_id) {
this.class_id = class_id;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
public String getCourse_name() {
return course_name;
}
public void setCourse_name(String course_name) {
this.course_name = course_name;
}
public Set<Teacher> getTeachers() {
return teachers;
}
public void setTeachers(Set<Teacher> teachers) {
this.teachers = teachers;
}
}
研究假设:
@Repository
public interface StudentRepository extends JpaRepository<Student,Integer> {
@Query("from Student as s Join Class on s.class_id = Class.class_id where Class.class_id
=id")
public List<Student> getStudent(@Param("id") int id);
}
教师资源库:
public interface TeacherRepository extends JpaRepository<Teacher,Integer> {
@Query(" t.t_name from Teacher as t inner join teacher_classes as tc on (tc.t_id = t.t_id)
inner join Class as c on (c.class_id = tc.class_id) where c.id = id")
public List<Teacher> getTeacher(@Param("id") int id);
}
2条答案
按热度按时间yruzcnhs1#
该本机查询存在一些问题,这就是为什么会出现令牌问题。重写如下。
idfiyjo82#
看起来你忘了带冒号。请尝试以下查询
我将重命名findstudentsbyclassid和FindTeacherByClassID中的方法