Mybatis中模糊查询的各种写法

    xiaoxiao2021-03-25  226

    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') || '%'

    好文要顶 
    转载请注明原文地址: https://ju.6miu.com/read-389.html

    最新回复(0)