嵌套对象映射

<resultMap id="userResultMap" type="com.example.User">
    <id property="id" column="user_id"/>
    <result property="name" column="user_name"/>
    <result property="age" column="user_age"/>
    <association property="address" javaType="com.example.Address">
        <id property="id" column="address_id"/>
        <result property="city" column="address_city"/>
        <result property="street" column="address_street"/>
    </association>
</resultMap>

 

集合映射

<resultMap id="userResultMap" type="com.example.User">
    <id property="id" column="user_id"/>
    <result property="name" column="user_name"/>
    <result property="age" column="user_age"/>
    <collection property="addresses" ofType="com.example.Address">
        <id property="id" column="address_id"/>
        <result property="city" column="address_city"/>
        <result property="street" column="address_street"/>
    </collection>
</resultMap>

 嵌套对象assocation换为 collection 就是 集合了qaq

${} 和 #{}  后者使用set方法赋值

 

posted on 2024-10-06 01:36  towboat  阅读(3)  评论(0编辑  收藏  举报