SpringBoot+Quartz+数据库存储的完美集合

官网:http://www.quartz-scheduler.org/

我们所需数据库

pom依赖

   <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <!--解决mybatis-generator-maven-plugin运行时没有将XxxMapper.xml文件放入target文件夹的问题-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--解决mybatis-generator-maven-plugin运行时没有将jdbc.properites文件放入target文件夹的问题-->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>*.properties</include>
                    <include>*.xml</include>
                    <include>*.yml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <dependencies>
                    <!--使用Mybatis-generator插件不能使用太高版本的mysql驱动 -->
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Quartz默认的连接池是c3p0,如果你的连接池不同需要直接替换它的配置文件,比如我用的连接池是druid,就需要自己改配置(如果就用c3p0就不需要改) 工具类 utils MyJobFactory

package com.wsy.quartz02.utils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
/**
 * @author干的漂亮
 * @site www.wangmage.com
 * @company 干得漂亮公司
 * @create 2019 - 11-15 17:05
 */
@Component
@Slf4j
public class MyJobFactory extends AdaptableJobFactory {
    //这个对象Spring会帮我们自动注入进来
    @Autowired
    private AutowireCapableBeanFactory autowireCapableBeanFactory;
    //重写创建Job任务的实例方法
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        Object jobInstance = super.createJobInstance(bundle);
        //通过以下方式,解决Job任务无法使用Spring中的Bean问题
        autowireCapableBeanFactory.autowireBean(jobInstance);
        return super.createJobInstance(bundle);
    }
}

DruidConnectionProvider

package com.wsy.quartz02.utils;
import com.alibaba.druid.pool.DruidDataSource;
import org.quartz.SchedulerException;
import org.quartz.utils.ConnectionProvider;
import java.sql.Connection;
import java.sql.SQLException;
/*
#============================================================================
# JDBC
#============================================================================
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties:false
org.quartz.jobStore.dataSource:qzDS
#org.quartz.dataSource.qzDS.connectionProvider.class:org.quartz.utils.PoolingConnectionProvider
org.quartz.dataSource.qzDS.connectionProvider.class:com.zking.q03.quartz.DruidConnectionProvider
org.quartz.dataSource.qzDS.driver:com.mysql.jdbc.Driver
org.quartz.dataSource.qzDS.URL:jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
org.quartz.dataSource.qzDS.user:root
org.quartz.dataSource.qzDS.password:root
org.quartz.dataSource.qzDS.maxConnections:30
org.quartz.dataSource.qzDS.validationQuery: select 0
*/
/**
 * @author干的漂亮
 * @site www.wangmage.com
 * @company 干得漂亮公司
 * @create 2019 - 11-15 17:02
 */
/**
 * [Druid连接池的Quartz扩展类]
 *
 * @ProjectName: []
 * @Author: [xuguang]
 * @CreateDate: [2015/11/10 17:58]
 * @Update: [说明本次修改内容] BY[xuguang][2015/11/10]
 * @Version: [v1.0]
 */
