我想找一个年龄大于18岁的老师作为学生。
我曾经使用Laravel框架,通过以下方式可以做到这一点:
$AdultStudents = $teacher->students->where('age'>18);
有没有办法在不使用mysql查询的情况下在Spring Boot中做到这一点?我的意思是使用JPA存储库中的一种方法。让我们这样说:
teacher.getStudents().whereAgeGreaterThan(18);
是的,假设您拥有JPA Spring Data Repo,则可以按照Spring Data查询方法规则通过将值作为方法参数传递的方式,通过命名方法来构造查询。
在您的Studends DAO内部的示例中,假设Student
拥有一个age
名为方法的属性:
findByAgeGreaterThan(Integer age)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句