1、${}
直接拼接为sql语句
<select id="selectCaseList" resultMap="BaseResultMap" parameterType="com.**.****.*****.bean.request.CaseListRequest">
select * from in_${appName}
<where>
<if test="inId != null">
AND inId = ${inId}
</if>
<if test="appName != null">
AND realClass = #{className}
</if>
<if test="methodName != null">
AND realMethod = #{methodName}
</if>
</where>
</select>
1、数据库名是作为参数传入进行拼接。假设appName=teacher,如果使用 #,就会变为select * from in_“teacher”,错误的sql语句
2、inId为Long类型,使用 # 会自动带上双引号,select * from in_teacher导致sql错误查不出数据
这个时候就可以用 $
但是这种也可以用 # 解决,如下面,指定jdbcType即可
<delete id="deleteById" parameterType="java.lang.Long" >
delete from t_jvm_mock
where id = #{id,jdbcType=BIGINT}
</delete>
2、#{}
拼接的时候会自动给参数带上双引号"",可以防止sql注入,较为安全