1. 程式人生 > >【spring boot jpa】hql語句報錯 :antlr.NoViableAltException: unexpected token: roleName

【spring boot jpa】hql語句報錯 :antlr.NoViableAltException: unexpected token: roleName

圖片 set 技術 body except exp 所在 antlr class

使用場景:在spring data jpa下使用@Query("hql語句")

然後在項目啟動的時候報錯

hql語句報錯:antlr.NoViableAltException: unexpected token: roleName

仔細查看了一下代碼:

 @Query(value =
    "from Role as r left join r.department as d left join d.company as c where" +
            " (:departmentId is null or d.id = :departmentId)" +
            " 
and (:companyId is null or c.id = :companyId)"+ " and (:roleName is null or r.name = :roleName)" ) fun searchRole( @Param("departmentId") departmentId: Long? = null, @Param("companyId") companyId: Long? = null, @Param("roleName") roleName: String? =
null ): Set<Role>

技術分享圖片

問題所在:

roleName本身確實沒有問題,但是它邊上的(括號確實有問題

發現它跟前的括號縮緊和上面的括號縮進不一樣,好吧 真惡心

解決問題:

把:roleName附近的中文括號替換成英文括號,問題解決。

【spring boot jpa】hql語句報錯 :antlr.NoViableAltException: unexpected token: roleName