在网上很多mybatis的关联查询资料,但是要用主表的多个条件查子表的资料少之又少,今天刚好用到了,就分享下给大家,多条件的写法。(主要是注意红色字体代码)
实体类:
public class PhotoFeedback implements Serializable {
private int id;
private String name;
private int userId; //用户id
private List<PhotoFeedbackPic> listPic;
}
photoFeedbackapper.xml的部分代码:
.......
<resultMap id="queryPhotoAllListResult" type="com.lianhua.tenement.domain.PhotoFeedback">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="titleName" column="titleName" />
<result property="describeTxt" column="describeTxt" />
<result property="address" column="address" />
<result property="telephone" column="telephone" />
<result property="commentaries" column="commentaries" />
<result property="enterpriseId" column="enterpriseId" />
<result property="latitude" column="latitude" />
<result property="longitude" column="longitude" />
<result property="createTime" column="createTime" />
<collection property="PhotoFeedbackPic" column="{id=id,createTime=createTime}" select="queryPhotoFeedbackList" />
</resultMap>
<select id="queryPhotoFeedbackList" parameterType="java.util.Map" resultType="com.lianhua.tenement.domain.PhotoFeedbackPic">
select
id as id ,
photoId as photoId,
month as month ,
pic_url as picUrl ,
pic_name as picName ,
create_time as createTime
from t_fip_business_photofeedback_pic
where photo_id = #{id} and month = date_format(#{date},‘%Y-%m‘)
</select>
写得不好望指教!