I would like to write a like query in JpaRepository
but it is not returning anything :
LIKE \'%place%\'
-its not working.
LIKE
You can also implement the like queries using Spring Data JPA supported keyword "Containing".
List<Registration> findByPlaceContaining(String place);
You can have one alternative of using placeholders as:
@Query("Select c from Registration c where c.place LIKE %?1%")
List<Registration> findPlaceContainingKeywordAnywhere(String place);
For your case, you can directly use JPA methods. That is like bellow :
Containing: select ... like %:place%
List<Registration> findByPlaceContainingIgnoreCase(String place);
here, IgnoreCase will help you to search item with ignoring the case.
Using @Query in JPQL :
@Query("Select registration from Registration registration where
registration.place LIKE %?1%")
List<Registration> findByPlaceContainingIgnoreCase(String place);
Here are some related methods:
Like findByPlaceLike
… where x.place like ?1
StartingWith findByPlaceStartingWith
… where x.place like ?1 (parameter bound with appended %)
EndingWith findByPlaceEndingWith
… where x.place like ?1 (parameter bound with prepended %)
Containing findByPlaceContaining
… where x.place like ?1 (parameter bound wrapped in %)
More info , view this link , this link and this
Hope this will help you :)
answer exactly will be
-->` @Query("select u from Category u where u.categoryName like %:input%") List findAllByInput(@Param("input") String input);