JPA 本机 sql 查询中的 like 子句

like clause in JPA native sql query

我有一个查询 returns 产品列表:

@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 子句?

当我在我的数据库中执行这条语句时得到一个结果:

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

但是如何将 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_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);

但是 none 这些工作。

我想你想要 CONCAT():

and name LIKE CONCAT('%', ?2, '%')