【发布时间】: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 Data JPA 实现以下查询。
select count(*) from example ex where ex.id = id and ex.status in (1, 2);
我知道 crud repo 中有一种方法用于计数,类似于 - countByIdAndStatus(params),但我不确定如何将“in”子句与此方法结合。
谢谢!
【问题讨论】:
你可以这样做:
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);
【讨论】: