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>

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