Spring Data JPA 查询 - count with in 子句



我正在尝试使用带有方法名称解析的弹簧数据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);

最新更新