|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.dsideal.Tools;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.Utils.dsKit;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
@ -20,7 +22,6 @@ public class GenerateCode {
|
|
|
|
|
// mysql与java的数据类型映射
|
|
|
|
|
public static Map<String, String> dataTypeMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前数据库下的表
|
|
|
|
|
*
|
|
|
|
@ -120,16 +121,10 @@ public class GenerateCode {
|
|
|
|
|
stmt.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
//加载配置文件
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
beanPackage = PropKit.get("beanPackage");
|
|
|
|
|
beanPath = PropKit.get("beanPath");
|
|
|
|
|
beanPath = beanPath + "/" + beanPackage.replace(".", "/");
|
|
|
|
|
if (!FileUtil.exist(beanPath)) {
|
|
|
|
|
FileUtil.mkdir(beanPath);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 功能:初始化数据库类型映射
|
|
|
|
|
*/
|
|
|
|
|
public static void initMap() {
|
|
|
|
|
//mysql与java的数据类型映射
|
|
|
|
|
dataTypeMap.put("INT", "int");
|
|
|
|
|
dataTypeMap.put("BIGINT", "long");
|
|
|
|
@ -152,6 +147,18 @@ public class GenerateCode {
|
|
|
|
|
dataTypeMap.put("DATETIME", "java.util.Date");
|
|
|
|
|
dataTypeMap.put("DECIMAL", "BigDecimal");
|
|
|
|
|
dataTypeMap.put("BOOLEAN", "boolean");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
//加载配置文件
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
beanPackage = PropKit.get("beanPackage");
|
|
|
|
|
beanPath = PropKit.get("beanPath");
|
|
|
|
|
beanPath = beanPath + "/" + beanPackage.replace(".", "/");
|
|
|
|
|
if (!FileUtil.exist(beanPath)) {
|
|
|
|
|
FileUtil.mkdir(beanPath);
|
|
|
|
|
}
|
|
|
|
|
initMap();
|
|
|
|
|
|
|
|
|
|
// 配置Druid数据源插件
|
|
|
|
|
HikariCpPlugin hpPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
|
|
|
|
@ -169,17 +176,21 @@ public class GenerateCode {
|
|
|
|
|
//开始生成
|
|
|
|
|
List<String> tables = getTableNames(conn);
|
|
|
|
|
|
|
|
|
|
String tableNames = "";
|
|
|
|
|
//表描述
|
|
|
|
|
for (String table : tables) {
|
|
|
|
|
getStructure(conn, table);
|
|
|
|
|
tableNames += table + ",";
|
|
|
|
|
}
|
|
|
|
|
//去掉最后的逗号
|
|
|
|
|
tableNames = tableNames.substring(0, tableNames.length() - 1);
|
|
|
|
|
|
|
|
|
|
//关闭数据库
|
|
|
|
|
conn.close();
|
|
|
|
|
arp.stop();
|
|
|
|
|
hpPlugin.stop();
|
|
|
|
|
|
|
|
|
|
System.out.println("恭喜,生成完成");
|
|
|
|
|
System.out.println(dsKit.getCurrentTimeStr() + " 恭喜,表" + tableNames + "代码已成功生成!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|