From 2f2521afe50fe38a24107cdf3987b44c8cc0e85b Mon Sep 17 00:00:00 2001 From: wangbing Date: Wed, 8 Apr 2020 14:24:45 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: e7dbfc65e1734ee82b1d22eeeb80e39b91913980 --- .../dbtool/javafx/JavaFxApplication.java | 76 +++-- .../dbtool/javafx/ctrl/MainController.java | 12 +- .../dbtool/javafx/manger/JsonManager.java | 37 +++ .../dbtool/javafx/manger/ManagerFactory.java | 7 +- .../dbtool/javafx/manger/ProjectManager.java | 41 ++- .../dbtool/javafx/manger/XmlManager.java | 5 +- .../manger/callable/SpringBootCallable.java | 264 +++++++++--------- .../dbtool/javafx/po/AbstractDBmapper.java | 15 +- .../dbtool/javafx/po/MySQLDBmapper.java | 8 +- .../dbtool/javafx/po/OracleDBmapper.java | 7 +- .../dbtool/javafx/po/SQLiteDBmapper.java | 8 +- .../xyz/wbsite/dbtool/javafx/tool/Dialog.java | 40 --- .../dbtool/web/frame/utils/FileUtil.java | 125 ++++++++- src/main/resources/fxml/generateOption.fxml | 66 ----- src/main/resources/fxml/projectdetail.fxml | 8 +- 15 files changed, 378 insertions(+), 341 deletions(-) create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/manger/JsonManager.java delete mode 100644 src/main/resources/fxml/generateOption.fxml diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/JavaFxApplication.java b/src/main/java/xyz/wbsite/dbtool/javafx/JavaFxApplication.java index e35bde2a..22acfa2f 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/JavaFxApplication.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/JavaFxApplication.java @@ -5,7 +5,6 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.Event; @@ -15,6 +14,7 @@ import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; +import javafx.scene.control.RadioButton; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -59,7 +59,7 @@ import java.util.List; public class JavaFxApplication extends Application { - private ProjectManager dBmanager = ManagerFactory.getProjectManager(); + private ProjectManager projectManager = ManagerFactory.getProjectManager(); private TreeView mTree = null; private Pane mDetail = null; private TableView mFields = null; @@ -226,7 +226,7 @@ public class JavaFxApplication extends Application { public void handle(MouseEvent event) { TextFieldTreeCell source = (TextFieldTreeCell) event.getSource(); String text = source.getText(); - Module dbByDBName = dBmanager.findDBByDBName(text); + Module dbByDBName = projectManager.findDBByDBName(text); if (dbByDBName != null) { dragMD = true; } else { @@ -250,7 +250,7 @@ public class JavaFxApplication extends Application { Dragboard md = event.getDragboard(); TextFieldTreeCell source = (TextFieldTreeCell) event.getSource(); - Module dbByDBName = dBmanager.findDBByDBName(source.getText()); + Module dbByDBName = projectManager.findDBByDBName(source.getText()); if (dragMD && dbByDBName != null) { double y = event.getY(); @@ -286,7 +286,7 @@ public class JavaFxApplication extends Application { String m2 = ((TreeCell) event.getGestureTarget()).getItem(); if (dragMD) { - List mds = dBmanager.getMds(); + List mds = projectManager.getMds(); int i1 = 0, i2 = 0; for (int i = 0; i < mds.size(); i++) { @@ -376,7 +376,7 @@ public class JavaFxApplication extends Application { case 1: {//查看模块 mTree.setContextMenu(md_right_menu); - currentMD = dBmanager.findDBByDBName((String) targetItem.getValue()); + currentMD = projectManager.findDBByDBName((String) targetItem.getValue()); currentTable = null; loadingModule(); } @@ -384,9 +384,9 @@ public class JavaFxApplication extends Application { case 2: {//查看对象 mTree.setContextMenu(table_right_menu); TreeItem parent = targetItem.getParent(); - currentMD = dBmanager.findDBByDBName((String) parent.getValue()); + currentMD = projectManager.findDBByDBName((String) parent.getValue()); if (currentMD != null) { - currentTable = dBmanager.findTableByTableName(currentMD, (String) targetItem.getValue()); + currentTable = projectManager.findTableByTableName(currentMD, (String) targetItem.getValue()); } loadingTable(); break; @@ -464,7 +464,13 @@ public class JavaFxApplication extends Application { currentProject.setCloud(newValue); } }); - detailProjectController.getDatabase().getToggles() + detailProjectController.getDatabase().selectedToggleProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Toggle oldValue, Toggle newValue) { + RadioButton radioButton = (RadioButton) newValue; + currentProject.setDatabase(radioButton.getText()); + } + }); } {//初始化表面板 @@ -544,7 +550,7 @@ public class JavaFxApplication extends Application { private void addField() { if (currentTable != null && mFields != null) { List fields = currentTable.getFields(); - String fieldName = dBmanager.getNewFieldName(fields); + String fieldName = projectManager.getNewFieldName(fields); System.out.println("新增字段-" + fieldName + "成功!"); this.mFields.getSelectionModel().select(fields.size() - 1); loadingTable(); @@ -564,7 +570,7 @@ public class JavaFxApplication extends Application { } public void loadingProjectTree() { - currentProject = dBmanager.getProject(); + currentProject = projectManager.getProject(); currentProject.setValue(currentProject.getProjectName()); currentProject.setExpanded(true); @@ -621,6 +627,16 @@ public class JavaFxApplication extends Application { detailProjectController.getProjectAuthor().setText(currentProject.getProjectAuthor()); detailProjectController.getMultiDB().setSelected(currentProject.getMultiDB()); detailProjectController.getSysMD().setSelected(currentProject.getSysMD()); + ObservableList toggles = detailProjectController.getDatabase().getToggles(); + Toggle toggle = toggles.get(0); + for (Toggle tog : toggles) { + RadioButton radioButton = (RadioButton) tog; + if (radioButton.getText().equals(currentProject.getDatabase())) { + toggle = radioButton; + } + } + detailProjectController.getDatabase().selectToggle(toggle); + detailProjectController.getCloud().setSelected(currentProject.isCloud()); if (gridPane != null) { mDetail.getChildren().clear(); @@ -1114,20 +1130,20 @@ public class JavaFxApplication extends Application { switch (level) { case 0: {//编辑项目名称 - dBmanager.getProject().setProjectName((String) event.getNewValue()); + projectManager.getProject().setProjectName((String) event.getNewValue()); loadingProject(); } break; case 1: {//编辑模块 - Module md = dBmanager.findDBByDBName((String) event.getOldValue()); + Module md = projectManager.findDBByDBName((String) event.getOldValue()); md.setModuleName((String) event.getNewValue()); loadingModule(); } break; case 2: {//编辑对象 TreeItem parent = treeItem.getParent(); - Module md = dBmanager.findDBByDBName((String) parent.getValue()); - Table table = dBmanager.findTableByTableName(md, (String) event.getOldValue()); + Module md = projectManager.findDBByDBName((String) parent.getValue()); + Table table = projectManager.findTableByTableName(md, (String) event.getOldValue()); if (table != null) { table.setTableName((String) event.getNewValue()); loadingTable(); @@ -1166,24 +1182,24 @@ public class JavaFxApplication extends Application { case "向上调整": if (index > 0) { - Tool.exchange(dBmanager.getProject().getModules(), index - 1, index); - Tool.exchange(dBmanager.getProject().getChildren(), index - 1, index); + Tool.exchange(projectManager.getProject().getModules(), index - 1, index); + Tool.exchange(projectManager.getProject().getChildren(), index - 1, index); } break; case "向下调整": - List mds = dBmanager.getMds(); + List mds = projectManager.getMds(); if (index < mds.size() - 1) { - Tool.exchange(dBmanager.getProject().getModules(), index, index + 1); - Tool.exchange(dBmanager.getProject().getChildren(), index, index + 1); + Tool.exchange(projectManager.getProject().getModules(), index, index + 1); + Tool.exchange(projectManager.getProject().getChildren(), index, index + 1); } break; case "新增模块": - dBmanager.getNewModuleName(); + projectManager.getNewModuleName(); break; case "删除模块": if (targetItem != null && targetItem.getParent() == project) { currentProject.getChildren().remove(targetItem); - boolean b = dBmanager.removeDBByDBName((String) targetItem.getValue()); + boolean b = projectManager.removeDBByDBName((String) targetItem.getValue()); if (b) { System.out.println("删除模块" + targetItem.getValue() + "成功!"); } @@ -1195,9 +1211,9 @@ public class JavaFxApplication extends Application { switch (level) { case 1: {//对模块右击 System.out.println("模块:" + targetItem.getValue()); - Module md = dBmanager.findDBByDBName((String) targetItem.getValue()); + Module md = projectManager.findDBByDBName((String) targetItem.getValue()); if (md != null) { - Table newTableName = dBmanager.getNewTableName(md); + Table newTableName = projectManager.getNewTableName(md); targetItem.getChildren().add(newTableName); } } @@ -1205,8 +1221,8 @@ public class JavaFxApplication extends Application { case 2: {//对对象右击 TreeItem parent = targetItem.getParent(); System.out.println("对象:" + parent.getValue()); - Module md = dBmanager.findDBByDBName((String) parent.getValue()); - Table newTableName = dBmanager.getNewTableName(md); + Module md = projectManager.findDBByDBName((String) parent.getValue()); + Table newTableName = projectManager.getNewTableName(md); parent.getChildren().add(new TreeItem<>(newTableName.getTableName())); break; } @@ -1224,15 +1240,15 @@ public class JavaFxApplication extends Application { switch (level) { case 0: {//对模块右击 System.out.println("模块:" + targetItem.getValue()); - Module md = dBmanager.findDBByDBName((String) targetItem.getValue()); - Table newTableName = dBmanager.getNewTableName(md); + Module md = projectManager.findDBByDBName((String) targetItem.getValue()); + Table newTableName = projectManager.getNewTableName(md); targetItem.getChildren().add(new TreeItem<>(newTableName.getTableName())); } break; case 1: {//对对象右击 TreeItem parent = targetItem.getParent(); System.out.println("对象:" + parent.getValue()); - Module md = dBmanager.findDBByDBName((String) parent.getValue()); + Module md = projectManager.findDBByDBName((String) parent.getValue()); for (Table table : md.getTables()) { if (table.getTableName().equals(targetItem.getValue())) { @@ -1252,7 +1268,7 @@ public class JavaFxApplication extends Application { } else if (text != null && targetItem == null) { switch (text) { case "新增模块": - dBmanager.getNewModuleName(); + projectManager.getNewModuleName(); break; default: break; diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java index 9f08039c..d8a4850a 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java @@ -12,8 +12,6 @@ import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; import xyz.wbsite.dbtool.javafx.JavaFxApplication; -import xyz.wbsite.dbtool.javafx.enums.DataBase; -import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener; import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; import xyz.wbsite.dbtool.javafx.manger.ProjectManager; import xyz.wbsite.dbtool.javafx.tool.Dialog; @@ -174,14 +172,8 @@ public class MainController { File file = directoryChooser.showDialog(stage); if (file != null) { - //展示生成方式 - Dialog.showGenerateOption(new GenerateOptionListener() { - @Override - public void onGenerate(String option, DataBase dataBase) { - System.out.println("生成目录:" + file.getAbsolutePath()); - dBmanger.generate(file.getAbsolutePath(), option, dataBase); - } - }); + System.out.println("生成目录:" + file.getAbsolutePath()); + dBmanger.generate(ManagerFactory.getProjectManager().getProject(), file.getAbsolutePath()); } } } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/JsonManager.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/JsonManager.java new file mode 100644 index 00000000..ebb77ce0 --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/JsonManager.java @@ -0,0 +1,37 @@ +package xyz.wbsite.dbtool.javafx.manger; + +import xyz.wbsite.dbtool.javafx.po.Project; +import xyz.wbsite.dbtool.web.frame.utils.FileUtil; +import xyz.wbsite.dbtool.web.frame.utils.MapperUtil; + +import java.io.File; +import java.io.IOException; + +public class JsonManager { + + public Project inflate(String json) { + Project project = MapperUtil.toJava(json, Project.class); + return project; + } + + public Project inflate(File json) { + try { + return inflate(FileUtil.readFileToString(json)); + } catch (IOException e) { + e.printStackTrace(); + return new Project(); + } + } + + public boolean saveAs(File file, Project project) { + String data = MapperUtil.toJson(project); + return FileUtil.writeStringToFile(data, file, false, false); + } + + private boolean getBoolean(String str) { + if (str != null && str.matches("true|1")) { + return true; + } + return false; + } +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ManagerFactory.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ManagerFactory.java index 98cc7b1b..5e971962 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ManagerFactory.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ManagerFactory.java @@ -4,12 +4,14 @@ import xyz.wbsite.dbtool.javafx.JavaFxApplication; public class ManagerFactory { private static XmlManager xmlManager = null; + private static JsonManager jsonManager = null; private static ReflashManager reflashManager = null; private static ProjectManager projectManager; private static FreeMarkerManager freeMarkerManager; static { xmlManager = new XmlManager(); + jsonManager = new JsonManager(); projectManager = new ProjectManager(); freeMarkerManager = new FreeMarkerManager(); } @@ -22,11 +24,14 @@ public class ManagerFactory { return freeMarkerManager; } - public static XmlManager getXmlManager() { return xmlManager; } + public static JsonManager getJsonManager() { + return jsonManager; + } + public static ReflashManager getReflashManager(JavaFxApplication main) { if (reflashManager == null) { reflashManager = new ReflashManager(main); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java index 74d3fae1..389f3084 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java @@ -7,7 +7,6 @@ import xyz.wbsite.dbtool.javafx.manger.callable.AndroidCallable; import xyz.wbsite.dbtool.javafx.manger.callable.ApiCallable; import xyz.wbsite.dbtool.javafx.manger.callable.SBMDBCallable; import xyz.wbsite.dbtool.javafx.manger.callable.SpringBootCallable; -import xyz.wbsite.dbtool.javafx.manger.callable.SpringMVCCallable; import xyz.wbsite.dbtool.javafx.manger.callable.VueCallable; import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper; import xyz.wbsite.dbtool.javafx.po.AndroidOption; @@ -43,12 +42,14 @@ public class ProjectManager { public static boolean isUpdate = false; private XmlManager xmlService; + private JsonManager jsonManager; public static AbstractDBmapper dBmapper; public static File path; private Project project = new Project(); public ProjectManager() { xmlService = ManagerFactory.getXmlManager(); + jsonManager = ManagerFactory.getJsonManager(); try { ApplicationHome home = new ApplicationHome(getClass()); File jarFile = home.getSource(); @@ -308,10 +309,12 @@ public class ProjectManager { */ public void save(File file) { xmlService.saveAs(file, project); +// jsonManager.saveAs(new File(file.getAbsolutePath().replaceAll("xml$", "json")), project); } public void save() { xmlService.saveAs(path, project); +// jsonManager.saveAs(new File(path.getAbsolutePath().replaceAll("xml$", "json")), project); } public void delete() { @@ -323,13 +326,13 @@ public class ProjectManager { private static ExecutorService service = Executors.newFixedThreadPool(1); - public void tryGetDBmapper(DataBase dataBase) { - if (dataBase.name().equals(DataBase.MySQL.name())) { - dBmapper = new MySQLDBmapper(dataBase); - } else if (dataBase.name().equals(DataBase.Oracle.name())) { - dBmapper = new OracleDBmapper(dataBase); - } else if (dataBase.name().equals(DataBase.SQLite.name())) { - dBmapper = new SQLiteDBmapper(dataBase); + public void tryGetDBmapper(Project project) { + if (project.getDatabase().equals(DataBase.MySQL.name())) { + dBmapper = new MySQLDBmapper(); + } else if (project.getDatabase().equals(DataBase.Oracle.name())) { + dBmapper = new OracleDBmapper(); + } else if (project.getDatabase().equals(DataBase.SQLite.name())) { + dBmapper = new SQLiteDBmapper(); } } @@ -338,8 +341,8 @@ public class ProjectManager { * * @param path */ - public void generate(final String path, final String option, final DataBase dataBase) { - tryGetDBmapper(dataBase); + public void generate(Project project, final String path) { + tryGetDBmapper(project); File root = new File(path); if (!root.exists()) { @@ -350,19 +353,7 @@ public class ProjectManager { @Override public void run() { Callable callback = null; - switch (option) { - case "SpringBoot": - callback = new SpringBootCallable(path, dataBase, project, option, false); - break; - case "SpringBoot+Cloud": - callback = new SpringBootCallable(path, dataBase, project, "SpringBoot", true); - break; - case "SpringMVC_Mybatis": - callback = new SpringMVCCallable(path, dataBase, project, option); - break; - default: - - } + callback = new SpringBootCallable(project, path); Future submit = service.submit(callback); try { @@ -532,7 +523,7 @@ public class ProjectManager { if ("Orcale".equals(type)) { try { - dBmapper = new OracleDBmapper(DataBase.Oracle); + dBmapper = new OracleDBmapper(); //加载驱动类 Class.forName(driverClassName); @@ -603,7 +594,7 @@ public class ProjectManager { } } else if ("Mysql".equals(type)) { try { - dBmapper = new MySQLDBmapper(DataBase.MySQL); + dBmapper = new MySQLDBmapper(); //加载驱动类 Class.forName(driverClassName); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java index e549eb1b..92297c7f 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java @@ -63,12 +63,11 @@ public class XmlManager { } else if (declaredField.getType() == Boolean.class || declaredField.getType() == boolean.class) { declaredField.setBoolean(project, getBoolean(textContent)); } - System.out.println("读取" + value + "=" + textContent); +// System.out.println("读取" + value + "=" + textContent); } } } - NodeList modules = dbElement.getElementsByTagName("module"); if (modules.getLength() > 0) { @@ -181,7 +180,7 @@ public class XmlManager { Object valuer = declaredField.get(project); element.setTextContent(String.valueOf(valuer)); rootProject.appendChild(element); - System.out.println("写入" + value + "=" + String.valueOf(valuer)); +// System.out.println("写入" + value + "=" + String.valueOf(valuer)); } } catch (IllegalAccessException e) { e.printStackTrace(); 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 e6042ff5..9f35bc76 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 @@ -28,17 +28,15 @@ public class SpringBootCallable implements Callable { private String root; private DataBase dataBase; private Project project; - private String option; private boolean cloud; private AbstractDBmapper dBmapper; private FreeMarkerManager freeMarkerManager; - public SpringBootCallable(String root, DataBase dataBase, Project project, String option, boolean cloud) { + public SpringBootCallable(Project project, String root) { this.root = root; - this.dataBase = dataBase; + this.dataBase = DataBase.valueOf(project.getDatabase()); this.project = project; - this.option = option; - this.cloud = cloud; + this.cloud = project.isCloud(); this.freeMarkerManager = ManagerFactory.getFreeMarkerManager(); this.dBmapper = ProjectManager.dBmapper; } @@ -68,17 +66,17 @@ public class SpringBootCallable implements Callable { File testResourcesDir = Tool.createPath(projectDir.getAbsolutePath(), "src", "test", "resources"); // 生成POM - generatePom(projectDir, project, dataBase, option); + generatePom(projectDir, project, dataBase); {//生成java文件 //生成 Controller System.out.println("生成模块:action"); - generateController(Tool.createPath(domainDir.getAbsolutePath(), "action"), project, dataBase, option); + generateController(Tool.createPath(domainDir.getAbsolutePath(), "action"), project, dataBase); // 生成 Config System.out.println("生成模块:config"); - generateConfig(Tool.createPath(domainDir.getAbsolutePath(), "config"), project, dataBase, option); + generateConfig(Tool.createPath(domainDir.getAbsolutePath(), "config"), project, dataBase); {// 模块 @@ -90,15 +88,15 @@ public class SpringBootCallable implements Callable { File moduleDir = Tool.createPath(domainDir.getAbsolutePath(), "module", module.getModuleName()); System.out.println("生成模块:Entity"); - generateEntity(Tool.createPath(moduleDir.getAbsolutePath(), "ent"), module, dataBase, option); + generateEntity(Tool.createPath(moduleDir.getAbsolutePath(), "ent"), module, dataBase); System.out.println("生成模块:Mapper"); - generateMapper(Tool.createPath(moduleDir.getAbsolutePath(), "mpr"), module, dataBase, option); + generateMapper(Tool.createPath(moduleDir.getAbsolutePath(), "mpr"), module, dataBase); System.out.println("生成模块:Manager"); - generateManager(Tool.createPath(moduleDir.getAbsolutePath(), "mgr"), module, dataBase, option); + generateManager(Tool.createPath(moduleDir.getAbsolutePath(), "mgr"), module, dataBase); System.out.println("生成模块:Request"); - generateRequest(Tool.createPath(moduleDir.getAbsolutePath(), "req"), module, dataBase, option); + generateRequest(Tool.createPath(moduleDir.getAbsolutePath(), "req"), module, dataBase); System.out.println("生成模块:Response"); - generateResponse(Tool.createPath(moduleDir.getAbsolutePath(), "rsp"), module, dataBase, option); + generateResponse(Tool.createPath(moduleDir.getAbsolutePath(), "rsp"), module, dataBase); } if (project.getSysMD()) {//生成系统模块 @@ -108,40 +106,40 @@ public class SpringBootCallable implements Callable { module.setProjectBasePackage(project.getProjectBasePackage()); module.setProjectName(project.getProjectName()); File moduleDir = Tool.createPath(domainDir.getAbsolutePath(), "module", "system"); - generateSystemModule(moduleDir, module, dataBase, option); + generateSystemModule(moduleDir, module, dataBase); } } // frame等内容 System.out.println("生成模块:frame"); - generateFrame(Tool.createPath(domainDir.getAbsolutePath(), "frame"), project, dataBase, option); + generateFrame(Tool.createPath(domainDir.getAbsolutePath(), "frame"), project, dataBase); // Task System.out.println("生成模块:task"); - generateTask(Tool.createPath(domainDir.getAbsolutePath(), "task"), project, dataBase, option); + generateTask(Tool.createPath(domainDir.getAbsolutePath(), "task"), project, dataBase); // Application System.out.println("生成模块:Application"); - generateApplication(Tool.createPath(domainDir.getAbsolutePath()), project, dataBase, option); + generateApplication(Tool.createPath(domainDir.getAbsolutePath()), project, dataBase); } {//生成resources文件 System.out.println("生成模块:Resources"); - generateResources(resourcesDir, project, dataBase, option); + generateResources(resourcesDir, project, dataBase); System.out.println("生成模块:Static"); - generateStatic(resourcesDir, project, dataBase, option); + generateStatic(resourcesDir, project, dataBase); System.out.println("生成模块:Templates"); - generateTemplates(resourcesDir, project, dataBase, option); + generateTemplates(resourcesDir, project, dataBase); } {//生成Test System.out.println("生成模块:Test"); - generateTest(testDomainDir, project, dataBase, option); + generateTest(testDomainDir, project, dataBase); } {//生成Test Resources System.out.println("生成模块:Test Resources"); - generateTestResources(testResourcesDir, project, dataBase, option); + generateTestResources(testResourcesDir, project, dataBase); } System.out.println("finish"); return true; @@ -154,13 +152,13 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generatePom(File root, Project project, DataBase dataBase, String option) { + public void generatePom(File root, Project project, DataBase dataBase) { HashMap ctx = new HashMap(); ctx.put("projectName", project.getProjectName()); ctx.put("basePackage", project.getProjectBasePackage()); ctx.put("dataBase", dataBase.toString()); ctx.put("cloud", cloud); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "pom.xml"), option + "/pom.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "pom.xml"), "SpringBoot/pom.ftl", ctx); } /** @@ -169,7 +167,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateController(File root, Project project, DataBase dataBase, String option) { + public void generateController(File root, Project project, DataBase dataBase) { Tool.clear(root); HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); @@ -179,7 +177,7 @@ public class SpringBootCallable implements Callable { File control = Tool.createPath(root.getAbsolutePath(), "control"); File screen = Tool.createPath(root.getAbsolutePath(), "screen"); - freeMarkerManager.outputTemp(Tool.createFile(control.getAbsolutePath(), "Header.java"), option + "/java/action/control/Header.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(control.getAbsolutePath(), "Header.java"), "SpringBoot/java/action/control/Header.java", ctx); { File ajax = Tool.createPath(root.getAbsolutePath(), "ajax"); @@ -195,7 +193,7 @@ public class SpringBootCallable implements Callable { ctxss.put("date", new Date()); ctxss.put("table", table); - freeMarkerManager.outputTemp(Tool.createFile(m.getAbsolutePath(), table.getCName() + "Ajax.java"), option + "/java/action/ajax/Ajax.java", ctxss); + freeMarkerManager.outputTemp(Tool.createFile(m.getAbsolutePath(), table.getCName() + "Ajax.java"), "SpringBoot/java/action/ajax/Ajax.java", ctxss); } } @@ -203,7 +201,7 @@ public class SpringBootCallable implements Callable { File system = Tool.createPath(ajax.getAbsolutePath(), "system"); for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/action/ajax/system/")) { - freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), option + "/java/action/ajax/system/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), "SpringBoot/java/action/ajax/system/" + name, ctx); } } } @@ -221,7 +219,7 @@ public class SpringBootCallable implements Callable { ctxss.put("author", project.getProjectAuthor()); ctxss.put("date", new Date()); ctxss.put("table", table); - freeMarkerManager.outputTemp(Tool.createFile(m.getAbsolutePath(), table.getCName() + "Api.java"), option + "/java/action/api/Api.java", ctxss); + freeMarkerManager.outputTemp(Tool.createFile(m.getAbsolutePath(), table.getCName() + "Api.java"), "SpringBoot/java/action/api/Api.java", ctxss); } } @@ -229,15 +227,15 @@ public class SpringBootCallable implements Callable { File system = Tool.createPath(api.getAbsolutePath(), "system"); for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/action/api/system/")) { - freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), option + "/java/action/api/system/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), "SpringBoot/java/action/api/system/" + name, ctx); } } } - freeMarkerManager.outputTemp(Tool.createFile(screen.getAbsolutePath(), "Index.java"), option + "/java/action/screen/Index.java", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "GlobalController.java"), option + "/java/action/GlobalController.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(screen.getAbsolutePath(), "Index.java"), "SpringBoot/java/action/screen/Index.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "GlobalController.java"), "SpringBoot/java/action/GlobalController.java", ctx); } - public void generateConfig(File root, Project project, DataBase dataBase, String option) { + public void generateConfig(File root, Project project, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -250,19 +248,19 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); //config - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ActionConfig.java"), option + "/java/config/ActionConfig.java", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "CacheConfig.java"), option + "/java/config/CacheConfig.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(), "ScheduleConfig.java"), option + "/java/config/ScheduleConfig.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); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ActionConfig.java"), "SpringBoot/java/config/ActionConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "CacheConfig.java"), "SpringBoot/java/config/CacheConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "FreeMarkerConfig.java"), "SpringBoot/java/config/FreeMarkerConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SecurityConfig.java"), "SpringBoot/java/config/SecurityConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ScheduleConfig.java"), "SpringBoot/java/config/ScheduleConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ThreadPoolConfig.java"), "SpringBoot/java/config/ThreadPoolConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "WebMvcConfig.java"), "SpringBoot/java/config/WebMvcConfig.java", ctx); if (dataBase.name().equals(DataBase.SQLite.name())) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SQLiteConfig.java"), option + "/java/config/SQLiteConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SQLiteConfig.java"), "SpringBoot/java/config/SQLiteConfig.java", ctx); } if (project.getMultiDB()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "MapperMainConfig.java"), option + "/java/config/MapperMainConfig.java", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "MapperTwoConfig.java"), option + "/java/config/MapperTwoConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "MapperMainConfig.java"), "SpringBoot/java/config/MapperMainConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "MapperTwoConfig.java"), "SpringBoot/java/config/MapperTwoConfig.java", ctx); } } @@ -272,7 +270,7 @@ public class SpringBootCallable implements Callable { * @param root * @param md */ - public void generateEntity(File root, Module md, DataBase dataBase, String option) { + public void generateEntity(File root, Module md, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -289,7 +287,7 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); File file = Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + ".java"); - freeMarkerManager.outputTemp(file, option + "/java/module/ent/entity.ftl", ctx); + freeMarkerManager.outputTemp(file, "SpringBoot/java/module/ent/entity.ftl", ctx); } } @@ -299,7 +297,7 @@ public class SpringBootCallable implements Callable { * @param root * @param md */ - public void generateMapper(File root, Module md, DataBase dataBase, String option) { + public void generateMapper(File root, Module md, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -317,18 +315,18 @@ public class SpringBootCallable implements Callable { for (Table table : md.getTables()) { ctx.put("table", table); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/module/mpr/mapper.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), "SpringBoot/java/module/mpr/mapper.java", ctx); if (table.getSys()) { -// freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), dataBase.name() + "_" + Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/module/mpr/" + dataBase.name() + "_mapper.xml", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/module/mpr/" + dataBase.name() + "_mapper.xml", ctx); +// freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), dataBase.name() + "_" + Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), "SpringBoot/java/module/mpr/" + dataBase.name() + "_mapper.xml", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), "SpringBoot/java/module/mpr/" + dataBase.name() + "_mapper.xml", ctx); } else { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/module/mpr/Nosys_mapper.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), "SpringBoot/java/module/mpr/Nosys_mapper.ftl", ctx); } } } - public void generateManager(File root, Module md, DataBase dataBase, String option) { + public void generateManager(File root, Module md, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -345,8 +343,8 @@ public class SpringBootCallable implements Callable { for (Table table : md.getTables()) { ctx.put("table", table); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/module/mgr/manager.ftl", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/module/mgr/managerImpl.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), "SpringBoot/java/module/mgr/manager.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), "SpringBoot/java/module/mgr/managerImpl.ftl", ctx); } } @@ -356,7 +354,7 @@ public class SpringBootCallable implements Callable { * @param root * @param md */ - public void generateRequest(File root, Module md, DataBase dataBase, String option) { + public void generateRequest(File root, Module md, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -372,34 +370,34 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); if (md.getModuleName().equals("api")) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiExampleRequest" + ".java"), option + "/java/module/req/ApiExampleRequest.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiExampleRequest" + ".java"), "SpringBoot/java/module/req/ApiExampleRequest.java", ctx); } for (Table table : md.getTables()) { ctx.put("table", table); if (table.getCreate()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateRequest" + ".java"), option + "/java/module/req/createRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateRequest" + ".java"), "SpringBoot/java/module/req/createRequestClass.ftl", ctx); } if (table.getDelete()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteRequest" + ".java"), option + "/java/module/req/deleteRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteRequest" + ".java"), "SpringBoot/java/module/req/deleteRequestClass.ftl", ctx); } if (table.getUpdate()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateRequest" + ".java"), option + "/java/module/req/updateRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateRequest" + ".java"), "SpringBoot/java/module/req/updateRequestClass.ftl", ctx); } if (table.getFind()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindRequest" + ".java"), option + "/java/module/req/findRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindRequest" + ".java"), "SpringBoot/java/module/req/findRequestClass.ftl", ctx); } if (table.getGet()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetRequest" + ".java"), option + "/java/module/req/getRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetRequest" + ".java"), "SpringBoot/java/module/req/getRequestClass.ftl", ctx); } if (table.getSearch()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchRequest" + ".java"), option + "/java/module/req/searchRequestClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchRequest" + ".java"), "SpringBoot/java/module/req/searchRequestClass.ftl", ctx); } } } @@ -410,7 +408,7 @@ public class SpringBootCallable implements Callable { * @param root * @param md */ - public void generateResponse(File root, Module md, DataBase dataBase, String option) { + public void generateResponse(File root, Module md, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -426,39 +424,39 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); if (md.getModuleName().equals("api")) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiExampleResponse" + ".java"), option + "/java/module/rsp/ApiExampleResponse.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiExampleResponse" + ".java"), "SpringBoot/java/module/rsp/ApiExampleResponse.java", ctx); } for (Table table : md.getTables()) { ctx.put("table", table); if (table.getCreate()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateResponse" + ".java"), option + "/java/module/rsp/createResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateResponse" + ".java"), "SpringBoot/java/module/rsp/createResponseClass.ftl", ctx); } if (table.getDelete()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteResponse" + ".java"), option + "/java/module/rsp/deleteResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteResponse" + ".java"), "SpringBoot/java/module/rsp/deleteResponseClass.ftl", ctx); } if (table.getUpdate()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateResponse" + ".java"), option + "/java/module/rsp/updateResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateResponse" + ".java"), "SpringBoot/java/module/rsp/updateResponseClass.ftl", ctx); } if (table.getFind()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindResponse" + ".java"), option + "/java/module/rsp/findResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindResponse" + ".java"), "SpringBoot/java/module/rsp/findResponseClass.ftl", ctx); } if (table.getGet()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetResponse" + ".java"), option + "/java/module/rsp/getResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetResponse" + ".java"), "SpringBoot/java/module/rsp/getResponseClass.ftl", ctx); } if (table.getSearch()) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchResponse" + ".java"), option + "/java/module/rsp/searchResponseClass.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchResponse" + ".java"), "SpringBoot/java/module/rsp/searchResponseClass.ftl", ctx); } } } - public void generateSystemModule(File root, Module md, DataBase dataBase, String option) { + public void generateSystemModule(File root, Module md, DataBase dataBase) { File ent = Tool.createPath(root.getAbsolutePath(), "ent"); File mpr = Tool.createPath(root.getAbsolutePath(), "mpr"); File mgr = Tool.createPath(root.getAbsolutePath(), "mgr"); @@ -473,29 +471,29 @@ public class SpringBootCallable implements Callable { ctx.put("dataBase", dataBase.toString()); for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/system/ent/")) { - freeMarkerManager.outputTemp(Tool.createFile(ent.getAbsolutePath(), name), option + "/java/module/system/ent/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(ent.getAbsolutePath(), name), "SpringBoot/java/module/system/ent/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/system/mgr/")) { - freeMarkerManager.outputTemp(Tool.createFile(mgr.getAbsolutePath(), name), option + "/java/module/system/mgr/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(mgr.getAbsolutePath(), name), "SpringBoot/java/module/system/mgr/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/system/mpr/")) { if (name.endsWith(".java")) { - freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name), option + "/java/module/system/mpr/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name), "SpringBoot/java/module/system/mpr/" + name, ctx); } else if (name.contains(dataBase.name())) { //todo dateBase调试 -// freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name), option + "/java/module/system/mpr/" + name, ctx); - freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name.replaceAll(dataBase.name() + "_", "")), option + "/java/module/system/mpr/" + name, ctx); +// freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name), "SpringBoot/java/module/system/mpr/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(mpr.getAbsolutePath(), name.replaceAll(dataBase.name() + "_", "")), "SpringBoot/java/module/system/mpr/" + name, ctx); } } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/system/req/")) { - freeMarkerManager.outputTemp(Tool.createFile(req.getAbsolutePath(), name), option + "/java/module/system/req/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(req.getAbsolutePath(), name), "SpringBoot/java/module/system/req/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/module/system/rsp/")) { - freeMarkerManager.outputTemp(Tool.createFile(rsp.getAbsolutePath(), name), option + "/java/module/system/rsp/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(rsp.getAbsolutePath(), name), "SpringBoot/java/module/system/rsp/" + name, ctx); } } @@ -505,7 +503,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateFrame(File root, Project project, DataBase dataBase, String option) { + public void generateFrame(File root, Project project, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -529,43 +527,43 @@ public class SpringBootCallable implements Callable { //auth for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/auth/")) { - freeMarkerManager.outputTemp(Tool.createFile(auth.getAbsolutePath(), name), option + "/java/frame/auth/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(auth.getAbsolutePath(), name), "SpringBoot/java/frame/auth/" + name, ctx); } //base for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/base/")) { - freeMarkerManager.outputTemp(Tool.createFile(base.getAbsolutePath(), name), option + "/java/frame/base/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(base.getAbsolutePath(), name), "SpringBoot/java/frame/base/" + name, ctx); } //excel for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/")) { - freeMarkerManager.outputTemp(Tool.createFile(excel.getAbsolutePath(), name), option + "/java/frame/excel/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(excel.getAbsolutePath(), name), "SpringBoot/java/frame/excel/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/annotation/")) { - freeMarkerManager.outputTemp(Tool.createFile(excelannotation.getAbsolutePath(), name), option + "/java/frame/excel/annotation/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(excelannotation.getAbsolutePath(), name), "SpringBoot/java/frame/excel/annotation/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/converter/")) { - freeMarkerManager.outputTemp(Tool.createFile(excelconverter.getAbsolutePath(), name), option + "/java/frame/excel/converter/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(excelconverter.getAbsolutePath(), name), "SpringBoot/java/frame/excel/converter/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/exception/")) { - freeMarkerManager.outputTemp(Tool.createFile(exception.getAbsolutePath(), name), option + "/java/frame/excel/exception/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(exception.getAbsolutePath(), name), "SpringBoot/java/frame/excel/exception/" + name, ctx); } for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/excel/style/")) { - freeMarkerManager.outputTemp(Tool.createFile(excelstyle.getAbsolutePath(), name), option + "/java/frame/excel/style/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(excelstyle.getAbsolutePath(), name), "SpringBoot/java/frame/excel/style/" + name, ctx); } //schedule for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/schedule/")) { - freeMarkerManager.outputTemp(Tool.createFile(schedule.getAbsolutePath(), name), option + "/java/frame/schedule/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(schedule.getAbsolutePath(), name), "SpringBoot/java/frame/schedule/" + name, ctx); } //utils for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/utils/")) { - freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), name), option + "/java/frame/utils/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), name), "SpringBoot/java/frame/utils/" + name, ctx); } //validation for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/validation/")) { - freeMarkerManager.outputTemp(Tool.createFile(validation.getAbsolutePath(), name), option + "/java/frame/validation/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(validation.getAbsolutePath(), name), "SpringBoot/java/frame/validation/" + name, ctx); } } @@ -576,7 +574,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateTask(File root, Project project, DataBase dataBase, String option) { + public void generateTask(File root, Project project, DataBase dataBase) { if (!root.exists()) { root.mkdirs(); } else { @@ -589,7 +587,7 @@ public class SpringBootCallable implements Callable { //task for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/task/")) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), name), option + "/java/task/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), name), "SpringBoot/java/task/" + name, ctx); } } @@ -599,7 +597,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateApplication(File root, Project project, DataBase dataBase, String option) { + public void generateApplication(File root, Project project, DataBase dataBase) { HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); @@ -607,7 +605,7 @@ public class SpringBootCallable implements Callable { ctx.put("multiDB", project.getMultiDB()); ctx.put("timestamp", new Date().getTime()); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "Application.java"), option + "/java/Application.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "Application.java"), "SpringBoot/java/Application.ftl", ctx); } /** @@ -616,7 +614,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateResources(File root, Project project, DataBase dataBase, String option) { + public void generateResources(File root, Project project, DataBase dataBase) { HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); @@ -629,11 +627,11 @@ public class SpringBootCallable implements Callable { ctx.put("projectName", project.getProjectName()); ctx.put("multiDB", project.getMultiDB()); ctx.put("cloud", cloud); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "start-dev.bat"), option + "/resources/start-dev.bat", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "start-prod.bat"), option + "/resources/start-prod.bat", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application-dev.properties"), option + "/resources/application-dev.ftl", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application-prod.properties"), option + "/resources/application-prod.ftl", ctx); - Tool.outputResource(option + "/resources/logback-spring.xml", Tool.createFile(root.getAbsolutePath(), "logback-spring.xml")); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "start-dev.bat"), "SpringBoot/resources/start-dev.bat", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "start-prod.bat"), "SpringBoot/resources/start-prod.bat", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application-dev.properties"), "SpringBoot/resources/application-dev.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application-prod.properties"), "SpringBoot/resources/application-prod.ftl", ctx); + Tool.outputResource("SpringBoot/resources/logback-spring.xml", Tool.createFile(root.getAbsolutePath(), "logback-spring.xml")); File dbtool = Tool.createPath(root.getAbsolutePath(), "dbtool"); { @@ -647,9 +645,9 @@ public class SpringBootCallable implements Callable { File tableDir = Tool.createPath(dbtool.getAbsolutePath(), module.getModuleName() + "_table"); for (Table table : module.getTables()) { ctx.put("table", table); - freeMarkerManager.outputTemp(Tool.createFile(tableDir.getAbsolutePath(), dataBase.name() + "_" + table.getTableName() + ".sql"), option + "/resources/dbtool/table.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(tableDir.getAbsolutePath(), dataBase.name() + "_" + table.getTableName() + ".sql"), "SpringBoot/resources/dbtool/table.ftl", ctx); } - freeMarkerManager.outputTemp(Tool.createFile(tableDir.getAbsolutePath(), dataBase.name() + "_ALL_TABLE" + ".sql"), option + "/resources/dbtool/tableAll.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(tableDir.getAbsolutePath(), dataBase.name() + "_ALL_TABLE" + ".sql"), "SpringBoot/resources/dbtool/tableAll.ftl", ctx); } if (project.getSysMD()) {//生成系统模块 @@ -657,14 +655,14 @@ public class SpringBootCallable implements Callable { for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/resources/dbtool/system/")) { if (name.contains(dataBase.name())) { - freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), option + "/resources/dbtool/system/" + name, ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), name), "SpringBoot/resources/dbtool/system/" + name, ctx); } } } if (DataBase.Oracle.name().equals(dataBase.name())) { File lib = Tool.createPath(root.getAbsolutePath(), "lib"); - Tool.outputResource(option + "/resources/lib/ojdbc7-12.1.0.2.jar", Tool.createFile(lib.getAbsolutePath(), "ojdbc7-12.1.0.2.jar")); + Tool.outputResource("SpringBoot/resources/lib/ojdbc7-12.1.0.2.jar", Tool.createFile(lib.getAbsolutePath(), "ojdbc7-12.1.0.2.jar")); } if (DataBase.SQLite.name().equals(dataBase.name())) { @@ -701,7 +699,7 @@ public class SpringBootCallable implements Callable { } } - public void generateTestResources(File root, Project project, DataBase dataBase, String option) { + public void generateTestResources(File root, Project project, DataBase dataBase) { HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); @@ -713,8 +711,8 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); ctx.put("multiDB", project.getMultiDB()); ctx.put("cloud", cloud); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application.properties"), option + "/test/application.ftl", ctx); - Tool.outputResource(option + "/test/logback-spring.xml", Tool.createFile(root.getAbsolutePath(), "logback-spring.xml")); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "application.properties"), "SpringBoot/test/application.ftl", ctx); + Tool.outputResource("SpringBoot/test/logback-spring.xml", Tool.createFile(root.getAbsolutePath(), "logback-spring.xml")); } /** @@ -723,7 +721,7 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateStatic(File root, Project project, DataBase dataBase, String option) { + public void generateStatic(File root, Project project, DataBase dataBase) { HashMap ctx = new HashMap(); ctx.put("basePackage", project.getProjectBasePackage()); @@ -738,29 +736,29 @@ public class SpringBootCallable implements Callable { File dist = Tool.createPath(static_.getAbsolutePath(), "dist"); { - Tool.outputResource(option + "/resources/static/favicon.ico", Tool.createFile(static_.getAbsolutePath(), "favicon.ico")); + Tool.outputResource("SpringBoot/resources/static/favicon.ico", Tool.createFile(static_.getAbsolutePath(), "favicon.ico")); } {//css文件 - freeMarkerManager.outputTemp(Tool.createFile(css.getAbsolutePath(), "base.css"), option + "/resources/static/css/base.css", ctx); + freeMarkerManager.outputTemp(Tool.createFile(css.getAbsolutePath(), "base.css"), "SpringBoot/resources/static/css/base.css", ctx); } {//img - Tool.outputResource(option + "/resources/static/img/logo.png", Tool.createFile(img.getAbsolutePath(), "logo.png")); + Tool.outputResource("SpringBoot/resources/static/img/logo.png", Tool.createFile(img.getAbsolutePath(), "logo.png")); } {//dist文件 //jquery + vue + vue-router + axios - Tool.outputResource(option + "/resources/static/dist/lib.min.js", Tool.createFile(dist.getAbsolutePath(), "lib.min.js")); + Tool.outputResource("SpringBoot/resources/static/dist/lib.min.js", Tool.createFile(dist.getAbsolutePath(), "lib.min.js")); //element-ui - Tool.outputResource(option + "/resources/static/dist/index.min.js", Tool.createFile(dist.getAbsolutePath(), "index.min.js")); - Tool.outputResource(option + "/resources/static/dist/index.min.css", Tool.createFile(dist.getAbsolutePath(), "index.min.css")); + Tool.outputResource("SpringBoot/resources/static/dist/index.min.js", Tool.createFile(dist.getAbsolutePath(), "index.min.js")); + Tool.outputResource("SpringBoot/resources/static/dist/index.min.css", Tool.createFile(dist.getAbsolutePath(), "index.min.css")); File fonts = Tool.createPath(dist.getAbsolutePath(), "fonts"); - Tool.outputResource(option + "/resources/static/dist/fonts/w-e-icon.woff", Tool.createFile(fonts.getAbsolutePath(), "w-e-icon.woff")); - Tool.outputResource(option + "/resources/static/dist/fonts/element-icons.woff", Tool.createFile(fonts.getAbsolutePath(), "element-icons.woff")); - Tool.outputResource(option + "/resources/static/dist/fonts/element-icons.ttf", Tool.createFile(fonts.getAbsolutePath(), "element-icons.ttf")); + Tool.outputResource("SpringBoot/resources/static/dist/fonts/w-e-icon.woff", Tool.createFile(fonts.getAbsolutePath(), "w-e-icon.woff")); + Tool.outputResource("SpringBoot/resources/static/dist/fonts/element-icons.woff", Tool.createFile(fonts.getAbsolutePath(), "element-icons.woff")); + Tool.outputResource("SpringBoot/resources/static/dist/fonts/element-icons.ttf", Tool.createFile(fonts.getAbsolutePath(), "element-icons.ttf")); } } @@ -771,20 +769,20 @@ public class SpringBootCallable implements Callable { * @param root * @param project */ - public void generateTemplates(File root, Project project, DataBase dataBase, String option) { + public void generateTemplates(File root, Project project, DataBase dataBase) { {//生成 File templates = Tool.createPath(root.getAbsolutePath(), "templates"); File control = Tool.createPath(templates.getAbsolutePath(), "control"); File layout = Tool.createPath(templates.getAbsolutePath(), "layout"); File screen = Tool.createPath(templates.getAbsolutePath(), "screen"); - Tool.outputResource(option + "/resources/templates/control/nav.ftl", Tool.createFile(control.getAbsolutePath(), "nav.ftl")); - Tool.outputResource(option + "/resources/templates/control/macro.ftl", Tool.createFile(control.getAbsolutePath(), "macro.ftl")); - Tool.outputResource(option + "/resources/templates/layout/default.ftl", Tool.createFile(layout.getAbsolutePath(), "default.ftl")); - Tool.outputResource(option + "/resources/templates/screen/home.ftl", Tool.createFile(screen.getAbsolutePath(), "home.ftl")); - Tool.outputResource(option + "/resources/templates/screen/login.ftl", Tool.createFile(screen.getAbsolutePath(), "login.ftl")); - Tool.outputResource(option + "/resources/templates/403.ftl", Tool.createFile(templates.getAbsolutePath(), "403.ftl")); - Tool.outputResource(option + "/resources/templates/404.ftl", Tool.createFile(templates.getAbsolutePath(), "404.ftl")); - Tool.outputResource(option + "/resources/templates/500.ftl", Tool.createFile(templates.getAbsolutePath(), "500.ftl")); + Tool.outputResource("SpringBoot/resources/templates/control/nav.ftl", Tool.createFile(control.getAbsolutePath(), "nav.ftl")); + Tool.outputResource("SpringBoot/resources/templates/control/macro.ftl", Tool.createFile(control.getAbsolutePath(), "macro.ftl")); + Tool.outputResource("SpringBoot/resources/templates/layout/default.ftl", Tool.createFile(layout.getAbsolutePath(), "default.ftl")); + Tool.outputResource("SpringBoot/resources/templates/screen/home.ftl", Tool.createFile(screen.getAbsolutePath(), "home.ftl")); + Tool.outputResource("SpringBoot/resources/templates/screen/login.ftl", Tool.createFile(screen.getAbsolutePath(), "login.ftl")); + Tool.outputResource("SpringBoot/resources/templates/403.ftl", Tool.createFile(templates.getAbsolutePath(), "403.ftl")); + Tool.outputResource("SpringBoot/resources/templates/404.ftl", Tool.createFile(templates.getAbsolutePath(), "404.ftl")); + Tool.outputResource("SpringBoot/resources/templates/500.ftl", Tool.createFile(templates.getAbsolutePath(), "500.ftl")); { HashMap ctx = new HashMap(); @@ -794,7 +792,7 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); ctx.put("modules", project.getModules()); ctx.put("sysMD", project.getSysMD()); - freeMarkerManager.outputTemp(Tool.createFile(screen.getAbsolutePath(), "index.ftl"), option + "/resources/templates/screen/index.ftl", ctx); + freeMarkerManager.outputTemp(Tool.createFile(screen.getAbsolutePath(), "index.ftl"), "SpringBoot/resources/templates/screen/index.ftl", ctx); } @@ -812,7 +810,7 @@ public class SpringBootCallable implements Callable { ctx.put("module", module.getName()); ctx.put("fields", table.getFields()); File file = Tool.createFile(module.getAbsolutePath(), table.getFName() + ".ftl"); - freeMarkerManager.outputTemp(file, option + "/resources/templates/screen/module/mgr.ftl", ctx); + freeMarkerManager.outputTemp(file, "SpringBoot/resources/templates/screen/module/mgr.ftl", ctx); } } } @@ -821,13 +819,13 @@ public class SpringBootCallable implements Callable { if (project.getSysMD()) {//生成系统模块 File system = Tool.createPath(screen.getAbsolutePath(), "system"); for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/resources/templates/screen/module/system/")) { - Tool.outputResource(option + "/resources/templates/screen/module/system/" + name, Tool.createFile(system.getAbsolutePath(), name)); + Tool.outputResource("SpringBoot/resources/templates/screen/module/system/" + name, Tool.createFile(system.getAbsolutePath(), name)); } } } } - public void generateTest(File root, Project project, DataBase dataBase, String option) { + public void generateTest(File root, Project project, DataBase dataBase) { { File config = Tool.createPath(root.getAbsolutePath(), "config"); @@ -839,7 +837,7 @@ public class SpringBootCallable implements Callable { ctx.put("author", project.getProjectAuthor()); ctx.put("date", new Date()); File file = Tool.createFile(config.getAbsolutePath(), "TestConfig" + ".java"); - freeMarkerManager.outputTemp(file, option + "/test/TestConfig.ftl", ctx); + freeMarkerManager.outputTemp(file, "SpringBoot/test/TestConfig.ftl", ctx); } { @@ -850,7 +848,7 @@ public class SpringBootCallable implements Callable { ctx.put("author", project.getProjectAuthor()); ctx.put("date", new Date()); File file = Tool.createFile(root.getAbsolutePath(), "UtilTest" + ".java"); - freeMarkerManager.outputTemp(file, option + "/test/UtilTest.java", ctx); + freeMarkerManager.outputTemp(file, "SpringBoot/test/UtilTest.java", ctx); } for (Module md : project.getModules()) { @@ -868,7 +866,7 @@ public class SpringBootCallable implements Callable { ctx.put("date", new Date()); File file = Tool.createFile(module.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Test" + ".java"); - freeMarkerManager.outputTemp(file, option + "/test/test.ftl", ctx); + freeMarkerManager.outputTemp(file, "SpringBoot/test/test.ftl", ctx); } } @@ -882,7 +880,7 @@ public class SpringBootCallable implements Callable { File system = Tool.createPath(root.getAbsolutePath(), "system"); for (String apiFile : ResourceUtil.getResourceFiles("/modules/SpringBoot/test/system/")) { - freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), apiFile), option + "/test/system/" + apiFile, ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), apiFile), "SpringBoot/test/system/" + apiFile, ctx); } } @@ -896,7 +894,7 @@ public class SpringBootCallable implements Callable { File system = Tool.createPath(root.getAbsolutePath(), "datainit"); for (String apiFile : ResourceUtil.getResourceFiles("/modules/SpringBoot/test/datainit/")) { - freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), apiFile), option + "/test/datainit/" + apiFile, ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), apiFile), "SpringBoot/test/datainit/" + apiFile, ctx); } } } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/AbstractDBmapper.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/AbstractDBmapper.java index 71971ba0..0af50719 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/AbstractDBmapper.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/AbstractDBmapper.java @@ -4,23 +4,12 @@ import xyz.wbsite.dbtool.javafx.enums.DataBase; import xyz.wbsite.dbtool.javafx.enums.FieldType; public abstract class AbstractDBmapper { - DataBase mDataBase = null; - private AbstractDBmapper() { - - } - - public AbstractDBmapper(DataBase mDataBase) { - this.mDataBase = mDataBase; - } - - DataBase getDataBase() { - return mDataBase; - } + public abstract DataBase getDataBase(); public abstract String getDataBaseType(FieldType type); abstract String getFieldSql(Field field); - public abstract FieldType getType(String type, int lenght, int precision, int scale); + public abstract FieldType getType(String type, int length, int precision, int scale); } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/MySQLDBmapper.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/MySQLDBmapper.java index cc67bbbd..53096d10 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/MySQLDBmapper.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/MySQLDBmapper.java @@ -5,10 +5,6 @@ import xyz.wbsite.dbtool.javafx.enums.FieldType; public class MySQLDBmapper extends AbstractDBmapper { - public MySQLDBmapper(DataBase mDataBase) { - super(mDataBase); - } - @Override public String getFieldSql(Field field) { StringBuffer sb = new StringBuffer(""); @@ -95,8 +91,8 @@ public class MySQLDBmapper extends AbstractDBmapper { } @Override - DataBase getDataBase() { - return super.getDataBase(); + public DataBase getDataBase() { + return DataBase.MySQL; } @Override diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/OracleDBmapper.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/OracleDBmapper.java index 2edf277a..cbd13f13 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/OracleDBmapper.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/OracleDBmapper.java @@ -68,11 +68,10 @@ public class OracleDBmapper extends AbstractDBmapper { } return sb.toString(); } - - public OracleDBmapper(DataBase mDataBase) { - super(mDataBase); + @Override + public DataBase getDataBase() { + return DataBase.Oracle; } - @Override public String getDataBaseType(FieldType type) { if (FieldType.Boolean.name().equals(type.name())) { 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 958fd49c..ea95ffc9 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/SQLiteDBmapper.java @@ -5,10 +5,6 @@ import xyz.wbsite.dbtool.javafx.enums.FieldType; public class SQLiteDBmapper extends AbstractDBmapper { - public SQLiteDBmapper(DataBase mDataBase) { - super(mDataBase); - } - @Override public String getFieldSql(Field field) { StringBuffer sb = new StringBuffer(""); @@ -81,8 +77,8 @@ public class SQLiteDBmapper extends AbstractDBmapper { } @Override - DataBase getDataBase() { - return super.getDataBase(); + public DataBase getDataBase() { + return DataBase.SQLite; } @Override diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java index 933543e4..d931f6ee 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java @@ -200,46 +200,6 @@ public class Dialog { } } - public static void showGenerateOption(GenerateOptionListener listener) { - FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/generateOption.fxml")); - try { - dbdetailloader.load(); - } catch (IOException e) { - return; - } - Parent root = dbdetailloader.getRoot(); - OptionMainController controller = dbdetailloader.getController(); - controller.setListener(listener); - controller.getCancel().setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - stopPopup(); - } - }); - controller.getOk().setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - listener.onGenerate(controller.getType(), DataBase.valueOf(controller.getDataBase())); - } - }); - - popup = new Stage(); - popup.setAlwaysOnTop(true); - popup.initModality(Modality.APPLICATION_MODAL); - - Scene scene = new Scene(root); - - popup.setOnCloseRequest(new EventHandler() { - @Override - public void handle(WindowEvent event) { - stopPopup(); - } - }); - popup.setScene(scene); - popup.setTitle("配置"); - popup.show(); - } - public static void showDBConnectInput() { Stage stage = new Stage(); stage.setAlwaysOnTop(true); diff --git a/src/main/java/xyz/wbsite/dbtool/web/frame/utils/FileUtil.java b/src/main/java/xyz/wbsite/dbtool/web/frame/utils/FileUtil.java index 8ed339c9..09ec84e0 100644 --- a/src/main/java/xyz/wbsite/dbtool/web/frame/utils/FileUtil.java +++ b/src/main/java/xyz/wbsite/dbtool/web/frame/utils/FileUtil.java @@ -1,13 +1,18 @@ package xyz.wbsite.dbtool.web.frame.utils; - +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; public class FileUtil { @@ -45,6 +50,58 @@ public class FileUtil { return var5; } + public static List readFileToLines(File file) { + List stringLines = new ArrayList(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + String line = null; + while ((line = reader.readLine()) != null) { + stringLines.add(line); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + reader.close(); + } catch (Exception ignored) { + + } + } + return stringLines; + } + + public static boolean writeStringToFile(String data, File file, boolean isNewLine, boolean isAppend) { + PrintWriter printWriter = null; + try { + printWriter = openPrintWriter(file); + if (isNewLine && isAppend) {// 换行追加 + printWriter.println(); + printWriter.append(data); + } else if (!isNewLine && isAppend) {// 不换行追加 + printWriter.append(data); + } else {// 直接写入 + printWriter.print(data); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (printWriter != null) printWriter.close(); + } + } + + public static PrintWriter openPrintWriter(File file) { + try { + return new PrintWriter(new FileOutputStream(file)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + public static FileInputStream openInputStream(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { @@ -123,6 +180,18 @@ public class FileUtil { return count > 2147483647L ? -1 : (int) count; } + public static boolean copy(File in, File out) throws Exception { + try { + FileInputStream input = new FileInputStream(in); + FileOutputStream output = new FileOutputStream(out); + copy(input, output); + input.close(); + output.close(); + return true; + } catch (IOException ie) { + return false; + } + } public static long copyLarge(InputStream input, OutputStream output) throws IOException { return copy(input, output, 4096); @@ -141,4 +210,58 @@ public class FileUtil { return count; } + + public static boolean clearDirectory(File dir) { + if ((dir == null) || !dir.isDirectory()) { + throw new IllegalArgumentException("Argument " + dir + + " is not a directory. "); + } + + File[] entries = dir.listFiles(); + int sz = entries.length; + + for (int i = 0; i < sz; i++) { + if (entries[i].isDirectory()) { + if (!clearDirectory(entries[i])) { + return false; + } + } else { + if (!entries[i].delete()) { + return false; + } + } + } + + if (!dir.delete()) { + return false; + } + return true; + } + + /** + * 将DOS/Windows格式的路径转换为UNIX/Linux格式的路径。 + * 其实就是将路径中的"\"全部换为"/",因为在某些情况下我们转换为这种方式比较方便, + * 某中程度上说"/"比"\"更适合作为路径分隔符,而且DOS/Windows也将它当作路径分隔符。 + */ + public static String toUNIXpath(String filePath) { + return filePath.replace('\\', '/'); + } + + public static void inputStream2File(InputStream is, File target) { + try { + if (!target.exists() && !target.createNewFile()) { + throw new RuntimeException(target.getName() + "not exists"); + } + OutputStream outStream = new FileOutputStream(target); + byte[] buffer = new byte[8 * 1024]; + int bytesRead; + while ((bytesRead = is.read(buffer)) != -1) { + outStream.write(buffer, 0, bytesRead); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/resources/fxml/generateOption.fxml b/src/main/resources/fxml/generateOption.fxml deleted file mode 100644 index 32f918df..00000000 --- a/src/main/resources/fxml/generateOption.fxml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -