MyBatis的SQL语句的两种取值方式

第一种就是用$符号进行取值

执行SQL:select * from user where name = ${Name}
参数:Name传入值为:zhangsan
解析后执行的SQL:Select * from user where name = zhangsan

这种方式容易有SQL注入,就相当于是你直接用JDBC的时候去拼接一个字符串出来。

第二种就是用#符号进行取值

执行SQL:select * from user where name = #{Name}
参数:Name传值为zhangsan
解析后执行的SQL:select * from user where name = ?

这种方式不容易有SQL注入,所以推荐使用#取值,MyBatis会有一些判断的。

猜你喜欢

转载自blog.csdn.net/minolk/article/details/82703812