更改类的属性类型后发现的坑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删除
本篇文章如有帮助到您,请给「翎野君」点个赞,感谢您的支持。
出处:http://www.cnblogs.com/lingyejun/
若本文如对您有帮助,不妨点击一下右下角的【推荐】。
如果您喜欢或希望看到更多我的文章,可扫描二维码关注我的微信公众号《翎野君》。
转载文章请务必保留出处和署名,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端