Reputation: 1935
I want to get students for a teacher where the student's age is larger than 18.
I used to work with Laravel framework, where I was able to do this by:
$AdultStudents = $teacher->students->where('age'>18);
Is there a way to do this in Spring Boot without using the mysql query? I mean using a single method from JPA Repository. Let us say something like this:
teacher.getStudents().whereAgeGreaterThan(18);
Upvotes: 0
Views: 469
Reputation: 21391
Yes, supposing you have your JPA Spring Data Repo you can construct the query by naming method as per the Spring Data query method rules passing the value as a method parameter.
In your example inside the Studends DAO supposing the Student
has an age
attribute a method named:
findByAgeGreaterThan(Integer age)
Upvotes: 2