在写javaweb项目时候发现报的这个错误

org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='brandName', 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 #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: 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 java.base of loader 'bootstrap')	

开始认为是sql问题仔细检查运行了我的sql

    <update id="updateBrand" parameterType="java.lang.Integer">
        update tb_brand set brand_name = #{brandName},company_name = #    {companyName},ordered=#{ordered},description=#{description},status=#{status} where id=#{id};
    </update>

发现sql没有问题,sql解析参数数量和匹配参数数量是一致的,后端servletdebug进入后发现确实是在执行sql时候报错,那么问题在哪里呢?

再看因为自己写的是修改,所以实际上parameterType的参数可以不传,但不知道为什么因为我在写mapper接口时候自动生成语句设置parameterType参数为java.lang.Integer所以在执行sql语句开始报500错误

解决办法

    <update id="updateBrand" parameterType="com.sujju.brand.pojo.Brand">
        update tb_brand set brand_name = #{brandName},company_name = #{companyName},ordered=#{ordered},description=#{description},status=#{status} where id=#{id};
    </update>

将parameterType设置自己实体类路径或者把parameterType删除

最后项目运行就没报错

原文地址:https://blog.csdn.net/qq_64373632/article/details/124235786

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_37302.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注