前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >更改类的属性类型后发现的坑org.apache.ibatis.type.TypeException: Could not set parameters for mapping

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

作者头像
翎野君
发布2024-11-21 12:22:18
发布2024-11-21 12:22:18
8900
代码可运行
举报
文章被收录于专栏:翎野君
运行总次数:0
代码可运行

背景

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

代码语言:javascript
代码运行次数:0
复制
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遗漏掉了,并未进行更正。

代码语言:javascript
代码运行次数:0
复制
<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://cloud.tencent.com/developer/article/2468638

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-07-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档