mapper.xml出现错误 Error setting non null for parameter #3 with JdbcType null .

这篇博客记录了在学习SSM框架时遇到的一个典型异常,异常原因是由于SQL语句中的细节错误导致。问题可能包括:1) 两个#符号紧挨在一起;2) SQL注释使用不当;3) 单引号误用覆盖了参数#{id}

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

记录学习SSM框架遇到的问题3

异常报告

消息 Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘id’, 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 #3 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).

描述 服务器遇到一个意外的情况,阻止它完成请求。

出现问题的原因主要是出现在mapper.xml文件中,可能会有几个原因:
1、两个#写在了一起,会出现识别错误 (我的错误)

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set>
            <include refid="News_update"/>
        </set>
        where id=##{id}
    </update>

2、里面出现javaEE的注释/* */

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set> /*  */
            <include refid="News_update"/>
        </set>
        where id=#{id}
    </update>

3、#{id}被单引号盖住了(摘自网上被人的错误 )

<update id="updateById" parameterType="main.java.com.dy.domain.News">
        update news
        <set>
            <include refid="News_update"/>
        </set>
        where id='#{id}'
    </update>

以上各种细节错误可能都会导致SQL语句执行时出现错误,所以以后开发过程程中还是尽量细心一点。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值