码迷,mamicode.com
首页 > 其他好文 > 详细

ibatis中使用like模糊查询

时间:2016-04-13 09:46:10      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

无效的方法:

select  *  from table1 where name like ‘%#name#%‘

两种有效的方法: 1) 使用$代替#。此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险。

select  *  from table1 where name like ‘%$name$%‘ 

2) 使用连接符。不过不同的数据库中方式不同。

mysql:

select  *  from table1 where name like concat(‘%‘, #name#, ‘%‘)

oracle:

select  *  from table1 where name like ‘%‘ || #name# || ‘%‘

sql server:

 select  *  from table1 where name like ‘%‘ + #name# + ‘%‘

  

 

ibatis中使用like模糊查询

标签:

原文地址:http://www.cnblogs.com/fuyuanming/p/5385770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!