MyBatis之java.lang.UnsupportedOperationException异常解决方案

今天在使用MyBatis执行sql语句时,出现如下异常:

执行的sql语句配置信息如下:

<select id="getColumnsByTableName" parameterType="String" resultType="java.util.List">
    select t.column_name from user_tab_columns t where t.tableName=#{tableName,jdbcType=VARCHAR}
</select>

对应的dao接口代码为:

public List<String> getColumnsByTableName(String tableName);

应该改为:

<select id="getColumnsByTableName" parameterType="String" resultType="String">      
    select t.column_name from user_tab_columns t where t.tableName=#{tableName,jdbcType=VARCHAR}
</select>

原因就在于resultType代表的是List中的元素类型,而不应该是List本身,究其原因就在于被dao中的方法声明

public List getColumnsByTableName(String tableName);

给迷惑住了

切记:resultType返回的是集合中的元素类型,而不是集合本身

上一篇 MyBatis根据List批量查询List结果
下一篇 Spring Boot中MyBatis打印sql
目录
文章列表
1 微信开发技术整理
微信开发技术整理
2
支付宝和微信的JSSDK发起支付
支付宝和微信的JSSDK发起支付
3
Grafana插件扩展之Clock安装
Grafana插件扩展之Clock安装
4
Moss(莫斯) - Spring Cloud体系的服务治理平台
Moss(莫斯) - Spring Cloud体系的服务治理平台
5
Python判断是否为数字
Python判断是否为数字
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。