简体   繁体   English

如何限制方法,使其仅在调用时仅在特定日期运行?

[英]How do I restrict a method so that it will only run on certain days if called?

I want to restrict a method to only be executable on weekdays.我想将一种方法限制为只能在工作日执行。 Is there a spring annotation that would allow for this?是否有允许这样做的 spring 注释? Im trying to avoid writing a method that just checks the day of the week and exits.我试图避免编写一个只检查星期几并退出的方法。

I don't think there's any comment to check the day of the week in the spring.我认为没有任何评论可以检查 spring 中的星期几。

You may need to use the following methods:您可能需要使用以下方法:

public void checkDate() {
    
    LocalDate localDate = LocalDate.now();
    
    DayOfWeek dayOfWeek = localDate.getDayOfWeek();
    
    if(dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) {
        // ...do something
    }
    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Mockito,如何验证方法是否具有某个参数? - Using Mockito, how do I verify a method was a called with a certain argument? 我可以将方法参数限制为仅某些Enum成员吗? - Can I restrict method parameters to only certain Enum members? 如何限制Android应用程序仅在特定时间段内运行? - How to restrict the Android application to run only a certain time period? 如何重新运行paint方法,使JPanel具有动画效果? - How do I re run the paint method so the JPanel is animated? 如何使我的MousePressed侦听器仅在单击特定区域时才响应? - How do I make it so that my MousePressed listener only respons when I click in a certain area? 如何限制方法仅接受对象作为参数而不是类对象作为类型文字? - How do I restrict method to accept only object as parameter instead of Class Objects as Type Literals? 如何限制在我的通用方法中仅接受一种类型? - How do I restrict accepting only one type in my generic method? 我如何仅在知道该方法应该做什么的情况下找到一种在Java中使用的方法? - How do I find a certain method to use in java knowing only what the method should do? 绘画方法被多次调用...如何限制呢? - the paint method is called multiple times… how to restrict that? 在我的新GUI中调用run方法后,如何返回课程? - How do I return to the class after I've called my run method in my new GUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM