package com.ljl.controller;
import com.ljl.service.admin.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.ParseException;
@Component
public class TimeTask {
@Autowired
private DemoService demoService;
//编写具体的定时任务组件(@Component注解),并且在需要定时调度的方法上添加@Scheduled触发器
//每隔5秒执行一次:*/5 * * * * ?
//每隔1分钟执行一次:0 */1 * * * ?
//每天23点执行一次:0 0 23 * * ?
//每天凌晨1点执行一次:0 0 1 * * ?
//每月1号凌晨1点执行一次:0 0 1 1 * ?
//每月最后一天23点执行一次:0 0 23 L * ?
//每周星期天凌晨1点实行一次:0 0 1 ? * L
//在26分、29分、33分执行一次:0 26,29,33 * * * ?
//每天的0点、13点、18点、21点都执行一次:0 0 0,13,18,21 * * ?
@Scheduled(cron = "0 */10 * * * ?")
public void ssgx() throws ParseException {
// System.out.println("hello");
demoService.upStatus();//更新状态的业务逻辑
}
}
启动类加入注解:
import org.springframework.scheduling.annotation.EnableScheduling;
//这里开启定时任务
@EnableScheduling