mybatis报错:Expected one result (or null) to be returned by selectOne(), but found: ...

问题引入:

今天在使用Mybatis查询数据库取值时,抛出了异常,异常信息如下:

Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: ...

尝试解决:

检查发现:

myabtis的xml配置bean数据库等均无错误,当 select返回单个结果集时,不会报错,多个结果集时就会导致报错。

mybatis和spring整合后,dao中的接口:

最终解决:

将上面截图中的代码改为如下:

问题完美解决.

总结:

由于只能返回一个对象的结果,会自动选择selectOne()方法,当返回到多个对象的结果集时报错。findHotsByAll是一个Hots类的bean无法接受多个结果集,则 改用List 就可以接受多个结果集.

猜你喜欢

转载自blog.csdn.net/qq_40820862/article/details/81974148
今日推荐