1、#将传入的数据当成一个字符串,会自动传入的数据加双引号“”。
例如:where username = #{username}; 如果传入的值为123,那么解析sql时的值为where username = “111”。
2、$将传入的值直接显示生成在sql中
例如:where username = ${username};如果传入的值为123,那么解析sql时的值为where username = 111。
在编写mybatis的映射语句时,尽量采用#{xxx},如果要使用${xxx}这样的参数要做好过滤工作,防止sql注入攻击。