mybatis java.lang.NumberFormatException: For input string: "D"

本文解析了一个MyBatis更新语句中出现的错误,并详细解释了为何会出现NumberFormatException。通过对比不同条件判断的写法,指出了问题所在,并给出了正确的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mybatis语句:

<if test="status!=null and status=='D' ">
            , PriorStatus = Status
</if>

报错:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.NumberFormatException: For input string: "D"
### Cause: java.lang.NumberFormatException: For input string: "D"
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
    at com.sun.proxy.$Proxy92.update(Unknown Source)

但是原先的代码'VCID'不报错

<when test="resclassid=='VCID'">
                substr(resvalue,to_number(#{VCIDStartStrNum}),length(resvalue)-to_number(#{VCIDStartStrNum})) resvalue
</when>

原因:'D'只有1位,被认为是char。'VCID'不止一位,认为是String。

解决:

<if test="status!=null and status== &quot;D&quot;">
            , PriorStatus = Status
</if>

转载于:https://www.cnblogs.com/MangogoLee/p/9020239.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值