Mybatis各類模糊查詢及#和$區別

模糊查詢:java

工做中用到,寫三種用法吧sql

  1. sql中字符串拼接

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

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

SELECT * FROM tableName WHERE name LIKE '%${text}%';session

  1. 程序中拼接app

    Javaui

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

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

    parameterMap.put("text", searchText);接口

    SqlMap.xml字符串

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

異常:

java.lang.IllegalArgumentException: modify is ambiguous in Mapped Statements collection (try using the full name including the namespace, or rename one of the entries) at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:466) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:349) at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:137) at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:46) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:34) at $Proxy10.modify(Unknown Source)

拋出這個異常的緣由多是由於mapper.xml配置文件中<mapper>的namespace屬性配置錯誤形成的,沒有根據命名空間的值(全稱類名)找到相應映射接口。

如:<mapper namespace="com.xxx.xxx.mapper.TestMapper" >

相關文章
相關標籤/搜索