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
::对象对应集合中的对象