在写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删除

最后项目运行就没报错

发表回复

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