public class DruidConnectionProvider implements ConnectionProvider {
    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * 常量配置,与quartz.properties文件的key保持一致(去掉前缀),同时提供set方法,Quartz框架自动注入值。
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */
    //JDBC驱动
    public String driver;
    //JDBC连接串
    public String URL;
    //数据库用户名
    public String user;
    //数据库用户密码
    public String password;
    //数据库最大连接数
    public int maxConnection;
    //数据库SQL查询每次连接返回执行到连接池,以确保它仍然是有效的。
    public String validationQuery;
    private boolean validateOnCheckout;
    private int idleConnectionValidationSeconds;
    public String maxCachedStatementsPerConnection;
    private String discardIdleConnectionsSeconds;
    public static final int DEFAULT_DB_MAX_CONNECTIONS = 10;
    public static final int DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION = 120;
    //Druid连接池
    private DruidDataSource datasource;
    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * 接口实现
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */
    public Connection getConnection() throws SQLException {
        return datasource.getConnection();
    }
    public void shutdown() throws SQLException {
        datasource.close();
    }
    public void initialize() throws SQLException{
        if (this.URL == null) {
            throw new SQLException("DBPool could not be created: DB URL cannot be null");
        }
        if (this.driver == null) {
            throw new SQLException("DBPool driver could not be created: DB driver class name cannot be null!");
        }
        if (this.maxConnection < 0) {
            throw new SQLException("DBPool maxConnectins could not be created: Max connections must be greater than zero!");
        }
        datasource = new DruidDataSource();
        try{
            datasource.setDriverClassName(this.driver);
        } catch (Exception e) {
            try {
                throw new SchedulerException("Problem setting driver class name on datasource: " + e.getMessage(), e);
            } catch (SchedulerException e1) {
            }
        }
        datasource.setUrl(this.URL);
        datasource.setUsername(this.user);
        datasource.setPassword(this.password);
        datasource.setMaxActive(this.maxConnection);
        datasource.setMinIdle(1);
        datasource.setMaxWait(0);
        datasource.setMaxPoolPreparedStatementPerConnectionSize(this.DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION);
        if (this.validationQuery != null) {
            datasource.setValidationQuery(this.validationQuery);
            if(!this.validateOnCheckout)
                datasource.setTestOnReturn(true);
            else
                datasource.setTestOnBorrow(true);
            datasource.setValidationQueryTimeout(this.idleConnectionValidationSeconds);
        }
    }
    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * 提供get set方法
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */
    public String getDriver() {
        return driver;
    }
    public void setDriver(String driver) {
        this.driver = driver;
    }
    public String getURL() {
        return URL;
    }
    public void setURL(String URL) {
        this.URL = URL;
    }
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public int getMaxConnection() {
        return maxConnection;
    }
    public void setMaxConnection(int maxConnection) {
        this.maxConnection = maxConnection;
    }
    public String getValidationQuery() {
        return validationQuery;
    }
    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }
    public boolean isValidateOnCheckout() {
        return validateOnCheckout;
    }
    public void setValidateOnCheckout(boolean validateOnCheckout) {
        this.validateOnCheckout = validateOnCheckout;
    }
    public int getIdleConnectionValidationSeconds() {
        return idleConnectionValidationSeconds;
    }
    public void setIdleConnectionValidationSeconds(int idleConnectionValidationSeconds) {
        this.idleConnectionValidationSeconds = idleConnectionValidationSeconds;
    }
    public DruidDataSource getDatasource() {
        return datasource;
    }
    public void setDatasource(DruidDataSource datasource) {
        this.datasource = datasource;
    }
}

application.yml

server:
  servlet:
    context-path: /
  port: 80
