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
相关推荐
Data_Journal17 小时前
如何使用cURL更改User Agent
大数据·服务器·前端·javascript·数据库
Python私教18 小时前
GenericAgent PySide6 桌面应用深度解析:悬浮按钮 + 聊天面板的原生 Qt 方案
开发语言·数据库·qt
phenhorlin18 小时前
我做了个工具,让切换 Homebrew 镜像像切 npm 源一样简单
后端·shell
byoass18 小时前
企业云盘与设计软件深度集成:AutoCAD/Revit/SolidWorks插件开发与API集成实战
服务器·网络·数据库·安全·oracle·云计算
爬山算法19 小时前
MongoDB(113)如何使用第三方工具进行MongoDB监控?
数据库·mongodb
早日退休!!!20 小时前
大模型推理瓶颈七层分析模型
java·服务器·数据库
大山同学20 小时前
claudecode精炼版-CoreCoder
数据库·人工智能·claude code·corecoder
of Watermelon League20 小时前
5、使用 pgAdmin4 图形化创建和管理 PostgreSQL 数据库
数据库·postgresql
Dontla21 小时前
Python asyncpg库介绍(基于Python asyncio的PostgreSQL数据库驱动)连接池、SQLAlchemy
数据库·python·postgresql
俺不要写代码21 小时前
数据库:DQL
数据库·sql·mysql