I am using Spring Data JPA with postgresql as data base.Want to search a pattern using user given keyword
@Query(value = "SELCET * FROM table_name WHERE column_name LIKE (CONCAT('%',:pattern,'%'))")
List<Class> findPattern(String pattern);
but :pattern is not replacing with pattern value
CodePudding user response:
You may try binding the entire LIKE
expression to a single placeholder:
@Query(value = "SELECT * FROM table_name WHERE column_name LIKE :pattern")
List<Object[]> findPattern(String pattern);
The usage would be something like this:
String value = "blah";
String pattern = "%" value "%";
List<Object[]> rs = repo.findPattern(pattern);
CodePudding user response:
Since like %pattern%
is the same as contains pattern, your use case doesn't even need a query coded:
List<MyClass> findByColumnNameContaining(String pattern);