解決使用mybatis取值,字段賦值錯誤的問題
使用mybatis取值,字段賦值錯誤
我在讀取數(shù)據(jù)庫的表信息時,出現(xiàn)了不同字段取值對應(yīng)不上的情況,有些字段的賦值是錯位置的,
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
BaseResultMap 里的字段對應(yīng)是錯誤的,估計是Map里字段順序的問題。改成了
<update id="updateByPrimaryKeySelective" parameterType="com.tour.info.admin.model.Template">
可以正確讀取
另外還查知:
還有mybatis ,mapper.xml的各個字段的順序是不影響賦值的,是自動對應(yīng)的。
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中注釋刪除即可
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
idea啟動多個SpringBoot服務(wù)實例的最優(yōu)解決方法
啟動SpringBoot項目其實就是啟動Tomcat等服務(wù)容器,只要這個端口不同就能啟動多個服務(wù)實例了,本文主要介紹了idea啟動多個SpringBoot服務(wù)實例的最優(yōu)解決方法,感興趣的可以了解一下2024-05-05
學(xué)習(xí)SpringMVC——國際化+上傳+下載詳解
本篇文章主要介紹了學(xué)習(xí)SpringMVC——國際化+上傳+下載,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。2016-12-12
Java中StringBuilder與StringBuffer使用及源碼解讀
我們前面學(xué)習(xí)的String就屬于不可變字符串,因為理論上一個String字符串一旦定義好,其內(nèi)容就不可再被改變,但實際上,還有另一種可變字符串,包括StringBuilder和StringBuffer兩個類,那可變字符串有什么特點,又怎么使用呢,接下來就請大家跟我一起來學(xué)習(xí)吧2023-05-05
java.lang.Runtime.exec() Payload知識點詳解
在本篇文章里小編給大家整理的是一篇關(guān)于java.lang.Runtime.exec() Payload知識點相關(guān)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2020-03-03

