解決使用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中注釋刪除即可
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Spring中的spring.factories文件用法(Spring如何加載第三方Bean)
這篇文章主要介紹了Spring中的spring.factories文件用法(Spring如何加載第三方Bean),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10SpringBoot + 微信公眾號JSAPI支付功能的實現
這篇文章主要介紹了SpringBoot + 微信公眾號JSAPI支付功能的實現,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03SpringBoot集成logback打印彩色日志的代碼實現
Logback是由log4j創(chuàng)始人設計的另一個開源日志組件,默認情況下,Spring?Boot會用Logback來記錄日志,并用INFO級別輸出到控制臺,本文給大家介紹了SpringBoot集成logback打印彩色日志,需要的朋友可以參考下2024-03-03