mybatis 查询条件包含list

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

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值