天天看点

Mybatis中模糊查询的各种写法

工作中用到,写三种用法吧,第四种为大小写匹配查询

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