close

 

nativeQuery = true

如果有使用的話,
就會使用原生 SQL語句去執行,
像你想從資料表去搜尋的話,就可以加這句。

沒有加的話,
就是使用 HQL語句去資料庫去搜尋。

沒有加和是要用資料表做查詢的話,
就會出現錯誤,
org.hibernate.hql.internal.ast.QuerySyntaxException: Prdouct1 is not mapped
螢幕擷取畫面 2021-11-08 184144.jpg

 

範例:

//查詢: 價格(低到高)
@Query(value="select p from Prdouct1 p ORDER BY p.price DESC", nativeQuery = true)
List<ProductBean> findAllProductsByPriceDesc(int price);

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 書童 的頭像
    書童

    小書童

    書童 發表在 痞客邦 留言(0) 人氣()