JPA自定義類接收查詢結果,聯表查詢

@Query("select new com.vo.UserInfoVo(u.id,u.userName,g.score) from UserInfo u left join Grade g on u.id = g.userId where u.id =:userId ")
List<UserInfoVo> queryEmpList(@Param("userId") String userId);

自定義UserInfoVo類,寫在sql語句中要全包名。

自定義Vo類中藥包含構造方法(重點),參數順序與sql中相同

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章