mybatis查询实体中包含list
1.实体
private List<String> birthdayCon; // 生日条件:01-12,格式如:01,02
private Integer ageMin; // 最小年龄
private Integer ageMax; // 最大年龄
private List<Map<String, Object>> cityCon;// 城市条件
2.mapper
<select id="selectFor" resultType="java.lang.Long" parameterType="com.test.Query">
select
DISTINCT(u.user_id) as userId
FROM
t_user u
LEFT JOIN t_user_info info ON u.user_id = info.user_id
LEFT JOIN t_order o on u.user_id = o.user_id
<where>
<if test="storeId != null and storeId != ''">and u.store_id = #{storeId}</if>
<if test="sex != null and sex != ''">and u.sex = #{sex}</if>
<if test="birthdayCon != null">and SUBSTR(u.birthday,6,2) in
<foreach collection="birthdayCon" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="ageMin != null and ageMin != ''">and TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) <![CDATA[>=]]> #{ageMin}</if>
<if test="ageMax != null and ageMax != ''">and TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) <![CDATA[<=]]> #{ageMax}</if>
<if test="cityCon != null"> and
<foreach collection="cityCon" index="index" item="item" open="(" separator="or" close=")">
(info.province = #{item.province}
and info.city = #{item.city}
and info.area = #{item.area})
</foreach>
</if>
</where>
</select>
转载地址:
https://blog.csdn.net/Luciferluanlan/article/details/80365008