Invalid bound statement (not found): cn.com.dao.UserDao.selectByUser
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)
at $Proxy22.selectByUser(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for cn.com.dao.UserDao.selectByUser
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)
... 34 more
我檢查了半天也沒看出什么問題來,后來把mapper的xml select 語句重寫。問題竟然好了。
出了這種問題:
1.
<mapper namespace="cn.com.dao.UserDao">
mapper的namespace寫的不對!
2.
UserDao的方法在UserDao.xml中沒有,然后執行UserDao的方法會報此錯
3. 刪除配置文件里中文的注釋,保存.
4. 如果你確認沒有以上問題,請任意修改下對應的xml文件,比如刪除一個空行,保存.問題解決...
2019-01-02 01:57:14,854 [http-nio-8081-exec-5] ERROR com.cloud.data.platform.service.impl.PortraitKpiServiceImpl - nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 13
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 13
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) ~[mybatis-spring-1.3.1.jar!/:1.3.1]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) ~[mybatis-spring-1.3.1.jar!/:1.3.1]
at com.sun.proxy.$Proxy111.selectOne(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) ~[mybatis-spring-1.3.1.jar!/:1.3.1]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82) ~[mybatis-3.4.4.jar!/:3.4.4]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) ~[mybatis-3.4.4.jar!/:3.4.4]
at com.sun.proxy.$Proxy116.queryOffLightsDuration(Unknown Source) ~[na:na]
at com.sengled.cloud.data.platform.service.impl.PortraitKpiServiceImpl.getOnDurationKpi(PortraitKpiServiceImpl.java:133) ~[data-platform-service-1.0.jar!/:1.0]
at sun.reflect.GeneratedMethodAccessor431.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_141]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_141]
...
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ~[mybatis-spring-1.3.1.jar!/:1.3.1]
... 114 common frames omitted
java用一個實體或者一個map接收數據,哪知數據表卻返回了多條數據而引發的TooManyResultsException,根據業務需要,只要一條數據,SQL應使用sum函數或者加group by 來聚合成一條數據!