如何在spring boot中查询关系?

如何在spring boot中查询关系?,spring,laravel,spring-boot,spring-data-jpa,Spring,Laravel,Spring Boot,Spring Data Jpa,我想找一个年龄超过18岁的学生当老师 我曾与Laravel framework合作,通过以下方式实现: $AdultStudents=$teacher->students->where('age'>18岁) 有没有一种方法可以在Spring Boot中不使用mysql查询来实现这一点?我的意思是使用JPA存储库中的单个方法。让我们这样说: teacher.getStudents()是的,假设您有JPA Spring数据Repo,您可以通过将值作为方法参数传递来命名方法来构造查询 在Studend

我想找一个年龄超过18岁的学生当老师

我曾与Laravel framework合作,通过以下方式实现:

$AdultStudents=$teacher->students->where('age'>18岁)

有没有一种方法可以在Spring Boot中不使用mysql查询来实现这一点?我的意思是使用JPA存储库中的单个方法。让我们这样说:


teacher.getStudents()

是的,假设您有JPA Spring数据Repo,您可以通过将值作为方法参数传递来命名方法来构造查询

在Studends DAO内的示例中,假设
Student
具有
age
属性,则方法名为:

findByAgeGreaterThan(Integer age)

是的,假设您有JPA Spring数据Repo,您可以通过将值作为方法参数传递来命名方法来构造查询

在Studends DAO内的示例中,假设
Student
具有
age
属性,则方法名为:

findByAgeGreaterThan(Integer age)

谢谢,所以要为教师检索,应该是这样的:
findbytacherandagegreaterthan(整数id,整数年龄)
无法使用关系
teacher.getStudents()
?假设您为
Student
定义了一个实体,并为此定义了一个JPA存储库,那么您可以使用签名
List findbytacheriandagegreater(长id,整数年龄)
构造一个方法。除非您想在业务逻辑中进行过滤,否则该特定getter在这里对您没有帮助。谢谢,因此,为了为教师检索该getter,它应该是这样的:
findbytacherandagegreaterthan(Integer id,Integer age)
无法使用关系
teacher.getStudents()
?假设您为
Student
定义了一个实体,并为此定义了一个JPA存储库,那么您可以使用签名
List findbytacheriandagegreater(长id,整数年龄)
构造一个方法。除非您想在业务逻辑中进行过滤,否则特定的getter在这里对您没有帮助。