<resultMaptype="com.qs.mybatisfast.pojo.Order"id="order_user_result_map"><idproperty="id"column="id"/><resultproperty="userId"column="user_id"/><resultproperty="money"column="money"/><resultproperty="note"column="note"/><resultproperty="createTime"column="create_time"/><!-- `association标签`:配置`一对一`关联映射。
1、`property属性`:对于`order`中的`user属性`。
2、`javaType属性`:是`user属性`的`数据类型`
--><associationproperty="user"column="user_id"javaType="com.qs.mybatisfast.pojo.User"><idproperty="id"column="user_id"/><resultproperty="username"column="username"/><resultproperty="address"column="address"/></association></resultMap><selectid="getOrderUserResultMap"resultMap="order_user_result_map">
SELECT o.id,
o.user_id,
o.money,
o.note,
o.create_time,
u.username,
u.address
FROM `order` o
LEFT JOIN `user` u ON u.id = o.user_id
</select>
<resultMaptype="com.qs.mybatisfast.pojo.Order"id="order_user_result_map"><idproperty="id"column="id"/><resultproperty="userId"column="user_id"/><resultproperty="money"column="money"/><resultproperty="note"column="note"/><resultproperty="createTime"column="create_time"/><!-- 一对一 --><associationproperty="user"javaType="com.qs.mybatisfast.pojo.User"column="user_id"select="getUserById"></association></resultMap><selectid="getOrderUserResultMap"resultMap="order_user_result_map">
SELECT id, user_id, money, note, create_time
FROM `order`
</select><selectid="getUserById"parameterType="int"resultType="com.qs.mybatisfast.pojo.User">
SELECT *
FROM `user`
WHERE id = #{id}
</select>
4.3 resultMap.collection 标签
<resultMaptype="com.qs.mybatisfast.pojo.User"id="user_order_result_map"><idproperty="id"column="id"/><resultproperty="username"column="username"/><resultproperty="sex"column="sex"/><resultproperty="birthday"column="birthday"/><resultproperty="address"column="address"/><!-- `collection标签`:配置`一对多`关联映射。
1、`property属性`:对于`user对象`中的`集合属性`。
2、`ofType属性`:集合中每个元素的数据类型。
--><collectionnotNullColumn="oid"property="orders"javaType="java.util.List"ofType="com.qs.mybatisfast.pojo.Order"><!-- id对于order的主键属性 --><idproperty="id"column="oid"/><resultproperty="money"column="money"/><resultproperty="note"column="note"/><resultproperty="createTime"column="create_time"/></collection></resultMap><selectid="getUserWithOrders"resultMap="user_order_result_map">
SELECT u.id,
u.username,
u.sex,
u.birthday,
u.address,
o.id AS oid,
o.money,
o.note,
o.create_time
FROM `user` u
LEFT JOIN `order` o ON o.user_id = u.id
</select>