报错信息
2020-11-06 12:13:24.241 ERROR 179946 --- [http-nio-7001-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception[Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException] with root cause
org.mybatis.spring.MyBatisSystemException: null
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:81)
at sun.reflect.GeneratedMethodAccessor191.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
at com.sun.proxy.$Proxy163.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:167)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
原因分析
我遇到该报错的原因是,根据task_id查询task结果时,==单条查询返回了多条结果==。
解决方案
临时的解决方案是限制查询返回,即在查询语句末尾加了“ limit 1”
<select id="getTaskResultByTaskId" parameterType="java.lang.Integer" resultMap="taskResultDO">
select *
from ats_task_result
where task_id = #{taskId} limit 1
</select>
最终解决的办法是,存task结果时,先根据task id查询是否已经存在;如果已经存在则更新结果,否则插入新的数据