mybatisのresultMap與resultType
阿新 • • 發佈:2018-12-04
resultMap 用於在資料庫表字段和java實體類欄位建立轉換關係
<!-- resultMap 資料結果集對映map,主要作用就是將資料庫中的欄位跟需要對映的model的屬性一一對應, 這樣即使model中的屬性跟資料庫中的欄位不一樣,也能對映成功 id 這個resultMap的唯一表示, type 需要對映的model資訊--> <resultMap id="customerMap" type="com.soft.mybatis.model.Customer"> <!-- id 屬性專門用來對映主鍵資訊,其他資訊用result節點 column 資料庫欄位 property model屬性 --> <id column="id" property="id"/> <!-- result 用來對映非主鍵資訊, column property 作用跟id標籤的一樣--> <result column="c_name" property="name"/> <resultcolumn="c_sex" property="sex"/> <result column="c_age" property="age"/> <result column="c_ceroNo" property="ceroNo"/> <result column="c_ceroType" property="ceroType"/> </resultMap>
在<select>標籤中是需要增加 resultType 型別,不然查詢的結果往哪裡放呢。
是的