How should I build my findBy method name so I can implement a where clause -
statusCode != 'Denied'
Is this be an option?
findByStatusCodeNotIn(List<String> statusCode);
What if I want to just pass a String instead of a list?
Thank You
How should I build my findBy method name so I can implement a where clause -
statusCode != 'Denied'
Is this be an option?
findByStatusCodeNotIn(List<String> statusCode);
What if I want to just pass a String instead of a list?
Thank You
Have you taken a look at the documentation about this in the Spring Data JPA
docs?
#findByStatusCodeNot(String statusCode);
It's akin the example in the docs like:
#findByLastnameNot
According to the Spring Data JPA Documentation on https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference
you can achieve this by using the "Not" keyword. forinstance your method would be
findByStatusCodeNot(String statusCode);
This means to achieve "statusCode != 'Denied'", you would call the method as
findByStatusCodeNot('Denied');
@Dovmo is right, but also keep in mind that if you are operating on String
data, you may have to take case into account, i.e. findByStatusCodeNot(String statusCode)
will find only records that are not 'Denied'
as is, but not for instance 'DeniEd'
. For case-insensitive searches, you can append IgnoreCase
- findByStatusCodeNotIgnoreCase(String statusCode)
In general, please follow the link that @Dovmo gave.
According to the spring JPA repository docs we can use the <> symbol in place of !=
so the query would be
statusCode <> 'Denied'
this would be helpful if you want to write a @Query instead of the inbuild repository methods.