我有一個枚舉 (ClubRole),它有一個方法從這個枚舉返回值的集合。我嘗試使用 SpEl 從查詢內部調用此方法。 @Query("select m from ClubMember m " + "where m.student = :student " + "and m.role in :#{#role.getParents()}" ) List<ClubMember> findByRoleWithInheritance(@Param("student") Student student, @Param("role") ClubRole role);這通過了構建,并且應用程序運行但是當調用此方法時我得到``沒有找到名稱角色的參數綁定!; 嵌套的異常是 java.lang.IllegalArgumentException:找不到名稱角色的參數綁定!我嘗試了不同的方法,但都沒有用。我想知道在這種情況下是否可以使用 SpEl,如果可以,如何使用?
1 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
看起來這是 spring-data-jpa 中的一個問題。我可以看到人們在 spring-blog 上討論同樣的問題。不確定是否存在未解決的問題。您可以嘗試以下作為解決方法。
@Query("select m from ClubMember m " +
"where m.student = :#{#student}" +
"and m.role in :#{#role.getParents()}"
)
List<ClubMember> findByRoleWithInheritance(@Param("student") Student student, @Param("role") ClubRole role);
或者您可以嘗試對第二個參數進行索引訪問,例如#{[1].getParents()}
這可能會有所幫助。
添加回答
舉報
0/150
提交
取消