物體類中的屬性名和表中的欄位名不一樣 怎么辦?
第1種: 通過在查詢的sql陳述句中定義欄位名的別名,讓欄位名的別名和物體類的屬性名一致,下面展示一些 行內代碼片,
<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種: 通過來映射欄位名和物體類屬性名的一一對應的關系
<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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/231492.html
標籤:其他
上一篇:SQL Server授予了CREATE TABLE權限但是無法創建表淺析
下一篇:HTML-標簽語法
