controller层定时任务

@RestController
@RequestMapping("/expenseList")
@Slf4j
@Component
@Configuration      //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class ExpenseListController {

    //生成费用表
    //1.定时生成
    @Scheduled(cron = "0 0 0 */1 * ?")
    //2.直接指定时间间隔,例如:5秒
    //@Scheduled(fixedRate=*60*1000)
    public ResultModel productExpenseTable() {
        //1.获取当前日期
        log.info("=====自动执行生成费用表========{}", LocalDateTime.now());
        LocalDate now = LocalDate.now();
        writeExpenseList(now);
        return new ResultModel(ResultModel.SUCCESS, LocalDateTime.now()+"自动生成费用成功!!");
    }

}

  

猜你喜欢

转载自www.cnblogs.com/ynhk/p/11525412.html