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

一、问题说明
转载自:https://www.cnblogs.com/zcleilei/p/6245617.html
具体错误提示如下:
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
看到标题就已经很明了了:
两种情况:
1、你想查询一条数据,但返回两条数据:
2、你想查询多条数据,但是前台限制只能查询一条
二、解决办法
1、检查自己的数据sql语句写对没有(关于mybatis的sql操作自己百度)
2、查看mybatis的返回值(resultType或resultMap),可以返回list,map等数据
3、dao层接口要与mybatis中返回值和接收值都要保持一致
例如:
返回map数据
返回多条数据是多个Map,多个Map放在List中用List>接收返回数据
Mybatis返回的Map是这样的一种格式:Map<字段名称,字段值> 
一个Map<字段名,字段值>对象代表一行数据 

你可能感兴趣的:(Mybatis)