网站首页文章详情

MyBatis报错:Could not set parameters for mapping: ParameterMapping{property='categoryName', mode=IN, j

发布时间:2019-03-06 12:26编辑:胜男

刚开始学习mybatis在update时一直报以下错误

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='categoryName', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 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 (1 > number of parameters, which is 0).
经过仔细查看相关文档是,因为我配置xml文件的sql语句写错了,以下为错误代码

<update id="save" parameterType="ProductCategory">
    update product_category set category_name="#{categoryName}",category_type="#{categoryType}" where category_id="#{categoryId}"
</update>
在参数上多加了双引号,应删除

<update id="save" parameterType="ProductCategory">
    update product_category set category_name=#{categoryName},category_type=#{categoryType} where category_id=#{categoryId}
</update>
运行成功!

2019-03-06 12:25:49.514 DEBUG 1215 --- [main] c.i.s.mapper.ProductCategoryMapper.save  : ==>  Preparing: update product_category set category_name=?,category_type=? where category_id=? 
2019-03-06 12:25:49.561 DEBUG 1215 --- [main] c.i.s.mapper.ProductCategoryMapper.save  : ==> Parameters: 111(String), 92(Integer), 1(Integer)
2019-03-06 12:25:49.566 DEBUG 1215 --- [main] c.i.s.mapper.ProductCategoryMapper.save  : <==    Updates: 1