Spring Data JPA查询 - 使用in子句进行计数

6

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

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

我知道crud repo中有一个计数的方法,它看起来像这样 - countByIdAndStatus(params),但我不确定如何将"in"子句与此方法结合使用。

谢谢!

1个回答

14

这是你可以做到的方法:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接