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返回的是集合中的元素类型,而不是集合本身

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/11/java-lang-unsupportedoperationexception-in-mybatis-solution/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
MyBatis之java.lang.UnsupportedOperationException异常解决方案
今天在使用MyBatis执行sql语句时,出现如下异常: 执行的sql语句配置信息如下: <select id="getColumnsByTableName" parameterType="Strin……
<<上一篇
下一篇>>
文章目录
关闭
目 录