spring - Spring Data JPA Query - 使用 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);
推荐阅读
- ios - 如何确定图像的 1x 大小?
- javascript - div上的jQuery自动更改类
- r - 跨多行替换特定值
- ruby - 请帮助纠正我对这个集合迭代、匹配和删除的误解:
- node.js - 这是使用 npm pkg 模块的询问
- javascript - onbeforeunload 事件异常?
- python - 获取以模式开头的字符串的单元格的所有行和列位置
- spring - Apache Curator + Spring Boot:简单的观察者模式示例
- android - Jetpack Compose 扩展 BottomSheetScaffold 的 BottomSheet 仅在重组后有效
- go - 如何使用 golang 和 FFmpeg 从视频中获取帧文件夹?