Mybatis 嵌套集合查询

假设:我要查询主子表的集合数据。(一对多)

一般查询就先查出主表,在查询字表。

用Mapper xml 中定义语句集合查询一次查询结果。

业务:

假设,要查询 某用户的所有上传记录

 

代码处理:

mapper:

<resultMap id="photoInfo" type="SurgeryPhotoClassificationInfo">
   <result column="id" property="id"/>
   <result column="photo_type"     property="photoType"/>
   <result column="take_date" property="takeDate"/>
   <result column="customer_number" property="customerNumber"/>
   <result column="name" property="createName"/>
   <collection  property="surgeryPhotoInfo" javaType="ArrayList" ofType="SurgeryPhotoInfo">
      <result column="id" property="id"/>
      <result column="photo_path" property="photoPath"/>
      <result column="customer_extend_photo_id" property="surPhotoClassificationInfoId"/>
      <result column="remarks" property="description"/>
   </collection>
</resultMap>

<select id="selectSinglePhoto" resultMap="photoInfo">
   SELECT  a.create_by,a.customer_number,a.take_date,a.photo_type,a.id ,b.photo_path,b.remarks,su.NAME
   from customer_extend_photo a
   INNER JOIN customer_extend_photo_chil b on b.customer_extend_photo_id = a.id
   INNER JOIN sys_user su on a.create_by = su.id
   where a.del_flag = '0'
    and a.photo_type =#{photoType}
   and a.customer_number=#{customerNumber}

</select>

这样就可以查出所有上传的次数,每次上次的照片了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值