MyBatis之java.lang.UnsupportedOperationException異常解決方案,resultType導致的問題

今天在使用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返回的是集合中的元素類型,而不是集合本身

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章