标签:
1 package com.practice.prac.service.Impl; 2 3 import java.text.DateFormat; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 import javax.annotation.Resource; 8 9 import org.springframework.scheduling.annotation.Scheduled; 10 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Service; 12 13 import com.practice.prac.dao.CreateTableByDayMapper; 14 import com.practice.prac.service.CreateTableByDayService; 15 16 @Service("CreateTableByDayService") 17 @Component 18 public class CreateTableByDayImpl implements CreateTableByDayService { 19 20 @Resource 21 CreateTableByDayMapper createTableByDayMapper; 22 23 @Override 24 @Scheduled(cron = "*/5 * * * * ?") 25 public void createTable() { 26 27 DateFormat fmt = new SimpleDateFormat("yyyyMMdd"); 28 String time = fmt.format(new Date()); 29 String sql = "create table if not exists table_name_" + time 30 + " (name varchar(50),value varchar(50))"; 31 createTableByDayMapper.createTable(sql); 32 } 33 34 }
使用SpringMVC自带的@Scheduled完成定时任务
标签:
原文地址:http://www.cnblogs.com/kangyun/p/5616098.html