boot-like子句

lmvvr0a8  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(341)

我有一个查询返回产品列表:

@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 这个条款?
当我在db a中执行此语句时,得到一个结果:

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);

但这些都不管用。

xmjla07d

xmjla07d1#

我想你想 CONCAT() :

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

相关问题