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


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




