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

背景

本次将一个类的属性从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')

实际上有两个类

一个是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>

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

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

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

首发链接:https://www.cnblogs.com/lingyejun/p/18306479

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值