org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned b

mybatis报错:
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
在这里插入图片描述

mybatis异常:太多结果集异常。
就是说期望获得一个结果,但是却查询到了两个或多个。
比如根据用户名查询,结果表中有重复的用户名条目,返回的结果就是一个list,而不是一个对象。


解决办法:
例如:

//根据用户名查询
    public User getByUserName(String uname);

改为:

//根据用户名查询
    public List<User> getByUserName(String uname);

使得查询到的结果集返回值可以装得下。

猜你喜欢

转载自blog.csdn.net/qq_43598138/article/details/105801651