有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring boot如何在java中自动触发特定日期的事件来重置计数?

我试图更新每次点击按钮的次数。我使用的是弹簧靴和棱角形作为前端。我设法通过编程计算按钮点击次数并保存到数据库中。但我需要在每个月的第一天将这些计数重置为零。 我该怎么做

/** On what day of each month should the count be reset? 1..28 */
static final int DAY_OF_MONTH_TO_RESET_COUNT = 1;
/** In what time zone should above day-of-month be interpreted? */
static final ZoneId timeZone = ZoneId.of("Asia/Pontianak");

public static void resetIfDue() {
    // substitute reset_date from DB here
    LocalDate lastResetDate = LocalDate.of(2020, Month.SEPTEMBER, 24);

    LocalDate nextResetDate = lastResetDate.plusMonths(1)
                                .withDayOfMonth(DAY_OF_MONTH_TO_RESET_COUNT);
    LocalDate today = LocalDate.now(timeZone);
    // "not after today" means today or before today
    if (! nextResetDate.isAfter(today)) {
        System.out.println("Reset the count and update the reset_date in the database");
        updateClickCounts();

    }
}

这里有一个函数,我必须在哪个日期重置计数。它将调用updateClickCounts()函数,该函数包含更新查询。但我想触发事件,在每个月的第一天自动调用resetIfDue()。我该怎么做?我不熟悉事件触发器,这就是为什么我不理解它是如何工作的


共 (0) 个答案