spring:
  datasource:
    #1.JDBC
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf8
    username: root
    password: 123
    druid:
      #2.连接池配置
      #初始化连接池的连接数量 大小,最小,最大
      initial-size: 5
      min-idle: 5
      max-active: 20
      #配置获取连接等待超时的时间
      max-wait: 60000
      #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 30000
      validation-query: SELECT 1 FROM DUAL
      test-while-idle: true
      test-on-borrow: true
      test-on-return: false
      # 是否缓存preparedStatement,也就是PSCache  官方建议MySQL下建议关闭   个人建议如果想用SQL防火墙 建议打开
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filter:
        stat:
          merge-sql: true
          slow-sql-millis: 5000
      #3.基础监控配置
      web-stat-filter:
        enabled: true
        url-pattern: /*
        #设置不统计哪些URL
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
        session-stat-enable: true
        session-stat-max-count: 100
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        #设置监控页面的登录名和密码
        login-username: admin
        login-password: admin
        allow: 127.0.0.1
        #deny: 192.168.1.100
#显示日志
logging:
  level:
    com.wsy.quartz02.mapper: debug

quartz.properties

#
#============================================================================
# Configure Main Scheduler Properties 调度器属性
#============================================================================
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount= 10
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
org.quartz.jobStore.misfireThreshold: 60000
#============================================================================
# Configure JobStore
#============================================================================
#存储方式使用JobStoreTX,也就是数据库
org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#使用自己的配置文件
org.quartz.jobStore.useProperties:true
#数据库中quartz表的表名前缀
org.quartz.jobStore.tablePrefix:qrtz_
org.quartz.jobStore.dataSource:qzDS
#是否使用集群(如果项目只部署到 一台服务器,就不用了)
org.quartz.jobStore.isClustered = true
#============================================================================
# Configure Datasources
#============================================================================
#配置数据库源(org.quartz.dataSource.qzDS.maxConnections: c3p0配置的是有s的,druid数据源没有s)

org.quartz.dataSource.qzDS.connectionProvider.class:com.wsy.quartz02.utils.DruidConnectionProvider
org.quartz.dataSource.qzDS.driver: com.mysql.jdbc.Driver
org.quartz.dataSource.qzDS.URL: jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf8
org.quartz.dataSource.qzDS.user: root
org.quartz.dataSource.qzDS.password: 123
org.quartz.dataSource.qzDS.maxConnection: 10

ScheduleTriggerMapper

package com.wsy.quartz02.mapper;
import com.wsy.quartz02.model.ScheduleTrigger;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ScheduleTriggerMapper {
    int deleteByPrimaryKey(Integer id);
    int insert(ScheduleTrigger record);
    int insertSelective(ScheduleTrigger record);
    ScheduleTrigger selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(ScheduleTrigger record);
    int updateByPrimaryKey(ScheduleTrigger record);
    /**
     * 查询触发器中包含的所有任务
     * @return
     */
    List<ScheduleTrigger> queryScheduleTriggerLst();
}

ScheduleTriggerParamMapper

package com.wsy.quartz02.mapper;
import com.wsy.quartz02.model.ScheduleTriggerParam;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ScheduleTriggerParamMapper {
    int deleteByPrimaryKey(Integer param_id);
    int insert(ScheduleTriggerParam record);
    int insertSelective(ScheduleTriggerParam record);
    ScheduleTriggerParam selectByPrimaryKey(Integer param_id);
    int updateByPrimaryKeySelective(ScheduleTriggerParam record);
    int updateByPrimaryKey(ScheduleTriggerParam record);
    /**
     * 查询出当前任务类对应所需的参数
     * @param triggerId
     * @return
     */
    List<ScheduleTriggerParam> queryScheduleParamLst(Integer triggerId);
}

ScheduleTriggerParam

<select id="queryScheduleParamLst" resultType="com.wsy.quartz02.model.ScheduleTriggerParam">
    select <include refid="Base_Column_List"/>
    from t_schedule_trigger_param where schedule_trigger_id=#{triggerId}
  </select>

ScheduleTrigger

<select id="queryScheduleTriggerLst" resultType="com.wsy.quartz02.model.ScheduleTrigger">
    select <include refid="Base_Column_List"/>
    from t_schedule_trigger
  </select>

QuartzConfiguration

package com.wsy.config;
import com.wsy.quartz02.utils.MyJobFactory;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import java.io.IOException;
import java.util.Properties;
@Configuration
public class QuartzConfiguration {
    @Autowired
    private MyJobFactory myJobFactory;
    //创建调度器工厂
    @Bean
        public SchedulerFactoryBean schedulerFactoryBean(){
            //1.创建SchedulerFactoryBean
            //2.加载自定义的quartz.properties配置文件
            //3.设置MyJobFactory
            SchedulerFactoryBean factoryBean=new SchedulerFactoryBean();
            try {
                factoryBean.setQuartzProperties(quartzProperties());
                factoryBean.setJobFactory(myJobFactory);
                return factoryBean;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
    }
    public Properties quartzProperties() throws IOException {
        PropertiesFactoryBean propertiesFactoryBean=new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    @Bean(name="scheduler")
    public Scheduler scheduler(){
        return schedulerFactoryBean().getScheduler();
}

MyJob

package com.wsy.quartz02.job;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class MyJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.err.println("MyJob是一个空的任务计划,时间:"+new Date().toLocaleString());
    }
}

MyJob1

package com.wsy.quartz02.job;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class MyJob1 implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail =
                jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        System.out.println(new Date().toLocaleString()+"-->携带参数个数:"+jobDataMap.size());
    }
}

