工作中用到,寫三種用法吧,第四種為大小寫比對查詢
1. sql中字元串拼接
select * from tablename where name like concat(concat('%', #{text}), '%');
2. 使用 ${...} 代替 #{...}
select * from tablename where name like '%${text}%';
3. 程式中拼接
java
// string searchtext = "%" + text + "%";
string searchtext = new stringbuilder("%").append(text).append("%").tostring();
parametermap.put("text", searchtext);
sqlmap.xml
select * from tablename where name like #{text};
4. 大小寫比對查詢
select * from tablename where upper(subsystem) like '%' || upper('jz') || '%' 或者
select * from tablename where lower(subsystem) like '%' || lower('jz') || '%'
原帖位址:http://blog.csdn.net/luqin1988/article/details/7865643