che*_*ire 1 sql jpa where-clause sql-like spring-boot
我有一个返回产品列表的查询:
@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);
Run Code Online (Sandbox Code Playgroud)
我如何LIKE为此添加一个子句?
当我在数据库中执行此语句时,得到结果:
Select * from Product join Product_Pro pp on Product.ID = pp.PRODUCT_ID where A_ID= ?1 AND name LIKE '%someString%' AND content LIKE '%someString%' order by name
Run Code Online (Sandbox Code Playgroud)
但如何添加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);
Run Code Online (Sandbox Code Playgroud)
和
@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);
Run Code Online (Sandbox Code Playgroud)
但这些都不起作用。
GMB*_*GMB 11
我认为你想要CONCAT():
and name LIKE CONCAT('%', ?2, '%')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6592 次 |
| 最近记录: |