我數(shù)據(jù)庫(kù)表的id是varchar類型,而已這條數(shù)據(jù)也是項(xiàng)目插入到數(shù)據(jù)庫(kù)的,但是在後麵查詢的時(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 cause
java.sql.SQLException: Invalid value for getInt() - 'x41D6z93'
這是錯(cuò)誤信息,以下是相關(guān)代碼
這是查詢映射代碼
我代碼在數(shù)據(jù)庫(kù)裏就能查詢出來(lái)
望各位看看
對(duì)了 model中 club中的id屬性是string的
ringa_lee
mapping的問(wèn)題:
<resultMap id="resultClubType" type="com.uiyllong.cims.model.ClubType">
<id column="id" jdbcType="INTEGER" property="id" />
<!-- 省略 -->
</resultMap>
<resultMap id="resultClub" 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的問(wèn)題(記得以後貼問(wèn)題把程式碼貼上來(lái),貼截圖讓人家怎麼拿你程式碼試,手敲嗎?):
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" />