springbatch使用记录

背景:并发抽取接口数据。通过ai生成后调试了老半天才能使,记录一下

主要是处理器Processor, 读取器Reader和写库用的Writer

使用了框架的Shell功能,挺强大的。如果要对接口读取的数据做过滤,可以增加执行参数,如:--skip-filter

  • 这个参数我是用在Processor中的,因为要对已经获取的数据进行过滤。但其中要注意的点就是需要再处理器中获取这个参数
java 复制代码
public class ExamReportItemProcessor implements ItemProcessor<ExamReportDto, ExamReportEntity> {

    @Autowired
    private InpatientValidationService inpatientValidationService;

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private boolean skipFilter = false;

    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {
        JobParameters jobParameters = stepExecution.getJobParameters();
        String skipFilterStr = jobParameters.getString("skipFilter");
        this.skipFilter = "true".equalsIgnoreCase(skipFilterStr);
    }

还要注意:并发执行命令需要用到注解 @StepScope,否则会陷入分批次拉数据却只调用一次的尴尬, 调了许久

java 复制代码
# 这是在BatchConfig.java中的配置
@Bean
@StepScope
 public ExamReportItemReader examReportItemReader() {
     return new ExamReportItemReader();
 }

 @Bean
 @StepScope
 public ExamReportItemProcessor examReportItemProcessor() {
     return new ExamReportItemProcessor();
 }

另外我是用cursor的auto模式调试的,出现问题就将问题和输入的命令进行反馈,经历了4-5次才能跑通了

放个私有的gitee地址

过程记录

bash 复制代码
# 使用curl检测接口,使用的POST格式,(接口每次只返回一页数据和总页数.为了方便,直接全部保存)
curl -X POST "http:xxxx" -H "Content-Type: application/json" -d '{"StartTime": "2025-01-01 00:00:00"....}'
# 使用json_pp美化json语句,挺方便,没有额外安装工具
echo '{"name":"john","age":30}' | json_pp!74
相关推荐
java水泥工4 小时前
网上摄影工作室|基于SpringBoot和Vue的网上摄影工作室(源码+数据库+文档)
数据库·vue.js·spring boot
jingfeng5144 小时前
MySQL库的操作(ubuntu)
数据库·mysql
奔跑吧邓邓子4 小时前
【C++实战(64)】C++ 邂逅SQLite3:数据库编程实战之旅
数据库·c++·sqlite·实战·sqlite3·数据库编程
Tony Bai10 小时前
【Go开发者的数据库设计之道】07 诊断篇:SQL 性能诊断与问题排查
开发语言·数据库·后端·sql·golang
cpsvps_net10 小时前
VPS服务器锁等待超时处理,如何有效解决数据库性能瓶颈
服务器·数据库·oracle
文火冰糖的硅基工坊13 小时前
[创业之路-653]:社会产品与服务的分类
大数据·数据库·人工智能
2351613 小时前
【MySQL】数据库事务深度解析:从四大特性到隔离级别的实现逻辑
java·数据库·后端·mysql·java-ee
脚踏实地的大梦想家13 小时前
【LangChain】P7 对话记忆完全指南:从原理到实战(下)
数据库·langchain
conkl13 小时前
Flask 与 MySQL 数据库集成:完整的 RESTful API 实现指南
数据库·mysql·flask