亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 ExampleMatcher 和 Pageable 檢索數據的 JPQL 自定義查詢

使用 ExampleMatcher 和 Pageable 檢索數據的 JPQL 自定義查詢

慕萊塢森 2022-07-20 15:41:42
如何使用 ExampleMatcher 使用 JPQL 自定義查詢?我正在嘗試從父母大小中檢索孩子。由于我不允許在子端添加另一種方法。我需要過濾和分頁以顯示孩子,因為孩子包含太多行數據。這是我的存儲庫。@Repositorypublic interface ParentRepository extends JpaRepository<Parent, String> {    @Query(value = "SELECT c FROM Child c where c.parent.id =:id")      public List<Child> findChildById(String id, Example example, Pageable pageable);}注意:如果沒有示例和可分頁作為參數,此查詢工作正常。該方法給我一個錯誤:    Error creating bean with name 'parentRepository':         Invocation of init method failed; nested exception is java.lang.IllegalStateException:         Using named parameters for method public abstract java.util.List com.example.test.ParentRepository.findChildById(java.lang.String,org.hibernate.criterion.Example,org.springframework.data.domain.Pageable)         but parameter 'Optional[example]' not found in annotated query         'SELECT c FROM Child c where c.parent.id =:id'!
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

您傳遞給帶有注釋的方法的參數@Query應該在查詢中使用,在您的示例中應該是這樣的:


@Query(value = "SELECT c FROM Child c where c.parent.id =:id")  

public List<Child> findChildById(@Param("id") String id);


查看完整回答
反對 回復 2022-07-20
  • 1 回答
  • 0 關注
  • 349 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號