Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1
阿新 • • 發佈:2019-01-06
情景:
mybatis語句
AND (p.times_limited='NO' OR (p.times_limited='YES' AND times LIKE '%#{times}%'))
異常資訊:
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='times', mode=IN, javaType=class java.lang.Integer, 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: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
解決方法:
需要將like 拼接一下否則 解析不了 出現異常
CONCAT('%',#{times},'%'))