上回说到,我们的设置页面已经做好了,接下来就是将时间转换为Unix Cron Expression。
2) 将时间转换为Unix Cron Expression
需要ActionForm将页面表单数据映射到Action中,然后在Action中转换为cron expression:
1 SchedulerForm schedulerForm = (SchedulerForm) form;
2 String jobName = schedulerForm.getJobName();
3 String cronExpression = "" ;
4 String[] commonNeeds = {schedulerForm.getSecond(), schedulerForm.getMinute(), schedulerForm.getHour()} ;
5 String[] monthlyNeeds = {schedulerForm.getWeek(), schedulerForm.getDayOfMonth()} ;
6 String weeklyNeeds = schedulerForm.getDayOfWeek();
7 String userDefinedNeeds = schedulerForm.getDate();
8 String everyWhat = schedulerForm.getEveryWhat();
9 // 得到时间规则
10 cronExpression = CronExpConversion.getCronExpression(everyWhat, commonNeeds,
11 monthlyNeeds, weeklyNeeds, userDefinedNeeds);
12