Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1

情景:

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

你可能感兴趣的:(Mybatis)