【问题标题】:Spring boot JPA @Query with like and in带有like和in的Spring Boot JPA @Query
【发布时间】:2019-03-15 15:52:55
【问题描述】:

我正在尝试在 Repository 中创建一个能够为我提供用户列表的方法,但它没有返回值。

这是我的方法:

public interface ProductRepository extends JpaRepository<Product, Integer> {
    @Query(value = "select * from mmall_product m where m.status =1 and m.name like CONCAT('%',?1,'%') and m.category_id in (?2)", nativeQuery = true)
    List<Product> findByNameAndCategoryIds(String productName, String categoryIdLists);
}

这是我的categoryIdLists

String categoryIdLists = StringUtils.join(categoryIdList, ",");

在我的navicatfor mysql中,我可以得到数据。

这是我的 SQL 选择:

select * from mmall_product m where m.status =1 and m.name like CONCAT('%','a','%') and m.category_id in ("100001","100002","100003")

这是我的回报:

26  100002  Apple iPhone 7 Plus (A1661) 128G    iPhone 7,.jpeg  detailtext  1422    7   1   2019-03-14 19:45:38 2019-03-14 19:45:58

40  100003  afa   aa    test.jpg    test.jpg,11.jpg,2.jpg,3.jpg detailtext  757 100 1   2019-03-14 19:45:38 2019-03-14 19:45:58

42  100003  apple   testtest.jpg    test.jpg,11.jpg,2.jpg,3.jpg detailtext  463 100 1   2019-03-14 19:45:38 2019-03-14 19:45:58

但在我的 spring boot 中,我无法获取返回值。

谁能帮我解决这个问题?

【问题讨论】:

    标签: java mysql spring-boot jpa spring-data-jpa


    【解决方案1】:

    根据您的要求,为什么不使用 booleanbuilder 而不是 @query。为便于理解,您可以通过http://www.querydsl.com/static/querydsl/2.1.0/reference/html/ch03.html

    【讨论】:

      猜你喜欢
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 2021-10-13
      • 2014-08-31
      • 2013-10-05
      相关资源
      最近更新 更多