Mybatis 中$与#的区别
来源:互联网 发布:2016网络大电影 编辑:程序博客网 时间:2024/06/07 19:51
Mybatis 中$与#的区别
1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端
把id值1,传入到后台的时候,就相当于 select id,name,age from student where id ='1'.
2 $是将传入的数据直接显示生成sql语句,eg:select id,name,age from student where id =${id},
当前端把id值1,传入到后台的时候,就相当于 select id,name,age from student where id = 1.
3 使用#可以很大程度上防止sql注入。(语句的拼接) $方式无法防止Sql注入。
4 但是如果使用在order by 中就需要使用 $.
5 在大多数情况下还是经常使用#,但在不同情况下必须使用$.
6.$方式一般用于传入数据库对象,例如传入表名.
我觉得#与$的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而{}穿入值,sql解析时,
参数是不带引号的。
1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端
把id值1,传入到后台的时候,就相当于 select id,name,age from student where id ='1'.
2 $是将传入的数据直接显示生成sql语句,eg:select id,name,age from student where id =${id},
当前端把id值1,传入到后台的时候,就相当于 select id,name,age from student where id = 1.
3 使用#可以很大程度上防止sql注入。(语句的拼接) $方式无法防止Sql注入。
4 但是如果使用在order by 中就需要使用 $.
5 在大多数情况下还是经常使用#,但在不同情况下必须使用$.
6.$方式一般用于传入数据库对象,例如传入表名.
我觉得#与$的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而{}穿入值,sql解析时,
参数是不带引号的。
阅读全文
0 0
- mybatis 中#与$的区别
- Mybatis 中 $ 与 # 的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- mybatis 中#与$的区别
- spring boot 架构问题 时间处理 (映射,时区问题)
- Spring mvc 注解总结 (下)
- CentOS7 Docker开启远程访问
- WEB_03_JavaScript_第一讲
- Servlet和CGI的区别
- Mybatis 中$与#的区别
- unity 压缩图片
- selvert 小解
- ansible-playbook实战之批量安装lamp
- English学习工具和资料
- log4j基本原理
- Go的并发
- 输入两个正整数m和n,求其最大公约数和最小公倍数
- leetcode--17. Letter Combinations of a Phone Number