解决使用mybatis取值,字段赋值错误的问题
使用mybatis取值,字段赋值错误
我在读取数据库的表信息时,出现了不同字段取值对应不上的情况,有些字段的赋值是错位置的,
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
BaseResultMap 里的字段对应是错误的,估计是Map里字段顺序的问题。改成了
<update id="updateByPrimaryKeySelective" parameterType="com.tour.info.admin.model.Template">
可以正确读取
另外还查知:
还有mybatis ,mapper.xml的各个字段的顺序是不影响赋值的,是自动对应的。
mybatis映射赋值失败
异常:TypeException: Could not set parameters for mapping
错误输出

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘pmNo’, mode=IN, javaType=class java.lang.String, 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.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
错误造成原因
在mybatis中SQL添加了注释

解决方法
将SQL中注释删除即可
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Java中StringBuilder与StringBuffer使用及源码解读
我们前面学习的String就属于不可变字符串,因为理论上一个String字符串一旦定义好,其内容就不可再被改变,但实际上,还有另一种可变字符串,包括StringBuilder和StringBuffer两个类,那可变字符串有什么特点,又怎么使用呢,接下来就请大家跟我一起来学习吧2023-05-05
java.lang.Runtime.exec() Payload知识点详解
在本篇文章里小编给大家整理的是一篇关于java.lang.Runtime.exec() Payload知识点相关内容,有兴趣的朋友们学习下。2020-03-03


最新评论