Expected one result (or null) to be returned by selectOne(), but found: 2
2017-07-14 18:52
477 查看
看到标题就已经很明了了:
两种情况:
1.你想查询一条数据,但返回两条数据:
2.你想查询多条数据,但是前台限制只能查询一条
(1) 检查自己的数据sql语句写对没有(关于mybaties的sql操作自己百度)
(2) 查看mybaties的返回值(resultType或resultMap),可以返回list,map等数据
(3) dao层接口要与mybaties中返回值和接收值都要保持一致
我项目中遇到的问题是将excel中数据录入到数据库中,但是要避免录入重复数据。所以要对每一列进行查重,查询搜索出的重复列可能是多条数据,但是在dao层中接收的返回值是单个对象,这与sql语句返回的对象数目矛盾,提示这个错误。
这时只需将dao层中方法的返回值类型改为能够接收多个对象的容器类(如list)就行了。
再次遇到这一问题:一定注意,如果返回多条数据,在dao层建议使用List<MusicDict>容器作为返回值,这样Impl中容易判断。
而且在xml语句中,返回值类型可以是resultMap="MusicDictMap",在resultMap中能手动配数据库表和实体类的映射。
两种情况:
1.你想查询一条数据,但返回两条数据:
2.你想查询多条数据,但是前台限制只能查询一条
(1) 检查自己的数据sql语句写对没有(关于mybaties的sql操作自己百度)
(2) 查看mybaties的返回值(resultType或resultMap),可以返回list,map等数据
(3) dao层接口要与mybaties中返回值和接收值都要保持一致
我项目中遇到的问题是将excel中数据录入到数据库中,但是要避免录入重复数据。所以要对每一列进行查重,查询搜索出的重复列可能是多条数据,但是在dao层中接收的返回值是单个对象,这与sql语句返回的对象数目矛盾,提示这个错误。
这时只需将dao层中方法的返回值类型改为能够接收多个对象的容器类(如list)就行了。
再次遇到这一问题:一定注意,如果返回多条数据,在dao层建议使用List<MusicDict>容器作为返回值,这样Impl中容易判断。
而且在xml语句中,返回值类型可以是resultMap="MusicDictMap",在resultMap中能手动配数据库表和实体类的映射。
相关文章推荐
- 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
- Expected one result (or null) to be returned by selectOne(), but found: 20
- Expected one result (or null) to be returned by selectOne(), but found: 4
- 关于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
- 错误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 returned by selectOne(), but found: 2
- 当Mybatis+sql遇到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: 20
- mybatis报错:Expected one result (or null) to be returned by selectOne(), but found: 20
- 遇到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: XX
- 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: 3
- 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
- Expected one result (or null) to be returned by selectOne(), but found: 2
- Expected one result (or null) to be returned by selectOne()
- one result (or null) to be returned by selectOne(), but found