java.lang.UnsupportedOperationException] with root cause解决办法

在使用MyBatis进行数据库查询时,返回值通常设置为List类型,如List<String>。但在mapper文件中,resultType应设置为List内部的数据类型,如Atlas。错误地将resultType设为List会导致异常。正确示例:将resultType改为Atlas,与List<String>showAtlas(String telephone)方法对应,避免UnsupportedOperationException。

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

查找数据库的多个数据时,我们通常把函数返回值设为List格式,例如List<String> showAtlas(String telephone);
但,mapper文件里不应将resultType设为List,而应该设为List里的格式,如String。因为resultType指的是返回的List里的格式。

举例:

起初我将resultType设为List,即

<select id="showAtlas" parameterType="string" resultType="java.util.List">
        select * from atlas where telephone = #{telephone}
</select>

报错

java.lang.UnsupportedOperationException] with root cause

修改为

<select id="showAtlas" parameterType="string" resultType="com.hjl.boot.Entity.Atlas">
        select * from atlas where telephone = #{telephone}
</select>

其中com.hjl.boot.Entity.Atlas为List中数据类型。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值