首頁 > 軟體

SpringBoot+Quartz+資料庫儲存的完美集合

2022-02-19 13:01:26

官網: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+資料庫儲存內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com