关于Expected one result (or null) to be returned by selectOne(), but found: 3。。。。异常

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

本人找了几个小时


如下:

- (13243 ms) - 2017-9-20 00:03:28[DEBUG](FrameworkServlet.java:976) Could not complete request
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364)



看看加红的代码,不是网上说的这个样,这样解决不了:如下----

看到标题就已经很明了了:

两种情况:

1.你想查询一条数据,但返回两条数据:

2.你想查询多条数据,但是前台限制只能查询一条

(1) 检查自己的数据sql语句写对没有(关于mybaties的sql操作自己百度)

(2) 查看mybaties的返回值(resultType或resultMap),可以返回list,map等数据

(3)  dao层接口要与mybaties中返回值和接收值都要保持一致

例:返回map数据


返回多条数据是多个Map,多个Map放在List中用List<Map<String,String>>接收返回数据

Mybatis返回的Map是这样的一种格式:Map<字段名称,字段值> 

一个Map<字段名,字段值>对象代表一行数据


其实是很简单的问题,那就是数据库,你的账户同字段的有多个,肯定登录不了




【问题解决】nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result 今天在调试项目的时候,控制台出现了如下的报错信息,从下面报错信息可以明白大致的意思是:出现了过多的结果返回值,只希望得到一个值,但是现在返回了2个。 阅读详情

相关推荐

多种方法解决Expected one result (or null) to be returned by selectOne(), but found: x 的错误

多种方法解决org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2或者Expected one result (or null) to be returned by getOne的错误。

念兮为美 7650

Expected one result (or null) to be returned by selectOne(), but found: 3报错解决方案

Expected one result (or null) to be returned by selectOne(), but found: 3

weixin_51821844的博客 1万+

解决MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException错误

多种方法解决org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2或者Expected one result (or null) to be returned by getOne的错误。

念兮为美 5312

 Expected one result (or null) to be returned by selectOne(), but found: 3

本人纯菜鸟, 刚刚开始学习,这个网站其实也是听老师提及到的 。 对于我这种初学者来说, 除了理解老师的代码以外 ,经常会遇到很多的错误, 今天就遇到了一个错误 ,其实很简单 ,想要分享一下 仅仅只想刚刚学习Java的同学百度的时候,能多一些思路 O(∩_∩)O哈哈~ 1.Expected one result (or null) to be returned by selectOne(), but found: 3 解决方法: 出现以上错误, 很大可能是你的SQL语句查询的结果应该返回一个集...

weixin_49698627的博客 1965

查询方法报错-运行时异常Expected one result (or null) to be returned by selectOne(), but found 3原因:多个返回却使用实体类接收

今天遇到个运行时报错,不仔细看还挺费时间的,标记这个异常,记录一下: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3 我的异常场景debug在一句查询上(红色框的);看了数据

SSHLY3的博客 2486

Expected one result (or null) to be returned by selectOne(), but found: 3

报这个错误的时候不要慌,首先他提醒的是我要一个对象他返回三个对象,这时把SQL语句改一下就行了 少了一个条件 这样就可以!

qq_58495578的博客 551

Expected one result (or null) to be returned by selectOne(), but found: (不一定是sql语句返回值类型dao层问题)

如标题所讲, Expected one result (or null) to be returned by selectOne(), but found: 。。 简单明了的报错,一般人在一般情况下想到的就是 1.查询一条数据,但返回多条数据: 2.查询多条数据,但是前台限制只能查询一条 从而回去检查相关的sql语句,sql语句中的返回值,相关的dao层代码。从而获取相关的解决办法...

FlyRman的博客 3203

TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2

标题:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2 报错原因:mapper层本该接收一个对象,但是执行该方法的sql后,查询出多个符合条件的对象,导致mybatis框架报错,无

qq_41203107的博客 1万+

Expected one result (or null) to be returned by selectOne(), but found: 5

Expected one result (or null) to be returned by selectOne(), but found: 5 通常如果出现了这个异常的,一般是mybatis的mapper.xml文件中的sql标签的返回值类型(resultType)为HashMap、并且sql语句没有条件指定,才导致的异常。 原因 因为HashMap本身是一个集合,可以存放多个元素。但是,...

qq_43489671的博客 3328

mybatis一对多映射时始终不能正确映射到实体类,报错:Expected one result (or null) to be returned by selectOne()but found:

写下这篇博客时真的是痛哭流涕啊,因为有个bug真的让我茶不思,饭不香一整天!那就是 TooManyResultsException: Expected one result (or null) to be returned by selectOne()but found:13 它的意思就是mybatis期待返回的是一条数据,但实际返回了多条数据。 下面看我的实体类代码,书和章节是一对多关系,所以...

qq_41536791的博客 4343

接口请求报异常Expected one result (or null) to be returned by selectOne(), but found multiple records

因为查出主键重复的数据了,然后调封装方法getOne就直接报异常

CSDN_C_66的博客 1811

mybatis报错:Expected one result (or null) to be returned by selectOne(), but found: 20

报错:      Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned b

潇洒哥的读书笔记 6万+

MyBatis Expected one result (or null) to be returned by selectOne(), but found问题解决

问题描述: org.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.exceptions.TooManyResultsException:Expectedoneresult(ornull)tobereturnedbyselectOne(),butfound:2 问题分析: 1、当前查询方法定义了只能返回一条数据,但是查询结果却返回了多条数据,导致报错。 ...

旭东怪的博客 8616

TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 7

严重: Servlet.service() for servlet [joshua] in context with path [/scotte] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested excepti...

700

Expected one result to be returned by selectOne,but found: 2

类型 异常报告 TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2 消息 Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooMa

XiaoFanMi的博客 2014

Java中Springboot项目执行sq查询时报错:Expected one result (or null) to be returned by selectOne(), but found: 2

Expected one result (or null) to be returned by selectOne(), but found: 2 我出现以上错误的原因是:在实现类中调用查询语句时,调用错误,本来想调用查询结果为1条的sql语句,结果调用了查询全部的sql语句,返回的结果超出了范围。 ...

JAVALearnerLJK的博客 1618

解决:TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found:

通过分析错误可知:需要的查询出一条数据,但是结果却大相径庭,出现的是多条结果(只要不是一条结果就是多条结果),从而应发了TooManyResultsException 错误。 错误截图: 由出现的事故来看,很有可能是 Sql 语句或者数据库方面的问题,从这个地方开始着手,分析我们的问题: 先看一下 resultType 是不是我们对应的数据类型: 你我的问题出现的方式可能不是一样的,所以先检查看看是不是你需要返回的数据类型,同时看看你的 dao 层 接口的返回值类型改了没有。 我的.

潘小蓝的博客 5万+

Expected one result (or null) to be returned by selectOne(), but found: 2

异常信息 04-Aug-2019 14:32:50.093 严重 [http-apr-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [springmvc] in context with path [] threw excep...

weixin_30475039的博客 193

mybatis:Expected one result (or null) to be returned by selectOne(), but found:

Expected one result (or null) to be returned by selectOne(), but found: 3 今天使用mybatis报了一个这个错,经过查询主要是查出数据和方法接收不一致导致的(我数据库语句是 查所有 User,但是方法名是 查一个 User不是List)如图: mapper文件的查询语句: 错误的方法: 正确的方法: ...

最秃不过程序员的博客 1842
上一篇: SSH必备知识点
下一篇: SSM知识点整理
libaxuann
博客等级 码龄10年 16粉丝 8原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值