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

posted @ 2020-02-08 20:04  未月廿三  阅读(1137)  评论(0编辑  收藏  举报