在使用mybatis进行集合查询时,查询指定字段时Mapper文件中的resultType不可以使用java.util.List,否则后台后报Cause: java.lang.UnsupportedOperationException异常。

如下代码:

 <select id="selectByBookId" resultType="java.lang.Long" parameterType="java.lang.Long">
        select id from `demo` where 1 = 1 and id = #{id,jdbcType=BIGINT}
    </select>

这里查询的是ID,则需要指定resultType为java.lang.Long

如指定resultType为java.util.List会报如下错误:

### Error querying database.  Cause: java.lang.UnsupportedOperationException
### The error may exist in file [/Users/user/Documents/demo/demo/target/classes/config/demoMapper.xml]
### The error may involve com.demo.demo.auxiliary.mapper.demoMapper.selectById
### The error occurred while handling results
### SQL: select id from `demo` where 1 = 1 and id = ?
### Cause: java.lang.UnsupportedOperationException