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

因为查询到两条数据

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210530215147292.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1hpYW9GYW5NaQ==,size_16,color_FFFFFF,t_70)

原来的查询语句

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210530215203110.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1hpYW9GYW5NaQ==,size_16,color_FFFFFF,t_70)

解决方法

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

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210530215224847.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1hpYW9GYW5NaQ==,size_16,color_FFFFFF,t_70)

posted @ 2021-05-30 21:50  肖帆咪  阅读(1540)  评论(0)    收藏  举报