解決使用mybatis取值,字段賦值錯(cuò)誤的問題
使用mybatis取值,字段賦值錯(cuò)誤
我在讀取數(shù)據(jù)庫的表信息時(shí),出現(xiàn)了不同字段取值對應(yīng)不上的情況,有些字段的賦值是錯(cuò)位置的,
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
BaseResultMap 里的字段對應(yīng)是錯(cuò)誤的,估計(jì)是Map里字段順序的問題。改成了
<update id="updateByPrimaryKeySelective" parameterType="com.tour.info.admin.model.Template">
可以正確讀取
另外還查知:
還有mybatis ,mapper.xml的各個(gè)字段的順序是不影響賦值的,是自動(dòng)對應(yīng)的。
mybatis映射賦值失敗
異常:TypeException: Could not set parameters for mapping
錯(cuò)誤輸出

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).
錯(cuò)誤造成原因
在mybatis中SQL添加了注釋

解決方法
將SQL中注釋刪除即可
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決springboot整合cxf啟動(dòng)報(bào)錯(cuò),原因是版本問題
這篇文章主要介紹了解決springboot整合cxf啟動(dòng)報(bào)錯(cuò),原因是版本問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07
idea啟動(dòng)多個(gè)SpringBoot服務(wù)實(shí)例的最優(yōu)解決方法
啟動(dòng)SpringBoot項(xiàng)目其實(shí)就是啟動(dòng)Tomcat等服務(wù)容器,只要這個(gè)端口不同就能啟動(dòng)多個(gè)服務(wù)實(shí)例了,本文主要介紹了idea啟動(dòng)多個(gè)SpringBoot服務(wù)實(shí)例的最優(yōu)解決方法,感興趣的可以了解一下2024-05-05
學(xué)習(xí)SpringMVC——國際化+上傳+下載詳解
本篇文章主要介紹了學(xué)習(xí)SpringMVC——國際化+上傳+下載,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。2016-12-12
Java中StringBuilder與StringBuffer使用及源碼解讀
我們前面學(xué)習(xí)的String就屬于不可變字符串,因?yàn)槔碚撋弦粋€(gè)String字符串一旦定義好,其內(nèi)容就不可再被改變,但實(shí)際上,還有另一種可變字符串,包括StringBuilder和StringBuffer兩個(gè)類,那可變字符串有什么特點(diǎn),又怎么使用呢,接下來就請大家跟我一起來學(xué)習(xí)吧2023-05-05
java.lang.Runtime.exec() Payload知識點(diǎn)詳解
在本篇文章里小編給大家整理的是一篇關(guān)于java.lang.Runtime.exec() Payload知識點(diǎn)相關(guān)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2020-03-03

