java - Mybatis查詢數(shù)據(jù)庫時(shí)出現(xiàn)查詢getInt()的錯(cuò)誤
問題描述
我數(shù)據(jù)庫表的id是varchar類型,而已這條數(shù)據(jù)也是項(xiàng)目插入到數(shù)據(jù)庫的,但是在后面查詢的時(shí)候就出現(xiàn)了一下錯(cuò)誤。
嚴(yán)重: Servlet.service() for servlet [SpringMVC] in context with path [/cims-ssm] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column ’id’ from result set. Cause: java.sql.SQLException: Invalid value for getInt() - ’x41D6z93’; SQL []; Invalid value for getInt() - ’x41D6z93’; nested exception is java.sql.SQLException: Invalid value for getInt() - ’x41D6z93’] with root causejava.sql.SQLException: Invalid value for getInt() - ’x41D6z93’
這是錯(cuò)誤信息,以下是相關(guān)代碼

這是查詢映射代碼
我代碼在數(shù)據(jù)庫里就能查詢出來

望各位看看對(duì)了 model中 club中的id屬性是string的
問題解答
回答1:mapping的問題:
<resultMap type='com.uiyllong.cims.model.ClubType'> <id column='id' jdbcType='INTEGER' property='id' /> <!-- 省略 --></resultMap><resultMap type='com.uiyllong.cims.model.Club'> <id column='id' jdbcType='VARCHAR' property='id' /> <!-- 省略 --> <association column='club_type_id' jdbcType='INTEGER'property='clubType' javaType='com.uiyllong.cims.model.ClubType'resultMap='resultClubType' /></resultMap>
resultClub和resultClubType的id屬性對(duì)應(yīng)的列名都是id,而其中一個(gè)的類型是int。
sql的問題(記得以后貼問題把代碼貼上來,貼截圖讓人家怎么拿你代碼試,手敲嗎?):
select club_t.id, ...club_type_t.id....
這個(gè)查詢結(jié)果有兩列ID。
解決辦法很簡(jiǎn)單,把 club_type_t 列設(shè)置別名,比如添加前綴:
select club_t.id, ...club_type_t.id ct_id, club_type_t.typeName ct_type_name
利用mybatis的columnPrefix:
<association property='clubType' columnPrefix='ct_' notNullColumn='ct_id' resultMap='resultClubType' />
相關(guān)文章:
1. docker綁定了nginx端口 外部訪問不到2. dockerfile - 為什么docker容器啟動(dòng)不了?3. git - webstorm窗口中左側(cè)列表的文件名顏色怎么修改4. android權(quán)限被第三方安全軟件禁止,如何獲取該權(quán)限狀態(tài)5. javascript - 深夜被問題困擾求解惑,rn的API之PermissionsAndroidd的問題6. javascript - 最近用echarts做統(tǒng)計(jì)圖時(shí)遇到兩個(gè)問題!!7. mysql - 我的myeclipse一直連顯示數(shù)據(jù)庫連接失敗,不知道為什么8. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?9. tp 6.0 數(shù)據(jù)查詢,求教!10. mysqld無法關(guān)閉

網(wǎng)公網(wǎng)安備