使用
MySQL可以使用CONCAT函数。例:
<if test
="userName
!= null and userName
!= ''"
>
and user_name like concat(
'%', #{userName},
'%')
</if>
注意:使用CONCAT函数连接字符串,在 MySQL 中,这个函数支持多个参数,但在 Oracle 中只支持两个参数。
针对这种情况,可以使用 bind 标签来避免由于更换数据库带来的一些麻烦。将上面的方法改为 bind 方式后,代码如下:
<if test
="userName
!= null and userName
!= ''"
>
<bind name
="userNameLike" value
="
'%' + userName
+ '%'"
/>
and user_name like #{userNameLike}
</if>
bind 标签的两个属性都是必选项,name 为绑定到上下文的变量名,value 为 OGNL 表达式。
转载于:https://www.cnblogs.com/zhuzhen/p/7160553.html
相关资源:数据结构—成绩单生成器