Compare commits

...

3 Commits

Author SHA1 Message Date
zyq ddf92dc84e 添加注释说明 2024-03-11 09:14:54 +08:00
zyq 861f25f90d 调整数据库连接方法 2024-03-11 09:14:33 +08:00
zyq d4d125f471 添加数据库连接 2024-03-11 09:14:06 +08:00
4 changed files with 27 additions and 7 deletions

View File

@ -1,9 +1,14 @@
package com.cyx.config;
import com.alibaba.druid.filter.stat.StatFilter;
import com.cyx.db.Jdbc;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.*;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.AnsiSqlDialect;
import com.jfinal.plugin.cron4j.Cron4jPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
/**
* @Author Created by cyx.zhang Administrator on 2024/3/1 16:11 周五
@ -26,6 +31,19 @@ public class AppConfig extends JFinalConfig {
*/
@Override
public void configPlugin(Plugins plugins) {
//配置Druid数据库连接池插件
DruidPlugin druidPlugin = Jdbc.createDruidPlugin();
//配置Druid数据库连接池大小
druidPlugin.set(20, 20, 100);
//添加 StatFilter 才会有统计数据
druidPlugin.addFilter(new StatFilter());
plugins.add(druidPlugin);
//配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
plugins.add(arp);
arp.setDialect(new AnsiSqlDialect());
//配置任务调度插件
Cron4jPlugin cp = new Cron4jPlugin(PropKit.use("cron4j.properties"),"cron4j");
plugins.add(cp);

View File

@ -22,13 +22,7 @@ public class MyTask implements Runnable{
@Override
public void run() {
EventLog.info("......任务调度开始执行......");
String is = Jdbc.jdbc();
if ("1".equals(is)) {
EventLog.info("......数据库连接成功......");
doStart();
}else {
EventLog.info("......数据库连接失败......");
}
doStart();
EventLog.info("......任务调度结束执行......");
}

View File

@ -17,6 +17,10 @@ public class Jdbc {
*/
private static Prop p = PropKit.use("config.properties");
/**
* 配置Druid数据库连接池插件
* @return
*/
public static DruidPlugin createDruidPlugin() {
DruidPlugin druidPlugin = null;
try {

View File

@ -9,6 +9,10 @@ import com.jfinal.server.undertow.UndertowServer;
*/
public class Main {
/**
* 主方法
* @param args
*/
public static void main(String[] args) {
UndertowServer.start(AppConfig.class, 8099, true);
EventLog.info("启动成功");