(1)引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
(2)配置定时器任务
@Component //交于spring容器该类对象
public class QuarzConfig {
@Autowired
private StudentMapper studentMapper;
@Scheduled(cron = "0/5 * * * * ? ")
public void show(){
//1.查询过期的订单
List<Student> students = studentMapper.selectList(null);
System.out.println(students);
//2.删除过期的订单
}
}
(3)开启定时器注解驱动在启动类加上注解@EnableScheduling
@SpringBootApplication
@MapperScan(basePackages = "com.cmx.mapper")
@EnableScheduling //开启定时器注解
public class Qy163Springboot03Application {
public static void main(String[] args) {
SpringApplication.run(Qy163Springboot03Application.class, args);
}
}