Cause: No type handler could be found to map the property 'reporter' to the colu

本文介绍了解决 MyBatis 在查询含有外键的主表时出现的错误:找不到类型处理器来映射属性到列的问题。通过使用 resultMap 的方式重新定义了查询结果的映射规则,成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[color=blue]在做根据ID查询一个带有外键的主表类时,如果在映射文件方法里返回结果使用相应类,则会报此种错误:[/color][color=darkred]Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler could be found to map the property 'reporter' to the column 'reporter'. One or both of the types, or the combination of types is not supported.[/color]
[color=red]
解决办法:使用resultMap。[/color]

[color=red]错误代码:[/color]

<select id="selectPetitonLetterById" parameterClass="int" resultClass="PetitionLetter">
select * from t_petitionletter where id = #id#
</select>


[color=red]正确代码:[/color]

<resultMap id="PetitionLetterResult" class="PetitionLetter">
<result property="id" column="id"/>
<result property="identifier" column="identifier"/>
<result property="reporter" column="reporter" select="selectReporter"/>
<result property="letterInformation" column="letterInformation" select="selectLetterInformation"/>
<result property="supervision" column="supervision" select="selectSupervision"/>
<result property="processFlow" column="processFlow" select="selectProcessFlow"/>
</resultMap>

<select id="selectPetitonLetterById" parameterClass="int" resultMap="PetitionLetterResult">
select * from t_petitionletter where id = #id#
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值