java.sql.SQLException: Parameter index out of range
异常提示:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=product.productName, mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId=null, jdbcTypeName=null, expression=null}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1
我这里是 like 语法错误 !
第一次 是这样
"<when test=product.keywords !=null>"+
"AND p.product_name like %#{product.keywords}% "+
"</when>"+
第二次 使用CONCAT 拼接 :这时候报上面的异常
"<when test=product.keywords !=null>"+
"AND p.product_name like CONCAT(%,${product.keywords},%)"+
"</when>"+
正确方式为:
"<when test=product.keywords !=null>"+
"AND p.product_name like CONCAT(%,#{product.keywords},%)"+
"</when>"+
感觉找了好久,试了不同的写法,这问题 主要是 同时写两种sql的锅!!!
用@SelectProvider方法 写sql 在这里面的注解 CONCAT(%,#{product.keywords},%) 用 “#”是可以的
最后,带 ” $ ” 好像是要加 单引的。。
