mybits配置条件

xml文件里面内容

//这是普通的查询语句
<select id="getUserDirectCode" resultType="Map">
        select a.country,a.province,a.city,a.district from area a where a.area_code = #{area_code} order by a.area_code limit 1
</select>

//但是这样有问题,如果为空呢?就像下面这个语句,有四个条件,如果为空,直接拼接就会有问题,就按下面这样写,进行判断,有值则进行拼接,就ok了。
<select id="query" parameterType="java.util.Map"   resultType="java.util.Map">
    SELECT area_code FROM dict_area  WHERE
    <if test="cond1 != null and cond1 != ''">
        cond1 = #{cond1}
    </if>
    <if test="cond2 !=null  and cond2 != ''">
        and cond2 = #{cond2}
    </if>
    <if test="cond3 !=null  and cond3 != ''">
        and cond3 = #{cond3}
    </if>
    <if test="cond4 !=null  and cond4 != ''">
        and cond4 = #{cond4}
    </if>
    <if test="sourceid !=null ">
        and 3rd_part = #{sourceid}  limit 1
    </if>
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值