求助:Mybatis查询返回Map<String, Object> 报错
publicMap<String,Object>getMonitorParentCodeIsNull(){return(Map<String,Object>)monito...
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 展开
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 展开
1个回答
展开全部
好像是因为你用的是select *,结果有多行返回结果,但是你的Mapper里面返回是的Object。
要么返回List<Map<String,Object>>,要么用select top 1之类的
要么返回List<Map<String,Object>>,要么用select top 1之类的
追问
select top 1?我就是要查询出所有。top1取了没达到我想要的效果,,,请问有其他办法吗?
追答
Mapper里面返回List,就是说Mapper里面的方法声明是
public List
dao、service层也作相应修改,改为返回List<Map<String,Object>>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询