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

Posted 肖帆咪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.TooManyResultsException: Expected one result (or null) to 
be returned by selectOne(), but found: 2

描述

服务器遇到一个意外的情况,阻止它完成请求。

例外情况

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is 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
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119

org.apache.ibatis.exceptions.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

因为查询到两条数据

在这里插入图片描述

原来的查询语句

在这里插入图片描述

解决方法

添加查询的用户的id,会自动将多条数据的同一用户封装到一个对象中
将id查询出来并映射到对象中

在这里插入图片描述

以上是关于TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2(代的主要内容,如果未能解决你的问题,请参考以下文章

org.apache.ibatis.exceptions.toomanyresultsexception是啥报错

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

mybatis-异常模块

查询测试程序中的selectOne和selectList函数

五MyBatis各种查询功能

sql查询一条数据,返回了两条数据idea报错