沒有使用別名,查詢語句對應的數據表裏面也有book_id這個列名,但是卻出現了這樣的錯誤,一開始找到的解釋基本都是使用別名,但是我沒有使用別名
原始代碼:
@Query(value = "select id,comment = ?",nativeQuery = true)
public List<Comment> getCommentByBook_id(@Param("book_id") Integer id);
對於查詢的結果處理,我只需要id 和comment 這倆個數據,但是就是這裏出了問題:在Entity 裏沒有使用別名,所以book_id not found 應該指的是在要封裝的對象中
查詢的信息應該是整個commnet 不能是一部分信息(雖然在sql 語句中是成立的但是在@query 還涉及到對結果的封裝問題)
更改的代碼:
@Query(value = "select id,comment,book_id,book_name,user_id from tbl_comment where book_id = ?",nativeQuery = true)
public List<Comment> getCommentByBook_id(@Param("book_id") Integer id);