1、#可以进行预编译,进行类型匹配,#变量名# 会转化为 jdbc 的 类型
$不进行数据类型匹配,$变量名$就直接把 $name$替换为 name的内容
例如:
select * from tablename where id = #id# ,假设id的值为12,其中如果数据库字段id为字符型,那么#id#表示的就是'12',如果id为整型,那么#id#就是 12
会转化为jdbc的 select * from tablename where id=?,把?参数设置为id的值
select * from tablename where id = $id$ ,如果字段id为整型,Sql语句就不会出错,但是如果字段id为字符型,
那么Sql语句应该写成 select * from table where id = '$id$'

3、#方式能够很大程度防止sql注入.
4、$方式无法方式sql注入.
5、$方式一般用于传入数据库对象.例如传入表名.
6、所以ibatis用#比$好,一般能用#的就别用$.
另外,使用##可以指定参数对应数据库的类型
如:
select * from tablename where id = #id:number#

在做in,like 操作时候要特别注意

总结以下:
$号使用在具体pojo类也就是非基本类型的取值,而#号使用在具体有基本类型的取值

<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>

ibatis中井号跟美元符号区别(#.$)的更多相关文章

  1. [转]ibatis中井号跟美元符号区别(#、$)

    Mybatis中如何在SQL语句表名中使用参数 insert into prefix_${table_name} (a, b, c) values (#{a}, #{b}, #{c}) ${} 表示直 ...

  2. MyBatis中井号与美元符号的区别

    #{变量名}可以进行预编译.类型匹配等操作,#{变量名}会转化为jdbc的类型. select * from tablename where id = #{id} 假设id的值为12,其中如果数据库字 ...

  3. URL 链接中 井号#、问号?、连接符& 分别有什么作用?

    在一个 URL 中可以包含很多的内容,其中不仅仅是包含 26 个英文字母,10 个罗马数字,中文汉字,还可以拥有井号“#”.问号“?”.连接符“&”等三种最常见的符号,那么这些符号在网站中都有 ...

  4. URL中#(井号)的作用(转)

    2010年9月,twitter改版. 一个显著变化,就是URL加入了"#!"符号.比如,改版前的用户主页网址为 http://twitter.com/username 改版后,就变 ...

  5. ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

    在iBATIS中isNull用于判断参数是否为Null,isNotNull相反 isEmpty判断参数是否为Null或者空,满足其中一个条件则其true isNotEmpty相反,当参数既不为Null ...

  6. 【转】ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

    转自:http://blog.csdn.net/fanfanjin/article/details/6676566 在iBATIS中 isNull用于判断参数是否为Null,isNotNull相反 i ...

  7. xml中${}的使用含义(美元符号大括号,以Spring、ibatis、mybatis为例)

    项目中,经常会在xml中看到这样的写法: <properties resource="properties/database.properties"/> <dat ...

  8. html5 css选择器。 井号,句号的区别

    .理解CSS的样式组成CSS里的样式表是有规则组成的,每条规则有三个部分组成:1.选择器(如下面例子中的:“body”),告诉浏览器文档的哪个部分受规则影响:2.属性(如实例中的font-family ...

  9. html5 css选择器 井号, 句点的区别

    一.理解CSS的样式组成CSS里的样式表是有规则组成的,每条规则有三个部分组成:1.选择器(如下面例子中的:"body"),告诉浏览器文档的哪个部分受规则影响:2.属性(如实例中的 ...

随机推荐

  1. python getopt学习记录

    有时候我们需要写一些脚本处理一些任务,这时候往往需要提供一些命令行参数,根据不同参数进行不同的处理,在Python里,命令行的参数和C语言很类似(因为标准Python是用C语言实现的).在C语言里,m ...

  2. python 常用系统参数

    获取当前路径: os.path.abspath('.') 或os.getcwd() 获取上一级路径: print os.path.abspath('..') 获取上上一级路径:  os.path.ab ...

  3. Commenting and uncommenting XML via Python

    转载: http://stackoverflow.com/questions/8764017/commenting-and-uncommenting-xml-via-python from xml.d ...

  4. [转载]Process工具类,提供设置timeout功能

    FROM:http://segmentfault.com/blog/lidonghao/1190000000372535 在前一篇博文中,简单介绍了如何使用Process类来调用命令行的功能,那样使用 ...

  5. 2017.7.10 Package name does not correspond to the file path

    参考来自:https://stackoverflow.com/questions/26440623/package-name-does-not-correspond-to-the-file-path- ...

  6. Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab

    Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab ...

  7. Ubuntu 下修改 Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    在Ubuntu上安装Apache,每次重启,都会出现以下错误提示: Could not reliably determine the server’s fully qualified domain n ...

  8. xcode几个常用的快捷键

    command + ctrl + e   修改变量的名称:选中某个变量,按下该快捷键,可以批量修改对应的变量名称 command + shift + j 定位到文档导航界面,然后通过上下方向键,可以快 ...

  9. Atitit。Time base gc 垃圾 资源 收集的原理与设计

    Atitit.Time base gc 垃圾 资源 收集的原理与设计 1. MRC(MannulReference Counting手动 retain/release/autorelease语句1 2 ...

  10. Android採用async框架实现文件上传

    页面效果 须要的权限 <uses-permission android:name="android.permission.INTERNET"/> 网络訪问权限; 布局文 ...