参考博客:

http://www.jb51.net/article/110541.htm

http://blog.csdn.net/wxwzy738/article/details/25158787

我这边项目的需求是:每天晚上1点删除数据库表t_tempclob中的所有记录;

 

代码:

Controller:

@Controller
public class AjaxFileDownload {
    
    private static Logger logger = Logger.getLogger(AjaxFileDownload.class);
    
    @Autowired
    private ProductService productService;
    
    @Autowired
    private TempClobService tcService;
    
    /**
     * 定时任务,每天晚上1点删除数据表t_tempClob中的所有记录
     */
    @Scheduled(cron= "0 0 1 * * ?")
    public void deleteAllTempClob(){
        int count = tcService.deleteAllTempClob();
        System.err.println("---->>deleteAllTempClob删除数据库记录数:" + count);
    }
}

Service:

spring的定时任务配置(注解)
/**
     * 删除所有大文本
     */
    public int deleteAllTempClob(){
        int count = 0;
        try {
            count = tcMapper.deleteAllTempClob();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return count;
    }
View Code

相关文章: