Mybatis TooManyResultsException: Expected one result (or null) to be returned by selectOne()
今天Mybatis报错
Mybatis TooManyResultsException: Expected one result (or null) to be returned by selectOne()
问题产生的位置
public T selectOneByExample(Object example){ return mapper.selectOneByExample(example); }
产生的原因:
想要获取一条数据,但是查询的结果为多条
解决的方法:
改成List<T>接收多条返回记录
public T selectOneByExample(Object example){ List<T> list = mapper.selectByCondition(example); if(list.size()>0){ return list.get(0); } return null; }