求助:Mybatis查询返回Map<String, Object> 报错

public Map<String, Object> getMonitorParentCodeIsNull(){
return (Map<String, Object>)monitorDao.getMonitorParentCodeIsNull();
}

MonitorService ms = (MonitorService) context.getBean("monitorService");
Map<String, Object> map = ms.getMonitorParentCodeIsNull();

报如下错误。。
nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 4

好像是因为你用的是select *,结果有多行返回结果,但是你的Mapper里面返回是的Object。
要么返回List<Map<String,Object>>,要么用select top 1之类的追问

select top 1?我就是要查询出所有。top1取了没达到我想要的效果,,,请问有其他办法吗?

追答

Mapper里面返回List,就是说Mapper里面的方法声明是

public List

dao、service层也作相应修改,改为返回List<Map<String,Object>>

温馨提示:答案为网友推荐,仅供参考
相似回答