myBatis MybatisMapperMethod类 获取 Page对象的坑。。

探讨Mybatis中MapperMethod的实现细节,特别是在分页功能上,必须将Page对象作为第一个参数的原因。深入分析源码,揭示潜在的参数传递限制及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MybatisMapperMethod 源码:

 

获取传入的第一个对象,导致在使用分页时,必须将Page放在第一个参数位置。。。

 

这里需要循环一下 数组,不能为了方便 留下隐形的坑

org.mybatis.spring.MyBatisSystemException: null at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:97) ~[mybatis-spring-3.0.3.jar:3.0.3] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439) ~[mybatis-spring-3.0.3.jar:3.0.3] at jdk.proxy2/jdk.proxy2.$Proxy82.selectList(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-3.0.3.jar:3.0.3] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:119) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:84) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:152) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at jdk.proxy2/jdk.proxy2.$Proxy130.findZeroValueRecords(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-6.0.13.jar:6.0.13] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.0.13.jar:6.0.13] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.0.13.jar:6.0.13] at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.invoke(DynamicDataSourceAnnotationInterceptor.java:57) ~[dynamic-datasource-spring-4.3.0.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.13.jar:6.0 int offset = 0; int size = 1000; List<ElectricityDataHis> list = new ArrayList<>(); IPage<ElectricityDataHis> records; do { Page<ElectricityDataHis> pages = new Page<>(offset, size); // 第1页,每页10条 records = hisService.findZeroValueRecords(pages); records.getRecords().stream().forEach(record->{ // 获取前一个有效值 ElectricityDataHis lastValid = hisService.findLastValidBeforeTime( record.getTagId(), record.getRecordTime() ); if (lastValid != null) { // 生成修正后的新记录 record.setRecordValue(lastValid.getRecordValue()); record.setStatus(2);// 标记为已修正 // 写入修正记录(保留原始记录) list.add(record); } }); hisService.fixAllData(list); list.clear(); offset++; } while (! records.getRecords().isEmpty()); }
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值