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

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

前言

  小编最近在做项目的时候碰到了这么一个问题,“Expected one result (or null) to be returned by selectOne(), but found: 2” ,期望返回一个结果或者空,但是接收到了两个,然后很自然就会报错了。报错日志如下:
在这里插入图片描述
  小编这个问题发生在接收返回的数据的时候,查询是有结果的,只是接收的时候数据不匹配了,所以将接收的实体类型改了就好了,用list接收就没问题了
在这里插入图片描述
  问题解决

总结

  刚开始遇到的时候我也不知道,但是这东西是可以积累的,除了细心之外,对数据的把控程度也很重要,也要注意看错误日志,这样能够帮助我们更快的解决问题

mybatis报错:Expected one result (or null) to be returned by selectOne(), but found: 2 springboot集成mybatis报错: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: 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

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

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的翻译是: selectOne()应返回一个结果(或空值),但返回2个结果。 运行test文件时,程序报错“Expected one result (or null) to be returned by selectOne(), but found: 2”,在网上搜索查找了一番后,发现要查找的参数,在数据库里找到了多条数据的情况。但返回的时候,只能接收一个数据

m0_54066656的博客 4万+

Mybatis :Expected one result (or null) to be returned by selectOne(), but found: 2 直白解析

直白解析 Mybatis :Expected one result (or null) to be returned by selectOne(), but found: 2

sajiahenmang的博客 3537

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

java springBoot mybatis 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 errorExpected one result (or null) to be returned by selectOne(), but found: 2 解释: selectOne()应返回一个结果(或null),但找到:2 从解释可以看出返回值大于1,而只接收了一个,解决方法 在后面加limit分页 只限制一条数据。 postgreSql 后加 li

wuyuanshun的博客 858

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

在学习MyBatis的时候,简简单单的MyBatis+MySql的增删改查操作,但是却出了问题。 刚开始数据库只有一条数据的时候,岁月静好,一切看起来都那么的OJBK。但是,当我往数据库插入第二条数据的时候, 再次查询所有数据的时候, 却出现了Expected one result (or null) to be returned by selectOne(), but fo...

weixin_30444105的博客 310

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

selectOne查询一条记录,如果使用selectOne查询多条记录则抛出异常 org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2 at org.apache.ibatis.session....

lazy_cat_go的博客 818

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

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

有好久一段时间没写mybatis的xml了,出现这样的问题,写一下加深印象。 错误分析: 这个错误是因为在从数据库查出多条数据,但是接收的时候只显示一个。 解决方案: 举个例子说明问题                                                       SELECT IFNULL(id,1)  FROM shop

yanguo110的博客 8720

mybatis plus分页查询报错Expected one result (or null) to be returned by selectOne(), but found: 10

mybatis plus分页查询报错Expected one result (or null) to be returned by selectOne(), but found: 10

HumorChen的博客 872

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: 16怎么解决

遇到Expected one result (or null) to be returned by selectOne(), but found: 16怎么解决 这个说明获取到的值原本为1个,但是实际获取到了16条。 解决方案:查看SQL语句是否出现问题。 ...

baidu_38878945的博客 2万+

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万+

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...

702

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

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

本人找了几个小时 如下: - (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.except

libaxuann的博客 5052
上一篇: 软考总结
下一篇: java——Cannot resolve symbol...
评论 8
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值