完整報錯信息:
nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found:
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) ~[mybatis-spring-1.2.3.jar:1.2.3]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) ~[mybatis-spring-1.2.3.jar:1.2.3]
at com.sun.proxy.$Proxy10.selectOne(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165) ~[mybatis-spring-1.2.3.jar:1.2.3]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69) ~[mybatis-3.3.0.jar:3.3.0]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.3.0.jar:3.3.0]
at com.sun.proxy.$Proxy49.selectByPrimaryKey(Unknown Source) ~[na:na]
Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) ~[mybatis-3.3.0.jar:3.3.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) ~[mybatis-spring-1.2.3.jar:1.2.3]
... 35 common frames omitted
錯誤分析:
selectOne(), but found: 3;這一句理解就是在查詢的時候你查詢的是一個,但是數據有三條,然後mybatis拋出的異常信息,簡單話理解就是:
這種就是查詢到了三條數據,返回的是一個實體並不是一個List多條數據
解決方案:
在你的mapper接口中:
//flowHolidayNumberPojo queryTeacherFlowNumber(@Param("userId")String userId);
//改成這個
List<flowHolidayNumberPojo> queryTeacherFlowNumber(@Param("userId")String userId);