标签:cos style varchar ble 解析 integer RoCE values 入参
我们经常使用的是#{},一般解说是因为这种方式可以防止SQL注入,简单的说#{}这种方式SQL语句是经过预编译的,它是把#{}中间的参数转义成字符串,举个例子:
select * from student where student_name = #{name}
预编译后,会动态解析成一个参数标记符?:
select * from student where student_name = ?
而使用${}在动态解析时候,会传入参数字符串
select * from student where student_name = ‘lyrics‘
#{}方式能够很大程度防止sql注入,$方式无法防止Sql注入。$方式一般用于传入数据库对象,例如传入表名或自己拼字符串.,一般能用#的就别用$。
<insert id="save"
parameterType="com.tarena.entity.Cost">
insert into cost values(
cost_seq.nextval,
#{name,jdbcType=VARCHAR},
#{base_duration,jdbcType=INTEGER},
#{base_cost,jdbcType=DOUBLE},
...
)
</insert>
Mybatis${}、#{}及使用#{}时指定jdbcType
标签:cos style varchar ble 解析 integer RoCE values 入参
原文地址:https://www.cnblogs.com/guanghe/p/9317476.html