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.
40 lines
1.4 KiB
40 lines
1.4 KiB
package com.dsideal.Base.Util;
|
|
|
|
import com.dsideal.Base.BaseApplication;
|
|
import com.dsideal.Base.Model._MappingKit;
|
|
import com.dsideal.Config.PropKit;
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
|
import com.jfinal.plugin.druid.DruidPlugin;
|
|
|
|
import java.io.File;
|
|
|
|
public class DbInit {
|
|
|
|
public static void Start(){
|
|
//加载数据库
|
|
DruidPlugin plugin = new DruidPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
|
plugin.start();
|
|
// 配置ActiveRecord插件
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", plugin);
|
|
arp.setDialect(new MysqlDialect());
|
|
//加入ORM配置
|
|
_MappingKit.mapping(arp);
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
File sqlDir;
|
|
String basePath = BaseApplication.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) {
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
}
|
|
}
|
|
//加载
|
|
arp.start();
|
|
}
|
|
}
|