xxl_job系列---【Glue(java)模式如何通过动态参数传参?】

1.编辑GLUE(Java)模式的定时任务

这里以传递json参数为例:
修改任务参数:{"startDate": "","endDate": "","desc": "入参日期格式:yyyyMMdd"}
保存。

2.编辑此定时任务的GLUE脚本

import添加:
import com.xxl.job.core.context.XxlJobHelper;
import cn.hutool.core.util.StrUtil;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

excute()方法里接收参数:

String jobParam = XxlJobHelper.getJobParam();
XxlJobHelper.log("自定义入参:"+jobParam);

String startDateStr = null;
String endDayStr = null;
if(!StrUtil.isEmptyIfStr(jobParam)){
  JSONObject jsonObject = new JSONObject(jobParam);
  startDayStr = jsonObject.getStr("startDate");
  endDayStr = jsonObject.getStr("endDate");
}

if(StrUtil.isEmptyIfStr(startDateStr) || StrUtil.isEmptyIfStr(endDateStr)){
  LocalDate todayDate = LocalDate.now();
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMMdd");
  startDateStr = todayDate.minusDays(2).format(formatter);
  endDateStr = todayDate.format(formatter);
}
...省略

posted on   少年攻城狮  阅读(180)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2020-01-07 Mysql系列---【在字符数组中查询某个字符串是否存在】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示