在写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解析参数数量和匹配的参数数量是一致的,后端servlet用debug进入后发现确实是在执行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删除
最后项目运行就没报错了
在写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
错误是这样说的:
原因:org.apache.ibatis.type。TypeException:无法设置映射参数:ParameterMapping{property=‘username’, mode=IN, javaType=class java.lang。
错点::ParameterMapping
就是下面代码里的parameterType这个参数写错了
parameterType在...
配置并执行对象到对象的映射。
为现代世界编写的软件涉及在层之间传递对象。 跨层时,对象的值将复制到其他对象,通常是为了避免跨层公开实现细节。 一个示例可能是根据从数据层返回的数据对象为UI创建表示对象。 您可能最终会编写如下所示的代码:
Presentation p = new Presentation();
p.UserName = user.Name;
p.AccountType = user.Type;
// ... 40 other properties ..
编写此代码可能很乏味,甚至可能需要重复。 TypeMapping库旨在通过允许您在一个位置配置一个映射并根据需要多次引用它来简化对象之间的映射。
DefineMap.From<User>().To<Presentation>()
.Map(user => user.Name, p => p.Use
Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法
一、问题描述
写好配置文件用JUnit进行测试,一运行就报错:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.fendo.entity.Person with invalid ty