diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 1ca59dc1..c1d30480 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -238,6 +238,7 @@ public class SpringBootCallable implements Callable { } HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); + ctx.put("projectName", project.getProjectName()); ctx.put("author", project.getProjectAuthor()); ctx.put("date", new Date()); @@ -245,6 +246,7 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ActionConfig.java"), option + "/java/config/ActionConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "FreeMarkerConfig.java"), option + "/java/config/FreeMarkerConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SecurityConfig.java"), option + "/java/config/SecurityConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SQLiteConfig.java"), option + "/java/config/SQLiteConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "TaskConfig.java"), option + "/java/config/TaskConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ThreadPoolConfig.java"), option + "/java/config/ThreadPoolConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "WebMvcConfig.java"), option + "/java/config/WebMvcConfig.java", ctx); @@ -616,7 +618,7 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx); - freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "ResourceUtil.java"), option + "/java/frame/utils/ResourceUtil.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "ResponseUtil.java"), option + "/java/frame/utils/ResponseUtil.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/frame/utils/RSAUtil.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), "StringUtil.java"), option + "/java/frame/utils/StringUtil.java", ctx); @@ -700,20 +702,19 @@ public class SpringBootCallable implements Callable { try { Class.forName("org.sqlite.JDBC"); connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath()); - statement = connection.createStatement(); - for (Module module : project.getModules()) { - File tableDir = Tool.createPath(dbtool.getAbsolutePath(), module.getModuleName() + "_table"); - File file = Tool.createFile(tableDir.getAbsolutePath(), "ALL_TABLE.sql"); - String string = FileUtil.readFileToString(file); - statement.execute(string); - } - - { - File tableDir = Tool.createPath(dbtool.getAbsolutePath(),"system"); - File file = Tool.createFile(tableDir.getAbsolutePath(), "ALL_TABLE.sql"); - String string = FileUtil.readFileToString(file); - statement.execute(string); + for (File fileModule : dbtool.listFiles()) { + if (!fileModule.isDirectory()) { + continue; + } + for (File file : fileModule.listFiles()) { + if (!file.getName().startsWith("ALL_") && file.getName().endsWith(".sql")) { + statement = connection.createStatement(); + String sql = FileUtil.readFileToString(file); + statement.execute(sql); + statement.close(); + } + } } } catch (ClassNotFoundException | SQLException | IOException e) { e.printStackTrace(); @@ -722,13 +723,13 @@ public class SpringBootCallable implements Callable { if (statement != null) statement.close(); if (connection != null) connection.close(); } catch (Exception e) { - e.printStackTrace(); + } } } { - File system = Tool.createPath(dbtool.getAbsolutePath(), "system"); + File system = Tool.createPath(dbtool.getAbsolutePath(), "system_table"); freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "ALL_TABLE.sql"), option + "/resources/dbtool/system/ALL_TABLE.sql", ctx); freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "DICT.sql"), option + "/resources/dbtool/system/DICT.sql", ctx); freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "DICT_ITEM.sql"), option + "/resources/dbtool/system/DICT_ITEM.sql", ctx); @@ -740,7 +741,7 @@ public class SpringBootCallable implements Callable { HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); - ctx.put("moduleName", project.getProjectName()); + ctx.put("projectName", project.getProjectName()); ctx.put("tool", Tool.class); ctx.put("dataBase", dataBase.toString()); ctx.put("author", project.getProjectAuthor()); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java index d009fa12..f48d66fe 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java @@ -12,7 +12,7 @@ public class SQLiteDBmapper extends AbstractDBmapper { @Override public String getFieldSql(Field field) { StringBuffer sb = new StringBuffer(""); - sb.append("`").append(field.getFieldName()).append("` "); + sb.append("\"").append(field.getFieldName()).append("\""); FieldType type = field.getFieldType(); diff --git a/src/main/resources/modules/SpringBoot/java/config/SQLiteConfig.java b/src/main/resources/modules/SpringBoot/java/config/SQLiteConfig.java new file mode 100644 index 00000000..e558b648 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/config/SQLiteConfig.java @@ -0,0 +1,32 @@ +package ${basePackage}.config; + +import ${basePackage}.frame.utils.ResourceUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; +import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Configuration +public class SQLiteConfig { + + @Value("${spring.datasource.url}") + private String url; + + @PostConstruct + public void setSharedVariable() { + Pattern compile = Pattern.compile("jdbc:sqlite:(.*.db)"); + Matcher matcher = compile.matcher(url); + if (matcher.find()) { + String group = matcher.group(1); + File file = new File(group); + if (!file.exists()) { + File path = file.getAbsoluteFile().getParentFile(); + if (!path.exists()) path.mkdirs(); + ResourceUtil.copyResource2File("${projectName}.db", file); + } + } + } +} diff --git a/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl b/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl index 32c6aea2..3fe2268d 100644 --- a/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl +++ b/src/main/resources/modules/SpringBoot/java/module/mpr/mapper.ftl @@ -9,7 +9,7 @@ <#elseif dataBase='MySQL'> `${module.modulePrefix?default("")}${table.tableName}` <#elseif dataBase='SQLite'> - ${module.modulePrefix?default("")}${table.tableName} + "${module.modulePrefix?default("")}${table.tableName}" @@ -18,7 +18,7 @@ <#elseif dataBase='MySQL'> <#list table.fields as f>`${f.fieldName}`<#if f_has_next>, <#elseif dataBase='SQLite'> - <#list table.fields as f>${f.fieldName}<#if f_has_next>, + <#list table.fields as f>"${f.fieldName}"<#if f_has_next>, @@ -39,7 +39,7 @@ <#elseif dataBase='MySQL'> `IS_DELETED` = 0 <#elseif dataBase='SQLite'> - IS_DELETED = 0 + "IS_DELETED" = 0 <#list table.fields as f> <#if f.isQuery> diff --git a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl index 9abf9ad3..34a79d24 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl @@ -40,7 +40,7 @@ mybatis.configuration.map-underscore-to-camel-case=true <#if dataBase == 'SQLite'> # SQLite spring.datasource.url=jdbc:sqlite::resource:example.db spring.datasource.driver-class-name=org.sqlite.JDBC -spring.datasource.url=jdbc:sqlite:./example.db +spring.datasource.url=jdbc:sqlite:${projectName?default("SpringBoot")}.db spring.datasource.username=test spring.datasource.password=123456 # mybatis diff --git a/src/main/resources/modules/SpringBoot/resources/application-prod.ftl b/src/main/resources/modules/SpringBoot/resources/application-prod.ftl index ecdcf043..0f2b346e 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-prod.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-prod.ftl @@ -40,7 +40,7 @@ mybatis.configuration.map-underscore-to-camel-case=true <#if dataBase == 'SQLite'> # SQLite spring.datasource.url=jdbc:sqlite::resource:example.db spring.datasource.driver-class-name=org.sqlite.JDBC -spring.datasource.url=jdbc:sqlite:./example.db +spring.datasource.url=jdbc:sqlite:${projectName?default("SpringBoot")}.db spring.datasource.username=test spring.datasource.password=123456 # mybatis diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/system/ALL_TABLE.sql b/src/main/resources/modules/SpringBoot/resources/dbtool/system/ALL_TABLE.sql index 87b0351a..64d0b15d 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/system/ALL_TABLE.sql +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/system/ALL_TABLE.sql @@ -172,26 +172,67 @@ COMMENT ON COLUMN "SYS_FILE"."LAST_UPDATE_BY" is '最后更新用户'; COMMENT ON COLUMN "SYS_FILE"."LAST_UPDATE_TIME" is '最后更新时间'; <#if dataBase == 'SQLite'> +-- ---------------------------- +-- Table structure for DICT - 字典 +-- Target : SQLite +-- Author : wangbing +-- Date: : 2019-12-16 +-- ---------------------------- +CREATE TABLE IF NOT EXISTS "SYS_DICT" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "DICT_NAME" VARCHAR(50) NOT NULL, + "DICT_COMMENT" VARCHAR(50) NOT NULL, + "VERSION" VARCHAR(50) NOT NULL, + "VALID" BOOLEAN NOT NULL, + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME +); + +-- ---------------------------- +-- Table structure for DICT_ITEM - 字典项 +-- Target : SQLite +-- Author : wangbing +-- Date: : 2019-12-16 +-- ---------------------------- +CREATE TABLE IF NOT EXISTS "SYS_DICT_ITEM" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "DICT_NAME" BIGINT NOT NULL, + "KEY" CHAR(10) NOT NULL, + "VALUE" VARCHAR(100) NOT NULL, + "SORT" MEDIUMINT NOT NULL, + "VALID" BOOLEAN NOT NULL, + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME +); + -- ---------------------------- -- Table structure for FILE - 文件 -- Target : SQLite -- Author : wangbing -- Date: : 2019-12-16 -- ---------------------------- -CREATE TABLE IF NOT EXISTS `SYS_FILE` ( - `ID` BIGINT PRIMARY KEY NOT NULL, - `NAME` VARCHAR(250), - `FILE_TYPE` VARCHAR(10), - `ATTRIBUTE1` VARCHAR(50), - `ATTRIBUTE2` VARCHAR(50), - `LOCATION` VARCHAR(500), - `URL` VARCHAR(500), - `URL_DOWNLOAD` VARCHAR(500), - `ROW_VERSION` BIGINT NOT NULL, - `IS_DELETED` BOOLEAN NOT NULL, - `CREATE_BY` BIGINT NOT NULL, - `CREATE_TIME` DATETIME NOT NULL, - `LAST_UPDATE_BY` BIGINT, - `LAST_UPDATE_TIME` DATETIME +CREATE TABLE IF NOT EXISTS "SYS_FILE" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "NAME" VARCHAR(250), + "FILE_TYPE" VARCHAR(10), + "ATTRIBUTE1" VARCHAR(50), + "ATTRIBUTE2" VARCHAR(50), + "LOCATION" VARCHAR(500), + "URL" VARCHAR(500), + "URL_DOWNLOAD" VARCHAR(500), + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME ); \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT.sql b/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT.sql index d599675e..0c0492d6 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT.sql +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT.sql @@ -61,17 +61,17 @@ COMMENT ON COLUMN "SYS_DICT"."LAST_UPDATE_TIME" is '最后更新时间'; -- Author : wangbing -- Date: : 2019-12-16 -- ---------------------------- -CREATE TABLE IF NOT EXISTS `SYS_DICT` ( - `ID` BIGINT PRIMARY KEY NOT NULL, - `DICT_NAME` VARCHAR(50) NOT NULL, - `DICT_COMMENT` VARCHAR(50) NOT NULL, - `VERSION` VARCHAR(50) NOT NULL, - `VALID` BOOLEAN NOT NULL, - `ROW_VERSION` BIGINT NOT NULL, - `IS_DELETED` BOOLEAN NOT NULL, - `CREATE_BY` BIGINT NOT NULL, - `CREATE_TIME` DATETIME NOT NULL, - `LAST_UPDATE_BY` BIGINT, - `LAST_UPDATE_TIME` DATETIME +CREATE TABLE IF NOT EXISTS "SYS_DICT" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "DICT_NAME" VARCHAR(50) NOT NULL, + "DICT_COMMENT" VARCHAR(50) NOT NULL, + "VERSION" VARCHAR(50) NOT NULL, + "VALID" BOOLEAN NOT NULL, + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME ); \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT_ITEM.sql b/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT_ITEM.sql index 56fafc71..663a06af 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT_ITEM.sql +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/system/DICT_ITEM.sql @@ -64,18 +64,18 @@ COMMENT ON COLUMN "SYS_DICT_ITEM"."LAST_UPDATE_TIME" is '最后更新时间'; -- Author : wangbing -- Date: : 2019-12-16 -- ---------------------------- -CREATE TABLE IF NOT EXISTS `SYS_DICT_ITEM` ( - `ID` BIGINT PRIMARY KEY NOT NULL, - `DICT_NAME` BIGINT NOT NULL, - `KEY` CHAR(10) NOT NULL, - `VALUE` VARCHAR(100) NOT NULL, - `SORT` MEDIUMINT NOT NULL, - `VALID` BOOLEAN NOT NULL, - `ROW_VERSION` BIGINT NOT NULL, - `IS_DELETED` BOOLEAN NOT NULL, - `CREATE_BY` BIGINT NOT NULL, - `CREATE_TIME` DATETIME NOT NULL, - `LAST_UPDATE_BY` BIGINT, - `LAST_UPDATE_TIME` DATETIME +CREATE TABLE IF NOT EXISTS "SYS_DICT_ITEM" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "DICT_NAME" BIGINT NOT NULL, + "KEY" CHAR(10) NOT NULL, + "VALUE" VARCHAR(100) NOT NULL, + "SORT" MEDIUMINT NOT NULL, + "VALID" BOOLEAN NOT NULL, + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME ); \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/system/FILE.sql b/src/main/resources/modules/SpringBoot/resources/dbtool/system/FILE.sql index be592973..1d48b200 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/system/FILE.sql +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/system/FILE.sql @@ -70,20 +70,20 @@ COMMENT ON COLUMN "SYS_FILE"."LAST_UPDATE_TIME" is '最后更新时间'; -- Author : wangbing -- Date: : 2019-12-16 -- ---------------------------- -CREATE TABLE IF NOT EXISTS `SYS_FILE` ( - `ID` BIGINT PRIMARY KEY NOT NULL, - `NAME` VARCHAR(250), - `FILE_TYPE` VARCHAR(10), - `ATTRIBUTE1` VARCHAR(50), - `ATTRIBUTE2` VARCHAR(50), - `LOCATION` VARCHAR(500), - `URL` VARCHAR(500), - `URL_DOWNLOAD` VARCHAR(500), - `ROW_VERSION` BIGINT NOT NULL, - `IS_DELETED` BOOLEAN NOT NULL, - `CREATE_BY` BIGINT NOT NULL, - `CREATE_TIME` DATETIME NOT NULL, - `LAST_UPDATE_BY` BIGINT, - `LAST_UPDATE_TIME` DATETIME +CREATE TABLE IF NOT EXISTS "SYS_FILE" ( + "ID" BIGINT PRIMARY KEY NOT NULL, + "NAME" VARCHAR(250), + "FILE_TYPE" VARCHAR(10), + "ATTRIBUTE1" VARCHAR(50), + "ATTRIBUTE2" VARCHAR(50), + "LOCATION" VARCHAR(500), + "URL" VARCHAR(500), + "URL_DOWNLOAD" VARCHAR(500), + "ROW_VERSION" BIGINT NOT NULL, + "IS_DELETED" BOOLEAN NOT NULL, + "CREATE_BY" BIGINT NOT NULL, + "CREATE_TIME" DATETIME NOT NULL, + "LAST_UPDATE_BY" BIGINT, + "LAST_UPDATE_TIME" DATETIME ); \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/table.ftl b/src/main/resources/modules/SpringBoot/resources/dbtool/table.ftl index 17fb23b4..b882d594 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/table.ftl +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/table.ftl @@ -39,7 +39,7 @@ PRIMARY KEY (`ID`) -- Author : ${author} -- Date: : ${date?string("yyyy-MM-dd")} -- ---------------------------- -CREATE TABLE IF NOT EXISTS `${module.modulePrefix?default("")}${table.tableName}` ( +CREATE TABLE IF NOT EXISTS ${module.modulePrefix?default("")}${table.tableName} ( <#list table.fields as field> ${dBmapper.getFieldSql(field)}<#if field_has_next>, diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/tableAll.ftl b/src/main/resources/modules/SpringBoot/resources/dbtool/tableAll.ftl index 87e68812..3bc14e5b 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/tableAll.ftl +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/tableAll.ftl @@ -44,7 +44,7 @@ PRIMARY KEY (`ID`) -- Author : ${author} -- Date: : ${date?string("yyyy-MM-dd")} -- ---------------------------- -CREATE TABLE IF NOT EXISTS `${module.modulePrefix?default("")}${table.tableName}` ( +CREATE TABLE IF NOT EXISTS ${module.modulePrefix?default("")}${table.tableName} ( <#list table.fields as field> ${dBmapper.getFieldSql(field)}<#if field_has_next>, diff --git a/src/main/resources/modules/SpringBoot/test/application.properties b/src/main/resources/modules/SpringBoot/test/application.properties index 9abf9ad3..34a79d24 100644 --- a/src/main/resources/modules/SpringBoot/test/application.properties +++ b/src/main/resources/modules/SpringBoot/test/application.properties @@ -40,7 +40,7 @@ mybatis.configuration.map-underscore-to-camel-case=true <#if dataBase == 'SQLite'> # SQLite spring.datasource.url=jdbc:sqlite::resource:example.db spring.datasource.driver-class-name=org.sqlite.JDBC -spring.datasource.url=jdbc:sqlite:./example.db +spring.datasource.url=jdbc:sqlite:${projectName?default("SpringBoot")}.db spring.datasource.username=test spring.datasource.password=123456 # mybatis