如何使用 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);
添加回答
舉報
0/150
提交
取消