在使用mybatis、以及其分页插件pagehelper时,原本的一个selectOne的sql语句被莫名(原因未知)的加上了分页相关,引起如下异常:

exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 5
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 5
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy192.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)
at com.sun.proxy.$Proxy204.findOne(Unknown Source)
at sun.reflect.GeneratedMethodAccessor578.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:84)

Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 5
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:81)
at sun.reflect.GeneratedMethodAccessor526.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)
... 203 common frames omitted

暂定解决办法如下:

import com.github.pagehelper.SqlUtil;

SqlUtil.clearLocalPage();  //在selectOne 代码逻辑之前加上此行代码   暂时解决上面的问题,暂时还清楚会引起其他什么问题?如有知道的,请留言一起讨论分析

参照博客:

Mybatis分页插件PageHelper原理_xiaoxsen的博客-CSDN博客

解决办法(作用是手动清理 ThreadLocal 存储的分页参):

5.0及以后版本,调用PageHelper.clearPage();
低于5.0版本,调用 SqlUtil.clearLocalPage();
————————————————
版权声明:本文为CSDN博主「xiaoxsen」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiaoxsen/article/details/104019062

最新文章

  1. Spark ZooKeeper数据恢复
  2. ecshop二次开发 商品分类描述编辑框
  3. 【转】 全世界最短的IE判定
  4. SqlServer数据库字典--索引.sql
  5. android xutils
  6. POJ 1037 (计数 + DP) 一个美妙的栅栏
  7. lucene4入门(3)琐记
  8. .net之页面生面周期
  9. 删除“自豪的采用wordpress”
  10. SPFA求最短路——Bellman-Ford算法的优化
  11. Spring 开发常见问题
  12. Docker 网络背后的原理探索
  13. 洗礼灵魂,修炼python(37)--面向对象编程(7)—了解魔法方法
  14. MySQL中几个关于时间/时区的变量
  15. Deep Learning for NLP
  16. (转)处理SQL中的异常并记录错误日志
  17. C#实现语音朗读功能
  18. Linux设备驱动剖析之SPI(二)
  19. 【quickhybrid】JS端的项目实现
  20. MyTalkStuffHomeIcon-2

热门文章

  1. [python] Python二维码生成器qrcode库入门
  2. YMOI 2019.6.8
  3. 刷题笔记——3002.买图书 & 2763.计算(a+b)/c的值
  4. bugku-source-wp详解
  5. Java入门与进阶P-4.3+P-4.4
  6. 如何又快又好实现 Catalog 系统搜索能力?火山引擎 DataLeap 这样做
  7. ADC-单通道DMA到多通道DMA ADC采集修改事项
  8. 记录一次排查log4cxx库按照日期回滚,不创建新目录的BUG
  9. DataGrid 设置某列可见或只读
  10. 通过pdf模板,填充内容,生成pdf文件---JAVA