假设:我要查询主子表的集合数据。(一对多)
一般查询就先查出主表,在查询字表。
用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>
这样就可以查出所有上传的次数,每次上次的照片了。