在網上很多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>
寫得不好望指教!