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.
61 lines
2.5 KiB
61 lines
2.5 KiB
package com.dsideal.resource.Test;
|
|
|
|
import com.dsideal.resource.Base.Model.BaseModel;
|
|
import com.dsideal.resource.Plugin.YamlProp;
|
|
import com.dsideal.resource.ResApplication;
|
|
import com.dsideal.resource.Util.RetKit;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
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 com.jfinal.plugin.activerecord.Record;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class testDb {
|
|
public static void main(String[] args) throws JsonProcessingException {
|
|
//加载配置文件
|
|
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();
|
|
|
|
BaseModel bm = new BaseModel();
|
|
List<Record> list = bm.fetchStructure(1, -1);
|
|
System.out.println(list);
|
|
|
|
|
|
Map<String, Object> map = RetKit.renderSuccess("成功", list, null, 1, 99999, list.size());
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
mapper.registerModule(new JavaTimeModule()); // 注册 JavaTimeModule
|
|
mapper.enable(SerializationFeature.INDENT_OUTPUT); // 启用美化输出
|
|
String jsonString = mapper.writeValueAsString(map);
|
|
System.out.println(jsonString);
|
|
}
|
|
}
|