父实体类:
public class MerchantsVO {
private Integer id;
private String name;
private List<PaymentAccountVO> paymentAccountList;
}
关联子查询实体类:
public class PaymentAccountVO {
private Integer id;
private Integer merchantsId;
}
父查询返回结果实体类映射:
<resultMap id="merchantsResultMap" type="com.entity.vo.MerchantsVO">
<result property="id" column="id"/>
<result property="name" column="name"/>
<collection property="paymentAccountList" ofType="com.entity.vo.PaymentAccountVO"
column="id" select="getPaymentAccountByMerchantsId" fetchType="eager">
</collection>
</resultMap>
<collection>标签中的 column="id" , 对应为父实体类数据库映射字段,用于关联子查询
集合子查询实体类映射:
<resultMap id="paymentAccountResultMap" type="com.entity.vo.PaymentAccountVO">
<!-- 定义这个集合中元素的封装规则 -->
<result property="id" column="id"/>
<result property="merchantsId" column="merchants_id"/>
</resultMap>
父查询:
<select id="getMerchantsVOList" resultMap="merchantsResultMap">
SELECT m.* FROM merchants m
</select>
子查询:
<select id="getPaymentAccountByMerchantsId" resultMap="paymentAccountResultMap">
SELECT * FROM payment_account WHERE merchants_id = #{id}
</select>