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

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

今天项目报了标题上这个错,花了不少时间解决,现在分享下过程,希望遇到类似问题的朋友能节省点时间。
这里写图片描述

根据错误提示的意思,是返回值的问题,于是检查了几遍mapper,确认sql语句无误后,又检查了dao中的返回值类型,也正确。

那么问题来了,返回值类型正确,也不是resultmap,resulttype的问题,难不成是Mybatis哪里配置出错了?可是我明明之前都还正常。

百思不得姐的时候,找了大牛请教,大牛看了一会发现了端倪,原来是数据库中,我的测试数据没有做验证…….导致了查询到多条相同数据,而我原来的需求是查到一条….
这里写图片描述

如果你也遇到了这个问题,在确认完上面的内容后,希望不是数据库的重复数据引起的,如果也是,咱们蠢到一块了#35

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

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

看到标题就已经很明了了: 两种情况: 1.你想查询一条数据,但返回两条数据: 2.你想查询多条数据,但是前台限制只能查询一条 (1) 检查自己的数据sql语句写对没有(关于mybaties的sql操作自己百度) (2) 查看mybaties的返回值(resultType或resultMap),可以返回list,map等数据 (3) dao层接口要与mybaties中返回值和接收值都要...

weixin_30439067的博客 4192

解决: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的问题解决方法

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

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

反射练习错误nested exception is Expected one result (or null) to be returned by selectOne(), but found: 20

练习反射的时候获取数据库中数据,直接报错了 mapper.xml配置文件是这样婶的 将数据直接存在map中,这样我再使用反射获取数据 错误原因,多条数据返回的是list类型,但是我给自定义返回的是Map,这样就可以练习自己的反射 解决方法:查询某一条数据,或者返回结果为List 如果必须要返回时Map,像我一样要用Map就将map放在list中 如 List<Map<S...

snack_TC_dora的博客 422

2021-04-20Expected one result(or null) to be returned by selectOne(),but found :45 idea 控制台报错!!

Expected one result(or null) to be returned by selectOne(),but found :48 你查下的不是一条数据,是48条数据 返回多条数据是多个map 多个map 用List<Map<String,Object> > 来接收多条数据;

weivi001的专栏 280

Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be

1、错误描述2016-05-16 11:16:36,750 [http-8080-exec-10] DEBUG enter cache org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one

游海东的技术专栏 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 <resultMap id="classesMap" type="cn.jam.entity.Classes"> <id column="c.id" property="id"/> <result column="c.name

qq_33954947的博客 4972

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

mybatis一对多映射 完美解决Expected one result (or null) to be returned by selectOne(), but found:

今天在进行mybatis学习时 出现了上述错误 在网上看了n篇文章都没有解决 下图是我查询用到的两个表 其中student表中的tid和teacher表中的id通过外键链接​ 在我的xml文件中 我刚开始是这么进行查询的 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://myb...

TIANJIAWEN的博客 1万+

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

123 public Object execute(SqlSession sqlSession, Object[] args) { Object result; switch (command.getType()) { case INSERT: { Object param = method.convertArgsToSqlCommandParam(args); result = rowCountResult(sqlSessio...

zhangm2020的博客 1938

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: 2

这个问题同样是在前后端交换数据的时候遇到的一个问题,然后我通过有道翻译给他翻译了一下: 刚开始看到这个对于新手小白来说可能还不能准确的定位到自己的错误,但是这个错误很明显就是在告诉我们: 你想查询多条数据,但是前台限制只能查询一条 这个错误在刚开始并没有出现,是因为我们刚开始的时候可能只是为了测试在数据库中只插入了一条数据,但是随着业务的增加,我们在数据库中加入了新的数据,但是同样的后端...

立志欲坚不欲锐,成功在久不在速度 2万+

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

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

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Ma...

最好的时光里 2293
上一篇: checkbox全选失败(第三次全选)
robertlee000
博客等级 码龄10年 1粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值