springboot 定时任务
时间参数参考:
https://www.cnblogs.com/Rain1203/p/11699420.html
1、程序开启入口
@SpringBootApplication @EnableScheduling public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
@EnableScheduling
2、定时任务
@Configuration @EnableScheduling public class DeleteCutImgSchedule { @Autowired private TpWisdomCutImgInfoMapper tpWisdomCutImgInfoMapper; @Scheduled(cron = "0/5 * * * * *") public void cron(){ DateUtils dateUtils = new DateUtils(); String beforeCustomDate = dateUtils.getBeforeCustomDate(2); System.out.println("================="); tpWisdomCutImgInfoMapper.deleteCutImgInfo(beforeCustomDate); System.out.println("+++++++++++++++++"); } }
吐槽:
希望Django工程师加强Schedule的开发,不能别SpringBoot落下