i'm using spring data jpa, and have a query to search text from the whole columns.
for example:
repository.findByNameContainingOrAliasContaining(name, alias, pageable)
And the name and alias are the same value, and i have to write like
string name = text; string alias = text;
repository.findByNameContainingOrAliasContaining(name, alias, pageable)
and actually, i have 5 columns to be matched, so how can i stop writing the same stupid code ?
and make the code like: repository.findByNameContainingOrAliasContaining(text, pageable)
(this writing now will cause ".NoSuchElementException")
When you face a limitation of implicit queries, you can always switch to explicit @Query
:
@Query("select f from Foo f where f.name like %?1% or f.alias like %?1% or ...")
public List<Foo> findByAnyColumnContaining(String text, Pageable pageable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With