我在 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 匹配,我認為這不是正確的解決方案,還有額外的操作。還考慮了改變數據庫的想法。
添加回答
舉報
0/150
提交
取消