功能:
Springboot的定时任务,定时调用controller的接口
使用方法:
1.在启动类上添加注释@SpringBootApplication
@SpringBootApplication
@EnableScheduling
public class BooksApplication {
public static void main(String args[]){
SpringApplication.run(BooksApplication.class,args);
}
}
2.在controller类上添加注释@Component
@Component //定时任务注释
@RestController
@RequestMapping("/api/reader")
public class SysReaderController {
3.在需要调用的接口添加注释@Scheduled(initialDelay = 1000, fixedRate = 6000)
@Scheduled(initialDelay = 1000, fixedRate = 6000) //定时任务注释
@GetMapping("/count")
public ResultVo getCount(){
int count = sysReaderService.getCount();
return ResultUtils.success("查询成功",count);
}
注意事项:
需要调用的接口方法不能有参数
学习产出:
不断学习,不断积累,充实自己!