首页 > 其他 > 详细

mybatis中#与$的区别

时间:2020-04-25 15:08:33      阅读:35      评论:0      收藏:0      [点我收藏+]

1、传入的参数在SQL中显示不同

#传入的参数在SQL中显示为字符串(当成一个字符串),会对自动传入的数据加一个双引号。

例:使用以下SQL

select id,name,age from student where id =#{id}

 

$传入的参数在SqL中直接显示为传入的值当我们传递的参数id为 "1" 时,上述 sql 的解析为:

select id,name,age from student where id ="1"

 

例:使用以下SQL

select id,name,age from student where id =${id}


 当我们传递的参数id为 "1" 时,上述 sql 的解析为:

select id,name,age from student where id =1

 

2、#可以防止SQL注入的风险(语句的拼接);但$无法防止Sql注入。

3、大多数情况下还是经常使用#,一般能用#的就别用$;但有些情况下必须使用$,例:MyBatis排序时使用order by 动态参数时需要注意,用$而不是#

mybatis中#与$的区别

原文:https://www.cnblogs.com/wanjun-top/p/12772921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!