Hice una consulta personalizada en JPA spring boot y quiero pasar parámetros como dinámicos a la consulta, pero no funciona bien.
Esta es la consulta:
public interface CustomerRepository extends JpaRepository<Customer, Integer>{ @Query(value = "select * from customer.customer_tbl" + "where firstname like '%:keyword%';", nativeQuery = true) List<Customer> findByKeyword(@Param("keyword") String keyword); }Aquí '%:keyword%' es un literal de cadena, por lo que el parámetro interno no se reemplaza.
Usar CONCAT('%',:keyword,'%')
@Query(value = "select * from customer.customer_tbl where firstname like CONCAT('%',:keyword,'%');", nativeQuery = true) List<Customer> findByKeyword(@Param("keyword") String keyword);Prueba esto.
public interface CustomerRepository extends JpaRepository<Customer, Integer>{ @Query(value = "select * from customer.customer_tbl where firstname like CONCAT('%', :keyword, '%');", nativeQuery = true) List<Customer> findByKeyword(@Param("keyword") String keyword); }