Java – spring data repositories – find the where field in the list
I am trying to use spring pagingandsortingrepository and find myentity, where the fields in fieldvalues are queried as follows:
@Repository public interface MyEntity extends PagingAndSortingRepository<MyEntity,String> { List<MyEntity> findByMyField(Set<String> myField); }
But it didn't succeed
I want the above function to return all entities whose fields match one of the field values, but it only returns null results
Even if it looks like a very direct capability, I can't find any reference to it in docs
Yes / how?
thank you.
Solution
This is indeed possible if you are searching for a specific field in an entity and want to return a list of all that field, and at least one entry in a collection matches The document here says that this can be implemented in, for example, findbyagein (collection < age > ages) using keywords, and is equivalent to... Where x.age in? one
From your post, I'm not 100% sure this is the use case you're using, but try it You need to search for a specific field, so replace "field" with the field you want to search If you want to search for multiple fields, you can connect the result to the or keyword and specify multiple fields in this way
@Repository public interface MyEntity extends PagingAndSortingRepository<MyEntity,String> { List<MyEntity> findByFieldIn(Set<String> myField); }