jeesite企业网站开发教程(所用到的非Jeesite本身知识点汇总)
2017-11-27 20:30
232 查看
(一)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注入。(语句的拼接)
4 但是如果使用在order by 中就需要使用 $.
5 在大多数情况下还是经常使用#,但在不同情况下必须使用$.
我觉得#与的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而{}穿入值,sql解析时,参数是不带引号的。
一 : 理解mybatis中 $与#
在mybatis中的$与#都是在sql中动态的传入参数。
eg:select id,name,age from student where name=#{name} 这个name是动态的,可变的。当你传入什么样的值,就会根据你传入的值执行sql语句。
二:使用$与#
#{}: 解析为一个 JDBC 预编译语句(prepared statement)的参数标记符,一个 #{ } 被解析为一个参数占位符 。
${}: 仅仅为一个纯碎的 string 替换,在动态 SQL 解析阶段将会进行变量替换。
name-->cy
eg: select id,name,age from student where name=#{name} -- name='cy'
select id,name,age from student where name=${name} -- name=cy
(二)json对象与字符串互转
JSON.parse(jsonstr); //可以将json字符串转换成json对象
JSON.stringify(jsonobj); //可以将json对象转换成json对符串
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注入。(语句的拼接)
4 但是如果使用在order by 中就需要使用 $.
5 在大多数情况下还是经常使用#,但在不同情况下必须使用$.
我觉得#与的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而的区别最大在于:#{} 传入值时,sql解析时,参数是带引号的,而{}穿入值,sql解析时,参数是不带引号的。
一 : 理解mybatis中 $与#
在mybatis中的$与#都是在sql中动态的传入参数。
eg:select id,name,age from student where name=#{name} 这个name是动态的,可变的。当你传入什么样的值,就会根据你传入的值执行sql语句。
二:使用$与#
#{}: 解析为一个 JDBC 预编译语句(prepared statement)的参数标记符,一个 #{ } 被解析为一个参数占位符 。
${}: 仅仅为一个纯碎的 string 替换,在动态 SQL 解析阶段将会进行变量替换。
name-->cy
eg: select id,name,age from student where name=#{name} -- name='cy'
select id,name,age from student where name=${name} -- name=cy
(二)json对象与字符串互转
JSON.parse(jsonstr); //可以将json字符串转换成json对象
JSON.stringify(jsonobj); //可以将json对象转换成json对符串
相关文章推荐
- PHP网站开发实例教程之知识点归纳2(操作数据库)
- PHP网站开发实例教程-知识点归纳1
- PHP网站开发实例教程之知识点归纳3(WEB表单与会话技术)
- 开发语言的一些汇总网站、及教程。
- Java与Java web开发教程网站之IBM developer
- iOS开发学习网站汇总
- 计算机软件开发--技术网站汇总
- IOS开发网站汇总
- GBin1教程:使用jQuery Mobile快速开发一个手机网站
- 使用VTEditor软件快速开发网站系列教程七 自定义页面篇
- 移动平台3G手机网站前端开发布局技巧汇总
- ASP.NET 视频教程 商务网站 购物车制作 VS2008 C# SQL2005 开发
- 【绝对给力】Android开发免豆资料(教程+工具+源码)地址汇总 ...
- 【绝对给力】Android开发免豆资料(教程+工具+源码)地址汇总
- 网站开发进阶(二十二)HTML UI知识汇总(更新中...)
- 如何做好网站开发项目需求分析_心得技巧教程
- android游戏开发框架libgdx的使用-安卓巴士教程地址汇总
- APP源码 教程 网页转APP 安卓Andriod应用开发 手机APP 移动网站
- 机器学习数据挖掘-软件、网站、课程资源知识点汇总
- 【原创·视频·教程】大话优酷、酷六类视频网站Android端软件开发