Expected one result (or null) to be returned by selectOne(), but found: 2
Posted kcblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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中返回值和接收值都要保持一致
例:返回map数据
返回多条数据是多个Map,多个Map放在List中用List<Map<String,String>>接收返回数据
Mybatis返回的Map是这样的一种格式:Map<字段名称,字段值>
一个Map<字段名,字段值>对象代表一行数据
解决方法,改返回数据类型
以上是关于Expected one result (or null) to be returned by selectOne(), but found: 2的主要内容,如果未能解决你的问题,请参考以下文章
TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2(代
Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be
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 和 java.lang.UnsupportedOp
Expected one result to be returned by selectOne,but found: 2
问题解决nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result