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

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

猜你喜欢

转载自blog.csdn.net/morning_china/article/details/80569089