为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Data JPA findAllBy ... in ... orderBy 输入列表

Spring Data JPA findAllBy ... in ... orderBy 输入列表

精慕HU 2021-09-12 16:40:14
我在 Kotlin/Java 中使用 JPA 和 Spring Boot。我正在尝试找到正确有效的方法来执行 findBy ... 在 OrderBy 输入中。我得到了一个我想要查找的 Id 列表,我想要一个具有相同顺序的有序输出。这是 JPA 允许您:@Repositoryinterface PhotoRepository : JpaRepository<Photo, String>{    // Which is the same as this query    @Query("SELECT p FROM Photo p where p.id in :var1")    fun findAllByIdIn(var1: List<String>, pageable: Pageable): List<Photo>}如果 JPA 允许您执行以下操作,那就太好了:@Repositoryinterface PhotoRepository : JpaRepository<Photo, String>{    @Query("SELECT p FROM Photo p where p.id in :var1 order by :var1")    fun findAllByIdInOrderByvar1(var1: List<String>, pageable: Pageable): List<Photo>}id 列表的大小在 500-1500 项之间。数据库中有很多记录,选择所有记录的想法不可行预期的解决方案是做一个findAllByIdIn然后将记录与列表中的 id 匹配,我认为这不是正确的解决方案,还有额外的操作。还考虑了改变数据库的想法。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信