mybatis中的association和collection

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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值