学无先后,达者为师

网站首页 java综合 正文

解决使用mybatis取值,字段赋值错误的问题_java

作者:是这耀眼的瞬间   更新时间: 2022-04-02 java综合

使用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中注释删除即可

原文链接:https://blog.csdn.net/Qiuzhongweiwei/article/details/74906104

栏目分类
最近更新