通过 @EnableScheduling 实现定时任务的布置
原文发布在我的博客:https://jimsunjing.github.io/tech/java/enablescheduling/
在阅读一个Github项目 VBlog 的源码过程中发现了这个注解,可以提供快速的基于多种规则的任务调度。
项目的数据统计需求
在 VBlog 项目中,作者实现了一个数据统计的功能,实现了文章阅读访问量每天的数据统计,并形成图表。效果如下:
前端使用了 EChart(vue-echarts) 进行数据的展示,这里 copy 一下它的数据获取方式:
mounted: function () {
var _this = this;
getRequest("/article/dataStatistics").then(resp=> {
if (resp.status == 200) {
_this.$refs.dschart.options.xAxis.data = resp.data.categories;
_this.$refs.dschart.options.series[0].data = resp.data.ds;
} else {
_this.$message({
type: 'error', message: '数据加载失败!'});
}
}, resp=> {
_this.$message({
type: 'error', message: '数据加载失败!'});
});
},
通过前端接口查找后端的实现:其中 getCategories
返回的是该用户id下 pv 统计表中的最近7个时间的统计时间列。getDataStatistics
返回的就是 pv 统计表中的流量数据。
@RequestMapping("/dataStatistics")
public Map<String,Object> dataStatistics() {
Map<String, Object> map = new HashMap<>(