Mybatis-Mapper.xml配置查询结果集到List遇到的问题

Mapper.xml配置:

<select id="selectSidlv3" resultType="java.util.List">
    select sid_lv3 as sid3 from table1 where sid_lv3 is not null and sid_lv3 != '';
</select>

Mapper类:

public interface TableMapper {
     //查询sid_lv3
    List<String> selectSidlv3();
}

注意上面XML配置的resultType,如果写成java.util.List的话会出现以下异常:

严重: Servlet.service() for servlet [appServlet] in context with path [/test] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.UnsupportedOperationException
### The error may exist in file [TableMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select sid_lv3 as sid3 from table where sid_lv3 is not null and sid_lv3 != '';
### Cause: java.lang.UnsupportedOperationException] with root cause
java.lang.UnsupportedOperationException
	at org.apache.ibatis.reflection.wrapper.CollectionWrapper.findProperty(CollectionWrapper.java:42)
	at org.apache.ibatis.reflection.MetaObject.findProperty(MetaObject.java:86)

如果写成java.lang.String的话,则不会出现问题

至于什么原因,有网上说的是MyBatis会默认把查出来的结果按String类型分割,成为List,是不是这样的情况我也不清楚。

转载于:https://my.oschina.net/wliming/blog/708182

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值