JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型(常用于association),而ofType指定的是映射到list集合属性中pojo的类型(常用于collection)。
2、association(一对一关联)
<resultMap id="getMaintenanceDtoListMapOneToOne"
type="com.atpdc.springboot.dto.BuildingMaintenanceDto" autoMapping="true">
<!-- BuildingDO 相关信息,必须有id才行-->
<id column="id" jdbcType="VARCHAR" property="id"/>
<!--关联的参数 1对1 fileDto-->
<association columnPrefix="sf_" property="fileDto" javaType="com.atpdc.springboot.dto.FileDto">
<id column="id" jdbcType="VARCHAR" property="id"/>
<id column="file_name_origin" jdbcType="VARCHAR" property="fileNameOrigin"/>
<id column="http_path" jdbcType="VARCHAR" property="httpPath"/>
</association>
</resultMap>
3、collection(一对多关联)
<result property="remark" column="remark"/>
<collection property="columns" javaType="java.util.List" resultMap="map1"/>
<resultMap id="getMaintenanceDtoListMapOneToMany"
type="com.atpdc.springboot.dto.BuildingMaintenanceDto" autoMapping="true">
<!-- BuildingDO 相关信息,必须有id才行-->
<id column="id" jdbcType="VARCHAR" property="id"/>
<!--关联的参数 fileDto-->
<collection columnPrefix="sf_" property="fileDto" ofType="com.atpdc.springboot.dto.FileDto">
<id column="id" jdbcType="VARCHAR" property="id"/>
<id column="file_name_origin" jdbcType="VARCHAR" property="fileNameOrigin"/>
<id column="http_path" jdbcType="VARCHAR" property="httpPath"/>
</collection>
</resultMap>
<collection property="emps" select="com.ta.dao.EmployeeMapper2.getEmpByIdStep" column="id"></collection>
<select id="getEmpByDeptIdStep" resultMap="IEmp>
select * from dept where id = #{id}
</select>