You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.5 KiB
41 lines
1.5 KiB
10 months ago
|
package com.dsideal.resource.Test;
|
||
|
|
||
|
import com.dsideal.resource.Plugin.YamlProp;
|
||
|
import com.dsideal.resource.ResApplication;
|
||
|
import com.jfinal.kit.Prop;
|
||
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||
|
|
||
|
import java.io.File;
|
||
|
|
||
|
public class testDb {
|
||
|
public static void main(String[] args) {
|
||
|
//加载配置文件
|
||
|
String configFile = "application_dev.yaml";
|
||
|
Prop PropKit = new YamlProp(configFile);
|
||
|
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||
|
masterPlugin.start();
|
||
|
|
||
|
// 配置ActiveRecord插件
|
||
|
ActiveRecordPlugin masterArp = new ActiveRecordPlugin("master", masterPlugin);
|
||
|
masterArp.setDialect(new MysqlDialect());
|
||
|
|
||
|
//遍历sql目录下所有的sql文件
|
||
|
File sqlDir;
|
||
|
String basePath = ResApplication.class.getResource("/").getPath();
|
||
|
sqlDir = new File(basePath + "/Sql");
|
||
|
File[] sqlFiles = sqlDir.listFiles();
|
||
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
||
|
//只加载.sql文件
|
||
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
||
|
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
||
|
}
|
||
|
}
|
||
|
masterArp.start();
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|