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);
}
...省略
愿你走出半生,归来仍是少年!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2020-01-07 Mysql系列---【在字符数组中查询某个字符串是否存在】