MyBatis #{} 和 ${}

<select id="select" parameterType="map" resultType="xxxModel">

        select
        *
        from
        xxxTable
        where
        cooperate_days > 120

        <if test="clueType != null and clueType != ''">
            AND clue_type = #{clueType}
        </if>

        order by apply_rate DESC

        <if test="limit != null and limit != '' ">
            LIMIT ${limit}
        </if>

    </select>

注意上面代码中的 #{} 和 ${}

对应的SQL语句:
select * from mart_fd.model_clue_manage_interface where cooperate_days > 120 AND clue_type = ? order by apply_rate DESC LIMIT 15000

#{} 处 是个占位符 ? , 而${} 处 是具体的值。

1 #是将传入的值当做字符串的形式,select * from xxxTable where xx =#{xx},即 select * from xxxTable where xx =‘1’.

2 $是将传入的数据直接显示生成sql语句,select * from xxxTable where xx =${xx},即 select * from xxxTable where xx = 1.

3 使用#可以很大程度上防止sql注入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值