【问题解决】nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result

简介: 【问题解决】nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result

项目场景

今天在调试项目的时候,控制台出现了如下的报错信息,从下面报错信息可以明白大致的意思是:出现了过多的结果返回值,只希望得到一个值,但是现在返回了2个。

\[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kHr8bJ3j-1677378165143)(%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF.image/image-20230224212340187.png)\]


问题描述

通过控制台打印的SQL,在数据库里面执行,显然出现两个结果返回值。

select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark from sys_post where post_code = 'zongjingli';

\[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1dlQjKtn-1677378165144)(%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF.image/image-20230224203155879.png)\]

再来看看我们定义的接口是怎样的?

SysPostMapper.java

SysPost selectPostByPostCode(String postCode);

SysPostMapper.xml

<select id="selectPostByPostCode" parameterType="String" resultMap="SysPostResult">
         <include refid="selectPostVo"/>
      where post_code = #{postCode}
</select>

原因分析

通过SQL查询出来的结果用于接收的是单个对象,但sql查询出来的结果却是一个列表(多个) 导致无法接收所有的查询结果值。


解决方案

下面给予了两种解决方案:

  • 把Mybatis对应的mapper接口的返回值修改为List
List<SysPost> selectPostByPostCode(String postCode);
  • 根据业务场景对查询SQL语句做返回数量的限制
select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark from 
sys_post where post_code = 'zongjingli' limit 1;
相关文章
|
Java Apache Maven
【异常解决】Handler dispatch failed;nested exception is java.lang.NoClassDefFoundError: org/apache/common
【异常解决】Handler dispatch failed;nested exception is java.lang.NoClassDefFoundError: org/apache/common
7844 0
|
Java 数据库连接 mybatis
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException:
Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException:
|
Java 数据库连接 mybatis
【已解决】nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘qcBizname‘ not found
【已解决】nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘qcBizname‘ not found
1003 0
|
前端开发 Java 数据库连接
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
557 1
|
Oracle 关系型数据库 数据库
实时计算 Flink版操作报错合集之执行Flink job,报错“Could not execute SQL statement. Reason:org.apache.flink.table.api.ValidationException: One or more required options are missing”,该怎么办
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
968 0
|
Java Spring
上传文件出现 aximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.
上传文件出现 aximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.
228 0
|
Java 数据库连接 mybatis
【Mybatis异常】nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter
【Mybatis异常】nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter
1965 0
|
SQL Java 数据库连接
nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘‘ not found. Ava
用mybatis写注解SQL的执行报错,这个报错有很多原因就不说了,说一下我的问题 同一个mapper中方法有重名的,虽然编译没报错,相当于重载了,但是执行的时候就报错了 方法写的太多了都没注意
|
9月前
|
存储 人工智能 大数据
The Past, Present and Future of Apache Flink
本文整理自阿里云开源大数据负责人王峰(莫问)在 Flink Forward Asia 2024 上海站主论坛开场的分享,今年正值 Flink 开源项目诞生的第 10 周年,借此时机,王峰回顾了 Flink 在过去 10 年的发展历程以及 Flink社区当前最新的技术成果,最后展望下一个十年 Flink 路向何方。
671 33
The Past, Present and Future of Apache Flink

推荐镜像

更多