parent
b68360467b
commit
34bbb68290
@ -1,14 +1,18 @@
|
||||
package com.dsideal.Res.Test;
|
||||
|
||||
import com.dsideal.Res.Model.BaseClass;
|
||||
import com.dsideal.Res.Model.SysLoginperson;
|
||||
import com.dsideal.Res.Util.DbInit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestGenerator {
|
||||
public static void main(String[] args) {
|
||||
BaseClass baseClass = new BaseClass();
|
||||
List<BaseClass> list= baseClass.findAll();
|
||||
//启动数据库连接
|
||||
DbInit.Start();
|
||||
|
||||
//测试ORM
|
||||
SysLoginperson sysLoginperson = new SysLoginperson();
|
||||
List<SysLoginperson> list = sysLoginperson.findAll();
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.dsideal.Res.Util;
|
||||
|
||||
import com.dsideal.Res.Model._MappingKit;
|
||||
import com.dsideal.Res.ResApplication;
|
||||
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(ResApplication.PropKit.get("mysql.jdbcUrl"), ResApplication.PropKit.get("mysql.user"),
|
||||
ResApplication.PropKit.get("mysql.password").trim(), ResApplication.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 = 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) {
|
||||
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
||||
}
|
||||
}
|
||||
//加载
|
||||
arp.start();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue