嵌套对象映射
<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方法赋值