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
相关推荐
哆啦A梦158813 小时前
Springboot整合MyBatis实现数据库操作
数据库·spring boot·mybatis
Zzzzmo_13 小时前
【MySQL】JDBC(含settings.xml文件配置/配置国内镜像以及pom.xml文件修改)
数据库·mysql
FirstFrost --sy14 小时前
MySQL内置函数
数据库·mysql
2401_8796938714 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
reembarkation14 小时前
光标在a-select,鼠标已经移出,下拉框跟随页面滚动
java·数据库·sql
eggwyw14 小时前
MySQL-练习-数据汇总-CASE WHEN
数据库·mysql
星轨zb15 小时前
通过实际demo掌握SpringSecurity+MP中的基本框架搭建
数据库·spring boot·spring security·mp
treacle田15 小时前
达梦数据库-配置本地守护进程dmwatcher服务-记录总结
数据库·达梦数据库·达梦数据库local数据守护
wyt53142915 小时前
Redis的安装教程(Windows+Linux)【超详细】
linux·数据库·redis
CeshirenTester15 小时前
从数据库到结构化用例:一套可落地的测试智能体架构
数据库·架构