JPA原生sql查询中的like子句
我有一个返回产品列表的查询:JPA原生sql查询中的like子句,sql,spring-boot,jpa,where-clause,sql-like,Sql,Spring Boot,Jpa,Where Clause,Sql Like,我有一个返回产品列表的查询: @Query(value = "Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 order by name", nativeQuery = true) List<Product> findAll(long id); 但是如何将LIKE添加到我的JPA原生查询中 我试过: @Query(value = "S
@Query(value = "Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 order by name",
nativeQuery = true)
List<Product> findAll(long id);
但是如何将LIKE
添加到我的JPA原生查询中
我试过:
@Query(value = "Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 and name LIKE '%?%' order by name",
nativeQuery = true)
List<Product> findAll(long id, String name);
@Query(value=“Select*from Product join Product\u Pro pp on Product.ID=pp.Product\u ID,其中A\u ID=1,名称类似“%”?%”按名称排序),
nativeQuery=true)
列表findAll(长id、字符串名称);
及
@Query(value=“Select*from Product join Product\u Pro pp on Product.ID=pp.Product\u ID,其中A\u ID=?1,名称类似“%:name%”按名称排序”,
nativeQuery=true)
List findAll(长id,@Param(“name”)字符串名);
但是这些都不行。我想你需要
CONCAT()
:
@Query(value = "Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 and name LIKE '%?%' order by name",
nativeQuery = true)
List<Product> findAll(long id, String name);
@Query(value = "Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 and name LIKE '%:name%' order by name",
nativeQuery = true)
List<Product> findAll(long id,@Param("name") String name);
and name LIKE CONCAT('%', ?2, '%')