Reputation: 643
For example a user repository,
interface PersonRepository extends Repository<User, Long> {
List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);
}
Is there a way to achieve findByEmailAddressAndLastname(null, "lastname")
= findByLastname("lastname")
, because after I add more parameters in user entity, the number of method name query increase exponentially. I want to reduce the redundancy.
Thanks.
Upvotes: 1
Views: 658
Reputation: 503
Since spring-data-jpa 2 you can use @Nullable annotation:
List<Person> findByEmailAddressAndLastname(@Nullable EmailAddress emailAddress, String lastname);
Check nullability annotations to see all the variants
Upvotes: 1