1. 程式人生 > >Mybatis xml中配置一對一關係association&一對多關係collection

Mybatis xml中配置一對一關係association&一對多關係collection

Mybatis xml中配置一對一關係association&一對多關係collection

今天在配置一對一關係對映以及一對多關係對映的時候,把collection中應該使用的ofType配置成了javaType。並且沒有及時發現錯誤,浪費了很多時間去查詢此配置問題,特此記一筆。

<resultMap id="deviceMap" type="com.cloud.model.iot.Device">
    <id property="id" column="id" />
    <result property="name" column
="name" />
<result property="sn" column="sn" /> <!-- 配置一對一關係 --> <association property="deviceType" columnPrefix="type_" javaType="com.cloud.model.iot.DeviceType"> <id property="id" column="id"/> <result property="name" column="name"/> <!-- 巢狀屬性一對多的關係 -->
<collection property="deviceTypeExtList" columnPrefix="ext_" ofType="com.cloud.model.iot.DeviceTypeExt"> <id property="id" column="id"/> <result property="attribute" column="attribute"/> <result property="dataType" column="data_type"/>
<result property="unit" column="unit"/> </collection> </association> </resultMap>

一對一關係中association 使用的是 javaType
::物件對應物件
一對多關係中collection 使用的是ofType
::物件對應集合中的物件