Anil :
I have a JPA method that finds list of Students by their graduation status.
List<Student> findAllByStatus(Status status);
But if the request is made with null Status, I want to retrieve entities with null status.
How can I handle this with JPARepository using only one method query, to achieve no filtering by status if the status is null?
Thanks in advance.
Raniere :
You should use something like:
@Query("SELECT s from Student s WHERE (?1 is null or s.status = ?1)")
List<Student> findAllByStatus(Status status);
Just a little fix to Ankit Kanani answer.