SQL中模糊查询的3种方式


1、使用 ${...} 代替 #{...}

 SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');

2、使用CONCAT()函数,如下

    

3、程序中拼接

   Java

   // String searchText = "%" + text + "%";

   String searchText = new StringBuilder("%").append(text).append("%").toString();

   parameterMap.put("text", searchText);
   Sql

   SELECT * FROM tableName WHERE name LIKE #{text};