文章目录
mybatis plus分页查询报错Expected one result (or null) to be returned by selectOne(), but found: 10
报错信息
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 10
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy197.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:89)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:62)
at com.sun.proxy.$Proxy343.queryInspectOrderList(Unknown Source)
at com.sffix.recovery.storage.test.InspectControllerTest.test1(InspectControllerTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
mapper定义
/**
* 查询审单统计列表
* @param vo
* @return
*/
Page<UpDoorInspectionVO> queryInspectOrderList(@Param("vo") UpDoorInspectionSearchVO vo,@Param("page") IPage<UpDoorInspectionVO> page);
单元测试
@Test
public void test1(){
Page<UpDoorInspectionVO> page = new Page<>();
Page<UpDoorInspectionVO> upDoorInspectionVOIPage = recycleUpDoorInspectionsMapper.queryInspectOrderList(new UpDoorInspectionSearchVO(), page);
System.out.println(upDoorInspectionVOIPage.getRecords());
}
问题分析:
从报错栈去打开mybatis plus源码debug便知,在决定是否为分页时,判定条件里有第一个参数是否为IPage的实现类。
解决办法:
把IPage参数放在第一个参数位置就好了