美文网首页
mybatis报错

mybatis报错

作者: 走走思 | 来源:发表于2017-08-25 18:13 被阅读0次

    今天在使用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<String> getColumnsByTableName(String tableName);
    给迷惑住了

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

    相关文章

      网友评论

          本文标题:mybatis报错

          本文链接:https://www.haomeiwen.com/subject/kfhpdxtx.html