MyJob2

package com.wsy.quartz02.job;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class MyJob2 implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail =
                jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        System.out.println(new Date().toLocaleString()+"-->MyJob2参数传递name="+jobDataMap.get("name")+",score="+
                jobDataMap.get("score"));
    }
}

Quartz02Controller

package com.wsy.quartz02.controler;
import com.wsy.quartz02.model.ScheduleTrigger;
import com.wsy.quartz02.service.ScheduleTriggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
 * @author干的漂亮
 * @site www.wangmage.com
 * @company 干得漂亮公司
 * @create 2019 - 11-16 16:02
 */
@Controller
@RequestMapping("/quartz")
public class Quartz02Controller {
    @Autowired
    private ScheduleTriggerService scheduleTriggerService;
    @RequestMapping("/list")
    public ModelAndView getAll(){
        ModelAndView mv = new ModelAndView();
        List<ScheduleTrigger> list = scheduleTriggerService.queryScheduleTriggerLst();
        mv.addObject("quartzList",list);
        mv.setViewName("index");
        return mv;
    }
    @RequestMapping("/edit")
    public String editStatus(ScheduleTrigger scheduleTrigger){
        int n = scheduleTriggerService.updateByPrimaryKeySelective(scheduleTrigger);
        return "redirect:/quartz/list";
    }
    @RequestMapping("/proSave/{id}")
    public ModelAndView proSave(@PathVariable(value = "id") Integer id){
        ModelAndView mv=new ModelAndView();
        ScheduleTrigger scheduleTrigger = scheduleTriggerService.selectByPrimaryKey(id);
        mv.addObject("schedule",scheduleTrigger);
        mv.setViewName("edit");
        return mv;
    }
}

ScheduleTriggerService

package com.wsy.quartz02.service;
import com.wsy.quartz02.model.ScheduleTrigger;
import java.util.List;
/**
 * @author干的漂亮
 * @site www.wangmage.com
 * @company 干得漂亮公司
 * @create 2019 - 11-16 16:02
 */
 public interface ScheduleTriggerService {
        int deleteByPrimaryKey(Integer id);
        int insert(ScheduleTrigger record);
        int insertSelective(ScheduleTrigger record);
        ScheduleTrigger selectByPrimaryKey(Integer id);
        int updateByPrimaryKeySelective(ScheduleTrigger record);
        int updateByPrimaryKey(ScheduleTrigger record);
        /**
         * 查询触发器中包含的所有任务
         * @return
         */
        List<ScheduleTrigger> queryScheduleTriggerLst();
}

Quartz02Application

package com.wsy.quartz02;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@MapperScan("com.wsy.quartz02.mapper")
@EnableTransactionManagement
@EnableScheduling
@SpringBootApplication
public class Quartz02Application {
    public static void main(String[] args) {
        SpringApplication.run(Quartz02Application.class, args);
    }
}

界面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>quartz定时任务管理</title>
</head>
<body>
<h1 style="text-align: center">定时任务</h1>
<table style="text-align: center" align="center" border="1px" width="50%">
    <tr>
        <td>id</td>
        <td>表达式</td>
        <td>状态</td>
        <td>工作类</td>
        <td>分组</td>
        <td>操作</td>
    </tr>
    <tr th:each="q : ${quartzList}">
        <td th:text="${q.id}"></td>
        <td th:text="${q.cron}"></td>
        <td th:text="${q.status}"></td>
        <td th:text="${q.job_name}"></td>
        <td th:text="${q.job_group}"></td>
        <td th:switch ="${q.status} == 0">
            <a th:case="true" th:href="@{/quartz/edit(id=${q.id},status=1)}" rel="external nofollow" >启动</a>
            <a th:case="false" th:href="@{/quartz/edit(id=${q.id},status=0)}" rel="external nofollow" >停止</a>
            <a th:href="@{'/quartz/proSave/'+${q.id}}" rel="external nofollow" >编辑</a>
            <a th:href="@{'/add/'}" rel="external nofollow" >增加</a>
        </td>
    </tr>
