當實體類中的屬性名和表中的字段名不一樣 ,怎么辦 ?


1 種: 通過在查詢的 sql 語句中定義字段名的別名,讓字段名的別名和實體類

的屬性名一致。

35 頁 共 485 頁<select id=”selectorder” parametertype=”int” resultetype=”

me.gacl.domain.order”>

select order_id id, order_no orderno ,order_price price form

orders where order_id=#{id};

</select>

2 種: 通過<resultMap>來映射字段名和實體類屬性名的一一對應的關系。

<select id="getOrder" parameterType="int"

resultMap="orderresultmap">

select * from orders where order_id=#{id}

</select>

<resultMap type=”me.gacl.domain.order” id=”orderresultmap”>

<!–用 id 屬性來映射主鍵字段–>

<id property=”id” column=”order_id”>

<!–用 result 屬性來映射非主鍵字段,property 為實體類屬性名,column

為數據表中的屬性–>

<result property = “orderno” column =”order_no”/>

<result property=”price” column=”order_price” />

</reslutMap>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM