MyBatis报错:Could not set parameters for mapping: ParameterMapping{property='categoryName', mode=IN, j - 一个90后PHP程序员的个人博客网站

刚开始学习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 product_category set category_name="#{categoryName}",category_type="#{categoryType}" where category_id="#{categoryId}"

在参数上多加了双引号,应删除

update product_category set category_name=#{categoryName},category_type=#{categoryType} where category_id=#{categoryId}

运行成功!

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


Original url: Access
Created at: 2019-08-27 12:24:50
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论