</table>
</body>
</html>

edit.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改定时任务</title>
</head>
<body>
<h1>修改定时任务</h1>
<form th:action="@{/quartz/edit}" method="post">
    <input type="hidden" name="id" th:value="${schedule.id}" />
    表达式: <input width="300px" type="text" name="cron" th:value="${schedule.cron}" /></br>
    工作类: <input width="300px" type="text" name="job_name" th:value="${schedule.job_name}" /></br>
    分组:<input width="300px" type="text" name="job_group" th:value="${schedule.job_group}" /></br>
    <input type="submit" value="提交"/>
</form>
</body>
</html>

到此这篇关于SpringBoot+Quartz+数据库存储的文章就介绍到这了,更多相关SpringBoot+Quartz+数据库存储内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • SpringBoot中使用Quartz管理定时任务的方法

    定时任务在系统中用到的地方很多,例如每晚凌晨的数据备份,每小时获取第三方平台的 Token 信息等等,之前我们都是在项目中规定这个定时任务什么时候启动,到时间了便会自己启动,那么我们想要停止这个定时任务的时候,就需要去改动代码,还得启停服务器,这是非常不友好的事情 直至遇见 Quartz,利用图形界面可视化管理定时任务,使得我们对定时任务的管理更加方便,快捷 一.Quartz 简介 Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵

  • springboot整合quartz实例demo

    目录 一.quartz简介 二.demo结构 三.代码详解 四.代码效果 一.quartz简介 1.Quartz是一个开源的任务调度框架.基于定时.定期的策略来执行任务是它的核心功能,比如x年x月的每个星期五上午8点到9点,每隔10分钟执行1次. 2.Quartz有3个核心要素:调度器(Scheduler).任务(Job).触发器(Trigger). 2.1.Job(任务):是一个接口,有一个方法void execute(),可以通过实现该接口来定义需要执行的任务(具体的逻辑代码).2.2.Jo

  • SpringBoot自动配置Quartz的实现步骤

    目录 1. 依赖信息 1.1 原依赖信息 1.2 新的依赖 1.3 依赖变化 2. 新的依赖使用 2.1 默认配置可用 2.2 使用自动配置 2.3 配置信息: 3. 总结 SpringBoot2.0版本之后,其中增加了对Quartz框架的支持内容,可以实现通过容器来自动配置Quartz. 1. 依赖信息 springboot2.x版本时,出现了spring-boot-starter-quartz这一起步依赖,其中提供了很多丰富功能. 1.1 原依赖信息 之前引入quartz框架时,必须引入的依

  • SpringBoot实现quartz定时任务可视化管理功能

    前言 在实际框架或产品开发过程中,springboot中集成quarzt方式基本是以job和trigger的bean对象方式直接硬编码完成的,例如以下代码示例.对于系统内定义的所有定时任务类型,具体执行类,执行策略,运行状态都没有一个动态全局的管理,所有决定将quartz做成可视化配置管理,便于统一管理,也降低了使用门槛,只需要关心job类的实现即可 @Bean public JobDetail SMSJobDetail() { return JobBuilder.newJob(SMSJob.c

  • SpringBoot结合Quartz实现数据库存储

    目录 一.先创建一个SpringBoot项目 二.导入依赖 三. 导入DruidConnectionProvider.java(Druid连接池的Quartz扩展类) 四. 修改自定义quartz.properties配置(在项目中添加quartz.properties文件(这样就不会加载自带的properties文件) ) 五.自定义MyJobFactory,解决spring不能在quartz中注入bean的问题 六.创建调度器schedule 七. 创建自定义任务 八. 更新quartz中的

  • springboot整合quartz定时任务框架的完整步骤

    目录 Spring整合Quartz pom文件 对应的properties 文件 配置类 自定义任务类:ScheduledTask 获取spring中bean的工具类:SpringContextUtil 定时任务服务接口:QuartzService QuartzService实现类:QuartzServiceImpl ScheduledTaskRunner类 任务实体类:QuartzTask 任务service层 service实现类 任务controller 数据表 具体使用 具体效果 总结

  • SpringBoot+Quartz+数据库存储的完美集合

    官网:http://www.quartz-scheduler.org/ 我们所需数据库 pom依赖 <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz<

  • springboot+quartz以持久化的方式实现定时任务的代码

    这篇文章给大家介绍springboot+quartz以持久化的方式实现定时任务,详情如下所示: 篇幅较长,耐心的人总能得到最后的答案小生第一次用quartz做定时任务,不足之处多多谅解. 首先 在springboot项目里做定时任务是比较简单的,最简单的实现方式是使用**@Scheduled注解,然后在application启动类上使用@EnableScheduling**开启定时任务. 示例 @SpringBootApplication @EnableScheduling public cla

  • SpringBoot配置数据库密码加密的实现

    你在使用 MyBatis 的过程中,是否有想过多个数据源应该如何配置,如何去实现?出于这个好奇心,我在 Druid Wiki 的数据库多数据源中知晓 Spring 提供了对多数据源的支持,基于 Spring 提供的 AbstractRoutingDataSource,可以自己实现数据源的切换. 一.配置动态数据源 下面就如何配置动态数据源提供一个简单的实现: org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource,

  • 关于SpringBoot mysql数据库时区问题

    寻找原因 后端开发中常见的几个时区设置 第一个设置点配置文件   spring.jackson.time-zone 第二个设置点 高版本SpringBoot版本 mysql-connector-java 用的是8.X,mysql8.X的jdbc升级了,增加了时区(serverTimezone)属性,并且不允许为空. 第三个设置点 mysql  time_zone变量 词义 serverTimezone临时指定mysql服务器的时区 spring.jackson.time-zone  设置spri

  • 更改Mysql数据库存储位置的具体步骤

    一.首先把mysql的服务先停掉. 二.更改MySQL配置文件My.ini中的数据库存储主路径 打开MySQL默认的安装文件夹C:\Program Files\MySQL\MySQL Server 5.1中的my.ini文件,点击记事本顶部的"编辑","查找",在查找内容中输入datadir后并点击"查找下一个"转到"Path to the database root数据库存储主路径"参数设置,找到datadir="

  • 相册管理系统(Java表单+xml数据库存储)

    功能文件的上传,下载和管理 技术:1.用xml当做数据库存储信息(dom4j,xpath) 2.Java表单的文件上传和下载 3.文件目录的打散 ( Hash目录是一种优化文件存储性能的方法) 需要的jar包: commons-fileupload-1.2.2.jar.commons-io-2.1.jar.dom4j-1.6.1.jar和jaxen-1.1-beta-6.jar -----------------------------------------------------------

  • Flutter持久化存储之数据库存储(sqflite)详解

    前言 数据库存储是我们常用的存储方式之一,对大批量数据有增.删.改.查操作需求时,我们就会想到使用数据库,Flutter中提供了一个sqflite插件供我们用于大量数据执行CRUD操作.本篇我们就来一起学习sqflite的使用. sqflite是一款轻量级的关系型数据库,类似SQLite. 在Flutter平台我们使用sqflite库来同时支持Android 和iOS. sqflite使用 引入插件 在pubspec.yaml文件中添加path_provider插件,最新版本为1.0.0,如下:

  • Python编写通讯录通过数据库存储实现模糊查询功能

    1.要求 数据库存储通讯录,要求按姓名/电话号码查询,查询条件只有一个输入入口,自动识别输入的是姓名还是号码,允许模糊查询. 2.实现功能 可通过输入指令进行操作. (1)首先输入"add",可以对通讯录进行添加联系人信息. sql1 = 'insert into TA(ID,NAME,AGE,ADDRESS,TELENUMBER)' sql1 += 'values("%d","%s","%d","%s",

  • Yii框架 session 数据库存储操作方法示例

    本文实例讲述了Yii框架 session 数据库存储操作方法.分享给大家供大家参考,具体如下: 在组件中声明session 组件开启数据库库存储 [ 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii', 'username' => 'root', 'password' => 'xxxxxx', 'charset' =&

随机推荐