原始SQL:select * from user where user_name = #{name} 预编译后:select * from user where user_name = ?
然后调用set方法来赋值‘张三’
原始SQL: select * from user where user_name = #{name} 编译后SQL:select * from user where user_name = ‘张三’
这样很容易会遭到恶意SQL的拼接来非法操作数据
因为采用预编译机制,预编译完成后,SQL的结构已经固定,
这时候,即使用户输入非法的参数,也不会对SQL语句的整体结构造成影响,从而避免了SQL注入的危险
原文:https://www.cnblogs.com/gslgb/p/15027791.html