bind 用法
来源:互联网 发布:网络语言王炸什么意思 编辑:程序博客网 时间:2024/06/05 04:54
bind 标签可以使用 OGNL 表达式创建一个变量并将其绑定到上下文中。在前面的例子中,UserMapper.xml 有一个selectByUser
方法,这个方法用到了like
查询条件,部分代码如下。
<if test="userName != null and userName != ''">
and user_name like concat('%', #{userName}, '%')
</if>
使用 concat
函数连接字符串,在 MySQL 中,这个函数支持多个参数,但在 Oracle 中只支持两个参数。由于不同数据库之间的语法差异,如果更换数据库,有些 SQL 语句可能就需要重写。针对这种情况,可以使用 bind
标签来避免由于更换数据库带来的一些麻烦。将上面的方法改为bind
方式后,代码如下。
<if test="userName!=null and userName!=""">
<bind userName="userNameLike" value="%"+"userName+"%""/>
and user_name like concat(‘%’,#{userNameLike},'%')
<if>
bind 标签的两个属性都是必选项,name
为绑定到上下文的变量名,value
为 OGNL 表达式。创建一个bind
标签的变量后,就可以在下面直接使用,使用 bind
拼接字符串不仅可以避免因更换数据库而去修改 SQL,也能预防 SQL 注入。
阅读全文
0 0
- bind 用法
- prototype的bind用法
- Boost bind 用法
- boost.bind用法
- boost function bind用法
- bind函数用法
- boost.bind用法
- bind的用法
- boost::bind()用法
- sdt:bind用法
- boost bind 用法
- Boost.Bind用法详解
- jQuery.bind用法
- bind()的用法
- boost bind function用法说明
- jquery bind()与unbind()用法
- c++ std::bind 基本用法
- apply、call、bind区别、用法
- 贪心
- spring+spring mvc+hibernate+maven+oracle10g框架搭建及hibernate Tool使用汇总(附github源码)
- 在PyCharm中三步完成PyPy解释器的配置
- synchronized 笔记
- Android Studio快捷键
- bind 用法
- tomcat的server options
- Android开发圆形头像
- Linux下read和write函数复制一个文件
- day_03_出错处理和环境变量
- laravel上线时,需要做的事
- MyBatis知识七ResultMap描述
- 四面楚歌
- 模式与数据库、数据库中的表的关系: