1.异常现场
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='size', 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 #3 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 (3 > number of parameters, which is 2).
<select id="listPropertiesByPage" resultMap="propertyDOResultMap"
parameterType="com.wz.eshop.commodity.domain.PropertyQuery">
SELECT id, property_name, description, input_type, input_values, create_time, update_time
FROM commodity_property
<where>
<if test="propertyName != null">
and property_name like '#{propertyName}%'
</if>
</where>
LIMIT #{offset},#{size};
</select>
需要设置的参数值个数超过了范围,3 > 2
2.原因
仔细看写的SQL,会发现这个:'#{}',#{}被单引号引用了
and property_name like '#{propertyName}%'
使用#{}时,使用单引号会导致#{}失效,改为${}即可
网友评论