package com.gblfy;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.*;@Configuration
public class QuartConfig {// 1.创建job对象@Beanpublic JobDetailFactoryBean jobDetailFactoryBean(){JobDetailFactoryBean factory = new JobDetailFactoryBean();factory.setJobClass(QuartzDemo.class);return factory;}// 2.创建Tigger对象 简单// @Bean// public SimpleTriggerFactoryBean simpleTriggerFactoryBean(JobDetailFactoryBean jobDetailFactoryBean) {// SimpleTriggerFactoryBean factory = new SimpleTriggerFactoryBean();// //关联JobDetail对象// factory.setJobDetail(jobDetailFactoryBean.getObject());// factory.setRepeatInterval(2000);// factory.setRepeatCount(5);// //设置重次数// return factory;// }@Beanpublic CronTriggerFactoryBean cronTriggerFactoryBean(JobDetailFactoryBean jobDetailFactoryBean){CronTriggerFactoryBean factory = new CronTriggerFactoryBean();factory.setJobDetail(jobDetailFactoryBean.getObject());//设置触发时间factory.setCronExpression("0/2 * * * * ?");return factory;}// 3.创建scheduler对象@Beanpublic SchedulerFactoryBean schedulerFactoryBean(CronTriggerFactoryBean cronTriggerFactoryBean, MyAdaptableJobFactory myAdaptableJobFactory){SchedulerFactoryBean factory = new SchedulerFactoryBean();//关联Tiggerfactory.setTriggers(cronTriggerFactoryBean.getObject());//注入对象并完成实例化factory.setJobFactory(myAdaptableJobFactory);return factory;}}
3. 创建一个业务处理类UserService
package com.gblfy;import org.springframework.stereotype.Service;@Service
public class UserService {//模拟操作数据库操作业务逻辑public voidaddUser(){System.out.println("add users....");}}
4. Job类 调用方法
package com.gblfy;import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;import java.util.Date;/*** Job类*/
public class QuartzDemo implements Job {@Autowiredprivate UserService userService;@Overridepublic voidexecute(JobExecutionContext jobExecutionContext) throws JobExecutionException {System.out.println("execute:"+ new Date());this.userService.addUser();}}
聚合函数:COUNT统计记录的条数、SUM求和函数、AVG求平均值、MAX求最大值、MIN求最小值一、COUNT练习:1、统计学校一共有多少个学生:mysql> SELECT COUNT(*) AS Total FROM t_student;-------| Total |-------| 13 |-------1 row in set (0…