[英]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.