1. 问题描述
公司需要在凌晨0点定时post请求银行接口获取交易记录以用于在OA里面进行费用报销
2. 问题解决
使用SpringBoot的@Scheduled创建定时任务
// 每天凌晨0点执行一次
@Scheduled(cron = "0 0 0 * * ?")
private void getTransData() throws Exception {
String strDateFormat = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
String dateFormat = sdf.format(new Date());
System.out.println("--执行了--,日期是:" + dateFormat);
// bankDataService.insertTD();
}
修改系统时间测试
运行项目查看结果