java - 如何在 Jpa Hibernate Query 中将数字数组作为参数传递?
问题描述
例子 :
Select * from student where roll_no in (1,2,3);
在学生存储库(Spring Boot)中:
@Query(value="Select * from student where roll_no in (?)",native =true)
List selectStudents(我在这里给什么?)
或者还有其他方法可以实现吗?
解决方案
如果你想使用本机查询,你可以像下面那样做
@Query(value="select * from student where roll_no in (:rollNos)",native =true)
List<Object[]> selectStudents(@Param("rollNos") List<Integer> rollNos);
但我建议您使用如下所示的 JPA 命名查询来执行此操作,这很容易进一步处理,因为它以实体格式为您提供结果。
Student findByRollNo(List<Integer> rollNos);
推荐阅读
- f# - VSCode 中名为 test.fsx 的 F# 文件没有错误高亮显示
- ruby-on-rails - 在用户指定的时间发送邮件并在 Rails 错误中更新数据库中的状态
- sqlalchemy - 如何使用 SQLAlchemy 创建“ORDER BY Column = 'Value'”查询
- sql - 在 Mac 上下载 PostgreSQL
- api - 以编程方式转换就绪 -> 草稿 GitHub PR,反之亦然
- visual-studio - 如何创建虚拟设备?
- c# - JWT 与 C# 与通用存储库模式
- javascript - 在日历应用程序中,我们应该在客户端还是服务器端找到时区?
- gnuplot - 从wireshark绘制一个csv文件
- javascript - 纠结于 js 的 promise,foreach 的 promise 添加结果