我数据库表的id是varchar类型,而已这条数据也是项目插入到数据库的,但是在后面查询的时候就出现了一下错误。
严重: 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'
这是错误信息,以下是相关代码
这是查询映射代码
我代码在数据库里就能查询出来
望各位看看
对了 model中 club中的id属性是string的
巴扎黑2017-04-18 10:58:22
mapping problem:
<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 and resultClubTypeid
属性对应的列名都是id
, and the type of one of them is int.
SQL problems (remember to post questions and post the code later, and post screenshots so that people can try your code, can you type it by hand?):
select club_t.id, ...
club_type_t.id
....
This query result has two columnsID
.
The solution is very simple, set an alias for the club_type_t column, such as adding a prefix:
select club_t.id, ...
club_type_t.id ct_id, club_type_t.typeName ct_type_name
Use columnPrefix of mybatis:
<association property="clubType"
columnPrefix="ct_"
notNullColumn="ct_id"
resultMap="resultClubType" />