【问题标题】:Spring Data JPA Query - count with in clauseSpring Data JPA Query - 使用 in 子句计数
【发布时间】:2018-08-28 12:53:13
【问题描述】:

我正在尝试使用带有方法名称解析的 Spring Data JPA 实现以下查询。

select count(*) from example ex where ex.id = id and ex.status in (1, 2);

我知道 crud repo 中有一种方法用于计数,类似于 - countByIdAndStatus(params),但我不确定如何将“in”子句与此方法结合。

谢谢!

【问题讨论】:

    标签: spring spring-data-jpa


    【解决方案1】:

    你可以这样做:

    long countByIdAndStatusIn(Integer id, List<Type> params);
    

    @Query:

    @Query("select count(*) from Example ex where ex.id = ?1 and ex.status in (?2)")
    long countByIdAndStatus(Integer id, List<Type> params);
    

    【讨论】:

      猜你喜欢
      • 2015-06-07
      • 2015-09-20
      • 2016-11-26
      • 2014-11-27
      • 2021-11-04
      • 2020-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      相关资源
      最近更新 更多