背景

本次将一个类的属性从Integer改成String,上线后发现有这种报错org.apache.ibatis.type.TypeException: Could not set parameters for mapping

org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='brandName', 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 #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause:
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module 
java.base of loader 'bootstrap')
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

实际上有两个类

一个是com.lingyejun.Brand

另一个com.lingyejun.BrandCriterion

本次改动的brandName是在Brand类中改成了String,但是BrandCriterion遗漏掉了,并未进行更正。

<update id="updateBrand" parameterType="com.lingyejun.BrandCriterion">
        update tb_brand set brand_name = #{brandName},company_name = #    {companyName},ordered=#{ordered},description=#{description},status=#{status} where id=#{id};
 </update>
  • 1.
  • 2.
  • 3.

际上parameterType的参数可以不传,但是如果传了就要保证正确,错误的写成了com.lingyejun.BrandCriterion,导致了上述报错。

将parameterType设置为自己实体类的路径com.lingyejun.Brand或者把parameterType删除

 

本篇文章如有帮助到您,请给「翎野君」点个赞,感谢您的支持。

 

 


更改类的属性类型后发现的坑org.apache.ibatis.type.TypeException: Could not set parameters for mapping_bc

作者:翎野君