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

背景

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

1
org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='brandName', mode=IN, javaType=class java.lang.Integer,<br>jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non<br>null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause:<br>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 <br>java.base of loader 'bootstrap')

实际上有两个类

一个是com.lingyejun.Brand

另一个com.lingyejun.BrandCriterion

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

1
2
3
<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

 
posted @   翎野君  阅读(82)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示