mybatis报错:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exception

简介: 接口配置:package mybatis.mapper;import java.util.List;public interface TestMapper { public List selectAllInfo();}mapper.

接口配置:

package mybatis.mapper;

import java.util.List;

public interface TestMapper {
	public List<String> selectAllInfo();
}

mapper.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="mybatis.mapper.TestMapper">

  <select id="selectAllInfo" resultType="java.util.List">
    SELECT
          ID
    FROM TEST
  </select>

</mapper>

在使用junit测试时出现以下错误:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.UnsupportedOperationException
### The error may exist in mybatis/mapper/TestMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT           ID     FROM TEST
### Cause: java.lang.UnsupportedOperationException

大致意思就是设置的参数有问题。

问题原因:

原因就在于mapper.xml的resultType代表的是List中的元素类型,而不应该是List本身,所以修改mapper.xml文件为:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="mybatis.mapper.TestMapper">

  <select id="selectAllInfo" resultType="java.lang.String">
    SELECT
          ID
    FROM TEST
  </select>

</mapper>








目录
相关文章
|
2天前
|
Java
SpringBoot启动报错org.apache.catalina.LifecycleException
SpringBoot启动报错org.apache.catalina.LifecycleException
11 0
|
2天前
|
Java Maven
Maven配置以及IDEA设置(Cannot resolve plugin org.apache.maven.plugins:报错)
Maven配置以及IDEA设置(Cannot resolve plugin org.apache.maven.plugins:报错)
18 1
|
2天前
|
Java Apache Spring
Spring BeanUtils与Apache BeanUtils提供基本属性复制,适用于简单需求
【5月更文挑战第4天】Spring BeanUtils与Apache BeanUtils提供基本属性复制,适用于简单需求;Cglib BeanCopier用于转换为Cglib代理对象;Apache PropertyUtils处理属性操作;Dozer支持复杂对象映射。选择工具取决于具体需求,如需精细控制或对象映射,推荐Dozer或Apache PropertyUtils。Apache BeanUtils可能因潜在的封装性破坏被禁用。
24 3
|
2天前
|
JSON Java Apache
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient
|
2天前
|
前端开发 Java 数据库连接
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
10 0
|
前端开发 Java Spring
阿里四面:Spring Exception的原理你精通了吗?(下)
阿里四面:Spring Exception的原理你精通了吗?
96 0
阿里四面:Spring Exception的原理你精通了吗?(下)
|
设计模式 前端开发 Java
阿里四面:Spring Exception的原理你精通了吗?(上)
阿里四面:Spring Exception的原理你精通了吗?
124 0
阿里四面:Spring Exception的原理你精通了吗?(上)
|
2天前
|
Java 应用服务中间件 Maven
SpringBoot 项目瘦身指南
SpringBoot 项目瘦身指南
57 0
|
2天前
|
缓存 安全 Java
Spring Boot 面试题及答案整理,最新面试题
Spring Boot 面试题及答案整理,最新面试题
138 0
|
2天前
|
存储 JSON Java
SpringBoot集成AOP实现每个接口请求参数和返回参数并记录每个接口请求时间
SpringBoot集成AOP实现每个接口请求参数和返回参数并记录每个接口请求时间
48 2

推荐镜像

更多