mybatis 返回List<String>

  • Post author:
  • Post category:其他




一、定义接口

public interface OraBackupInfoMapper 
{
    
    List<String> queryRacList();
}



二、开发*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="com.hidata.devops.selfops.mapper.OraBackupInfoMapper">
    <select id="queryRacList" resultType="java.util.List">
        SELECT DISTINCT rac_name FROM `ora_backup_info`
    </select>
</mapper>



三、执行测试类

@Test
    public void testApi(){
        List<String> racList = oraBackupInfoMapper.queryRacList();
        System.out.println(racList);
    }

运行结果报错:

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 [D:\workspace_ruoyi_code\branch\hipaas\paas\target\classes\mapper\oracle\OraBackupInfoMapper.xml]
### The error may involve com.hidata.devops.selfops.mapper.OraBackupInfoMapper.queryRacList
### The error occurred while handling results
### SQL: SELECT DISTINCT rac_name FROM `ora_backup_info`
### Cause: java.lang.UnsupportedOperationException

在这里插入图片描述



四、解决办法

将resultType=“java.util.List” 修改为 resultType=“String”

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hidata.devops.selfops.mapper.OraBackupInfoMapper">
    <select id="queryRacList" resultType="String">
        SELECT DISTINCT rac_name FROM `ora_backup_info`
    </select>
</mapper>



版权声明:本文为weixin_43860634原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。