mybatis取值字段赋值错误

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

mybatis取值字段赋值错误

是这耀眼的瞬间   2022-05-23 我要评论

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们