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 221fa8ed..16f0a7ef 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java @@ -10,13 +10,13 @@ import javafx.scene.control.TableView; import javafx.scene.control.TreeView; import javafx.scene.layout.Pane; import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; import javafx.stage.Stage; import xyz.wbsite.dbtool.javafx.JavaFxApplication; import xyz.wbsite.dbtool.javafx.enumeration.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.po.Project; import xyz.wbsite.dbtool.javafx.tool.Dialog; import java.io.File; @@ -104,62 +104,66 @@ public class MainController { } @FXML - public void showFileChooser(ActionEvent actionEvent) { - DirectoryChooser directoryChooser = new DirectoryChooser(); + public void modelOpen(ActionEvent actionEvent) { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("选择模型文件"); + fileChooser.setInitialDirectory(dBmanger.getPath()); + + fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("模型文件", "*.xml", "*.XML")); + Stage stage = new Stage(); - File file = directoryChooser.showDialog(stage); + File file = fileChooser.showOpenDialog(stage); if (file != null && file.exists()) { - dBmanger.setPath(file.getAbsolutePath()); - dBmanger.invalidate(); - main.loadingProjectTree(); - - System.out.println(file.getAbsolutePath()); + dBmanger.invalidate(file);//初始化模型树 - 到内容 + main.loadingProjectTree();//加载模型树 - 到组件 + main.loadingProject(); } } - public boolean doSave(ActionEvent actionEvent) { + @FXML + public void modelSave(ActionEvent actionEvent) { if (dBmanger.getPath() == null || "".equals(dBmanger.getPath())) { DirectoryChooser directoryChooser = new DirectoryChooser(); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); if (file == null) { - - return false; + System.err.println("请选择目录!"); + } else { + dBmanger.setPath(file); + System.out.println(file.getAbsolutePath()); } - dBmanger.setPath(file.getAbsolutePath()); - System.out.println(file.getAbsolutePath()); } dBmanger.save(); - System.out.println("自动保存成功"); - return true; } @FXML - public void save(ActionEvent actionEvent) { - doSave(actionEvent); - } - - @FXML - public void saveAs(ActionEvent actionEvent) { + public void modelSaveAs(ActionEvent actionEvent) { DirectoryChooser directoryChooser = new DirectoryChooser(); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); if (file != null) { - dBmanger.setPath(file.getAbsolutePath()); - dBmanger.save(); + dBmanger.save(file); } } @FXML - public void clear(ActionEvent actionEvent) { - Dialog.showConfirmDialog("确认清空所有信息?", new EventHandler() { + public void modelCreate(ActionEvent actionEvent) { + dBmanger.modelCreate(); + main.loadingProjectTree(); + main.loadingProject(); + } + + @FXML + public void modelDelete(ActionEvent actionEvent) { + Dialog.showConfirmDialog("确认删除当前模型?", new EventHandler() { @Override public void handle(Event event) { - dBmanger.clear(); + dBmanger.delete(); + dBmanger.invalidate(); main.loadingProjectTree(); main.loadingProject(); } @@ -167,18 +171,16 @@ public class MainController { } @FXML - public void showConnectInfo(ActionEvent actionEvent) { + public void modelImport(ActionEvent actionEvent) { Dialog.showDBConnectInput(); } @FXML - public void generate(ActionEvent actionEvent) { - if (!this.doSave(null)) { - return; - } + public void modelGenerate(ActionEvent actionEvent) { + this.modelSave(null); if (dBmanger.doCheck()) { DirectoryChooser directoryChooser = new DirectoryChooser(); - directoryChooser.setInitialDirectory(new File(dBmanger.getPath())); + directoryChooser.setInitialDirectory(dBmanger.getPath()); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); @@ -204,6 +206,7 @@ public class MainController { public void generateApi(ActionEvent actionEvent) { Dialog.showApi(); } + @FXML public void generateAndroid(ActionEvent actionEvent) { Dialog.showAndroid(); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/SdkInfoController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/SdkInfoController.java index 7b7a535c..df3636be 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/SdkInfoController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/SdkInfoController.java @@ -201,7 +201,7 @@ public class SdkInfoController { if (moduleFile.exists()) { data.clear(); - File reqs = new File(moduleFile.getAbsolutePath() + File.separator + "req"); + File reqs = new File(moduleFile,"req"); if (!reqs.exists()) { return; 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 4e8835ee..fc143761 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java @@ -8,6 +8,7 @@ import xyz.wbsite.dbtool.javafx.po.*; import xyz.wbsite.dbtool.javafx.tool.Dialog; import java.io.File; +import java.io.FilenameFilter; import java.sql.*; import java.util.List; import java.util.Map; @@ -18,7 +19,7 @@ public class ProjectManager { public static boolean isUpdate = false; private XmlManager xmlService; public static AbstractDBmapper dBmapper; - public static String path; + public static File path; private Project project = new Project(); public ProjectManager() { @@ -26,15 +27,23 @@ public class ProjectManager { try { ApplicationHome home = new ApplicationHome(getClass()); File jarFile = home.getSource(); - this.path = jarFile.getParent() + File.separator + "project"; + this.path = new File(jarFile.getParent(), "project"); } catch (Exception e) { e.printStackTrace(); - this.path = System.getProperty("user.home") + File.separator + "project"; + this.path = new File(System.getProperty("user.home"), "project"); } invalidate(); } - public void clear() { + public static File getPath() { + return path; + } + + public static void setPath(File path) { + ProjectManager.path = path; + } + + public void modelCreate() { project = new Project(); } @@ -163,17 +172,6 @@ public class ProjectManager { return project; } - public String getPath() { - return path; - } - - public void setPath(String path) { - if (path != null && !path.equals(this.path)) { - this.path = path; - invalidate(); - } - } - public boolean doCheck() { if (project.getProjectName() == null || "".equals(project.getProjectName())) { Dialog.showConfirmDialog("没有填写项目名!"); @@ -200,31 +198,18 @@ public class ProjectManager { /** * 保存配置文件 */ - public void save() { - if (path != null) { - File file = new File(path); - if (!file.exists()) { - file.mkdirs(); - } - xmlService.save(path, project); - } + public void save(File file) { + xmlService.saveAs(file, project); } - private void clear(File f) { - if (f.isDirectory()) { - File[] files = f.listFiles(); - for (File file : files) { - if (file.isDirectory()) { - clear(file); - boolean delete = file.delete(); - - System.out.println("删除" + file.getName() + (delete ? "成功" : "失败")); - } else { - boolean delete = file.delete(); + public void save() { + xmlService.saveAs(path, project); + } - System.out.println("删除" + file.getName() + (delete ? "成功" : "失败")); - } - } + public void delete() { + File file = new File(path, project.getProjectName() + ".xml"); + if (file.exists()) { + file.delete(); } } @@ -290,10 +275,10 @@ public class ProjectManager { @Override public void run() { boolean mkdirs = sdk.mkdirs(); - File reqList = new File(module.getAbsolutePath() + File.separator + "req"); - File rspList = new File(module.getAbsolutePath() + File.separator + "rsp"); - File entList = new File(module.getAbsolutePath() + File.separator + "ent"); - File enumsList = new File(module.getAbsolutePath() + File.separator + "enums"); + File reqList = new File(module,"req"); + File rspList = new File(module,"rsp"); + File entList = new File(module, "ent"); + File enumsList = new File(module, "enums"); SDKCallable sdkCallable = new SDKCallable(sdk, reqList, rspList, entList, enumsList, apis); Future submit = service.submit(sdkCallable); try { @@ -362,8 +347,28 @@ public class ProjectManager { }.start(); } + /** + * 初始化模型树,当存在多个时,默认第一个 + */ public void invalidate() { - project = xmlService.inflate(path); + File[] files = path.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".xml") || name.endsWith(".XML"); + } + }); + + if (files.length == 0) { + project = xmlService.inflate(null); + } else { + project = xmlService.inflate(files[0]); + } + } + + /** + * 初始化模型树,当存在多个时,默认第一个 + */ + public void invalidate(File xmlFile) { + project = xmlService.inflate(xmlFile); } public static boolean testConnect(Map properties) { 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 a0ed316d..be22f9fe 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/XmlManager.java @@ -17,141 +17,128 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; public class XmlManager { - public Project inflate(String path) { + public Project inflate(File xmlFile) { Project project = new Project(); - if (path == null || "".equals(path)) { + if (xmlFile == null) { return project; - } - File file = new File(path); - if (!file.exists()) { - System.err.println("目录不存在!"); + } else if (!xmlFile.exists()) { + System.err.println("文件不存在!"); } else { - File dbFile = new File(path); - - if (!dbFile.exists()) { - dbFile.mkdir(); - } else { - File[] files = dbFile.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".xml") || name.endsWith(".XML"); - } - }); - - //开始解析 - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - for (File xml : files) { - FileInputStream inputStream = null; - try { - inputStream = new FileInputStream(xml); - Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream); + //开始解析 + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + FileInputStream inputStream = null; + try { + inputStream = new FileInputStream(xmlFile); + Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream); - Element dbElement = document.getDocumentElement(); + Element dbElement = document.getDocumentElement(); - if ("project".endsWith(dbElement.getNodeName())) { - System.out.println("发现项目:" + xml.getName()); + if ("project".endsWith(dbElement.getNodeName())) { + System.out.println("加载模型[" + xmlFile.getName() + "]"); - NodeList projectName = dbElement.getElementsByTagName("projectName"); - if (projectName.getLength() == 1) { - project.setProjectName(projectName.item(0).getTextContent()); - } + NodeList projectName = dbElement.getElementsByTagName("projectName"); + if (projectName.getLength() == 1) { + project.setProjectName(projectName.item(0).getTextContent()); + } - NodeList projectBasePackage = dbElement.getElementsByTagName("projectBasePackage"); - if (projectBasePackage.getLength() == 1) { - project.setProjectBasePackage(projectBasePackage.item(0).getTextContent()); - } + NodeList projectBasePackage = dbElement.getElementsByTagName("projectBasePackage"); + if (projectBasePackage.getLength() == 1) { + project.setProjectBasePackage(projectBasePackage.item(0).getTextContent()); + } - NodeList projectAuthor = dbElement.getElementsByTagName("projectAuthor"); - if (projectAuthor.getLength() == 1) { - project.setProjectAuthor(projectAuthor.item(0).getTextContent()); - } + NodeList projectAuthor = dbElement.getElementsByTagName("projectAuthor"); + if (projectAuthor.getLength() == 1) { + project.setProjectAuthor(projectAuthor.item(0).getTextContent()); + } - NodeList modules = dbElement.getElementsByTagName("module"); - if (modules.getLength() > 0) { + NodeList modules = dbElement.getElementsByTagName("module"); + if (modules.getLength() > 0) { - for (int i = 0; i < modules.getLength(); i++) { - Module module = new Module(); - Element moduleElement = (Element) modules.item(i); + for (int i = 0; i < modules.getLength(); i++) { + Module module = new Module(); + Element moduleElement = (Element) modules.item(i); - NodeList moduleName = moduleElement.getElementsByTagName("moduleName"); - if (moduleName.getLength() == 1) { - module.setModuleName(moduleName.item(0).getTextContent()); - } + NodeList moduleName = moduleElement.getElementsByTagName("moduleName"); + if (moduleName.getLength() == 1) { + module.setModuleName(moduleName.item(0).getTextContent()); + } - NodeList moduleComment = moduleElement.getElementsByTagName("moduleComment"); - if (moduleComment.getLength() == 1) { - module.setModuleComment(moduleComment.item(0).getTextContent()); - } + NodeList moduleComment = moduleElement.getElementsByTagName("moduleComment"); + if (moduleComment.getLength() == 1) { + module.setModuleComment(moduleComment.item(0).getTextContent()); + } - NodeList modulePrefix = moduleElement.getElementsByTagName("modulePrefix"); - if (modulePrefix.getLength() == 1) { - module.setModulePrefix(modulePrefix.item(0).getTextContent()); - } + NodeList modulePrefix = moduleElement.getElementsByTagName("modulePrefix"); + if (modulePrefix.getLength() == 1) { + module.setModulePrefix(modulePrefix.item(0).getTextContent()); + } - NodeList hasSysFields = moduleElement.getElementsByTagName("hasSysFields"); - if (hasSysFields.getLength() == 1) { - module.setHasSysFields(Boolean.parseBoolean(hasSysFields.item(0).getTextContent())); - } + NodeList hasSysFields = moduleElement.getElementsByTagName("hasSysFields"); + if (hasSysFields.getLength() == 1) { + module.setHasSysFields(Boolean.parseBoolean(hasSysFields.item(0).getTextContent())); + } - NodeList tables = moduleElement.getElementsByTagName("table"); - if (tables.getLength() > 0) { - for (int j = 0; j < tables.getLength(); j++) { - Element tableElement = (Element) tables.item(j); - Table table = new Table(); - table.setdBhandle(module); - table.setTableName(tableElement.getAttribute("tableName")); - table.setTableComment(tableElement.getAttribute("tableComment")); - table.setCreate(Boolean.parseBoolean(tableElement.getAttribute("create"))); - table.setDelete(Boolean.parseBoolean(tableElement.getAttribute("delete"))); - table.setUpdate(Boolean.parseBoolean(tableElement.getAttribute("update"))); - table.setFind(Boolean.parseBoolean(tableElement.getAttribute("find"))); - table.setGet(Boolean.parseBoolean(tableElement.getAttribute("get"))); - table.setSearch(Boolean.parseBoolean(tableElement.getAttribute("search"))); - table.setGetAll(Boolean.parseBoolean(tableElement.getAttribute("getAll"))); - - NodeList fields = tableElement.getElementsByTagName("field"); - - if (fields.getLength() > 0) { - for (int k = 0; k < fields.getLength(); k++) { - Element fieldElement = (Element) fields.item(k); - Field field = new Field(); - field.setFieldName(fieldElement.getAttribute("fieldName")); - field.setFieldType(FieldType.parse(fieldElement.getAttribute("fieldType"))); - field.setFieldLength(Integer.parseInt(fieldElement.getAttribute("fieldLength"))); - field.setFieldComment(fieldElement.getAttribute("fieldComment")); - field.setDefaultValue(fieldElement.getAttribute("defaultValue")); - field.setIsSystem(Boolean.parseBoolean(fieldElement.getAttribute("IsSystem"))); - field.setIsMust(Boolean.parseBoolean(fieldElement.getAttribute("isMust"))); - field.setIsPrimaryKey(Boolean.parseBoolean(fieldElement.getAttribute("isPrimaryKey"))); - field.setIsQuery(Boolean.parseBoolean(fieldElement.getAttribute("isQuery"))); - field.setIsSearch(Boolean.parseBoolean(fieldElement.getAttribute("isSearch"))); - table.putField(field); - } - } - module.putTable(table); + NodeList tables = moduleElement.getElementsByTagName("table"); + if (tables.getLength() > 0) { + for (int j = 0; j < tables.getLength(); j++) { + Element tableElement = (Element) tables.item(j); + Table table = new Table(); + table.setdBhandle(module); + table.setTableName(tableElement.getAttribute("tableName")); + table.setTableComment(tableElement.getAttribute("tableComment")); + table.setCreate(Boolean.parseBoolean(tableElement.getAttribute("create"))); + table.setDelete(Boolean.parseBoolean(tableElement.getAttribute("delete"))); + table.setUpdate(Boolean.parseBoolean(tableElement.getAttribute("update"))); + table.setFind(Boolean.parseBoolean(tableElement.getAttribute("find"))); + table.setGet(Boolean.parseBoolean(tableElement.getAttribute("get"))); + table.setSearch(Boolean.parseBoolean(tableElement.getAttribute("search"))); + table.setGetAll(Boolean.parseBoolean(tableElement.getAttribute("getAll"))); + + NodeList fields = tableElement.getElementsByTagName("field"); + + if (fields.getLength() > 0) { + for (int k = 0; k < fields.getLength(); k++) { + Element fieldElement = (Element) fields.item(k); + Field field = new Field(); + field.setFieldName(fieldElement.getAttribute("fieldName")); + field.setFieldType(FieldType.parse(fieldElement.getAttribute("fieldType"))); + field.setFieldLength(Integer.parseInt(fieldElement.getAttribute("fieldLength"))); + field.setFieldComment(fieldElement.getAttribute("fieldComment")); + field.setDefaultValue(fieldElement.getAttribute("defaultValue")); + field.setIsSystem(Boolean.parseBoolean(fieldElement.getAttribute("IsSystem"))); + field.setIsMust(Boolean.parseBoolean(fieldElement.getAttribute("isMust"))); + field.setIsPrimaryKey(Boolean.parseBoolean(fieldElement.getAttribute("isPrimaryKey"))); + field.setIsQuery(Boolean.parseBoolean(fieldElement.getAttribute("isQuery"))); + field.setIsSearch(Boolean.parseBoolean(fieldElement.getAttribute("isSearch"))); + table.putField(field); } } - project.putModule(module); + module.putTable(table); } } - System.out.println("数据初始化成功..."); - return project; + project.putModule(module); } - } catch (Exception e) { - System.out.println("文件:'" + xml.getName() + "'解析失败!请检查语法是否正确!"); + } + System.out.println("模型初始化成功..."); + return project; + } + } catch (Exception e) { + System.out.println("文件:'" + xmlFile.getName() + "'解析失败!请检查语法是否正确!"); + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { e.printStackTrace(); - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } } } @@ -159,7 +146,7 @@ public class XmlManager { return project; } - public boolean saveAs(String path, Project project) { + public boolean saveAs(File path, Project project) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; //生成DOM模型 @@ -257,16 +244,16 @@ public class XmlManager { t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.METHOD, "xml"); - File dbFile = new File(path); - if (!dbFile.exists()) { - dbFile.mkdirs(); + if (!path.exists()) { + path.mkdirs(); } - File file = new File(dbFile.getAbsolutePath() + File.separator + project.getProjectName() + ".xml"); + File file = new File(path, project.getProjectName() + ".xml"); if (!file.exists()) { file.createNewFile(); } stream = new FileOutputStream(file); t.transform(new DOMSource(doc), new StreamResult(stream)); + System.out.println("[" + file.getName() + "]保存成功!"); } catch (Exception e) { e.printStackTrace(); return false; @@ -286,10 +273,4 @@ public class XmlManager { } return true; } - - public boolean save(String path, Project project) { - File projectFile = new File(path); - saveAs(projectFile.getAbsolutePath(), project); - return true; - } } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java index d881eab6..bd2a6bc8 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java @@ -53,7 +53,7 @@ public class SDKCallable implements Callable { System.out.println("生成模块:Pom"); HashMap ctx = new HashMap(); ctx.put("sdk", sdk.getName().toLowerCase()); - File file = new File(sdk.getAbsolutePath() + File.separator + "pom.xml"); + File file = new File(sdk, "pom.xml"); freeMarkerManager.outputTemp(file, "Java_api/pom.ftl", ctx); } @@ -103,7 +103,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaClassReader.getModuleName()); - File request = new File(stringBuffer.toString() + File.separator + "request"); + File request = new File(stringBuffer.toString(), "request"); request.mkdirs(); { @@ -118,7 +118,7 @@ public class SDKCallable implements Callable { ctx.put("tool", tool); ctx.put("hasList", javaClassReader.isHasList()); ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag()); - File file = new File(request.getAbsolutePath() + File.separator + api.getReq().getName()); + File file = new File(request.getAbsolutePath(), api.getReq().getName()); freeMarkerManager.outputTemp(file, "Java_api/module/request/request.ftl", ctx); System.out.println("生成文件" + file.getName() + "成功"); @@ -148,7 +148,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaClassReader.getModuleName()); - File response = new File(stringBuffer.toString() + File.separator + "response"); + File response = new File(stringBuffer.toString(), "response"); response.mkdirs(); { @@ -163,7 +163,7 @@ public class SDKCallable implements Callable { ctx.put("tool", tool); ctx.put("hasList", javaClassReader.isHasList()); ctx.put("Tclass", javaClassReader.getTclass()); - File file = new File(response.getAbsolutePath() + File.separator + api.getRsp().getName().replaceAll("Request", "Response")); + File file = new File(response.getAbsolutePath(), api.getRsp().getName().replaceAll("Request", "Response")); freeMarkerManager.outputTemp(file, "Java_api/module/response/response.ftl", ctx); System.out.println("生成文件" + api.getRsp().getName() + "成功"); @@ -175,7 +175,7 @@ public class SDKCallable implements Callable { for (String s : api.getDepReq()) { try { - File f = new File(req.getAbsolutePath() + File.separator + s + ".java"); + File f = new File(req.getAbsolutePath(), s + ".java"); if (!f.exists()) { System.err.println("文件" + f.getAbsolutePath() + "不存在"); continue; @@ -213,7 +213,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaClassReader.getModuleName()); - File request = new File(stringBuffer.toString() + File.separator + "request"); + File request = new File(stringBuffer.toString(), "request"); request.mkdirs(); { @@ -228,7 +228,7 @@ public class SDKCallable implements Callable { ctx.put("tool", tool); ctx.put("hasList", javaClassReader.isHasList()); ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag()); - File file = new File(request.getAbsolutePath() + File.separator + f.getName()); + File file = new File(request.getAbsolutePath(), f.getName()); freeMarkerManager.outputTemp(file, "Java_api/module/request/request.ftl", ctx); System.out.println("生成文件" + file.getName() + "成功"); @@ -239,8 +239,8 @@ public class SDKCallable implements Callable { } try { - File f = new File(rsp.getAbsolutePath() + File.separator + s.replaceAll("Request", "Response.java")); - if (!f.exists()){ + File f = new File(rsp.getAbsolutePath(), s.replaceAll("Request", "Response.java")); + if (!f.exists()) { System.err.println("文件" + f.getAbsolutePath() + "不存在"); } JavaClassReader javaClassReader = new JavaClassReader(f); @@ -260,7 +260,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaClassReader.getModuleName()); - File response = new File(stringBuffer.toString() + File.separator + "response"); + File response = new File(stringBuffer.toString(), "response"); response.mkdirs(); { @@ -275,7 +275,7 @@ public class SDKCallable implements Callable { ctx.put("tool", tool); ctx.put("hasList", javaClassReader.isHasList()); ctx.put("Tclass", javaClassReader.getTclass()); - File file = new File(response.getAbsolutePath() + File.separator + f.getName()); + File file = new File(response.getAbsolutePath(), f.getName()); freeMarkerManager.outputTemp(file, "Java_api/module/response/response.ftl", ctx); System.out.println("生成文件" + api.getRsp().getName() + "成功"); @@ -289,7 +289,7 @@ public class SDKCallable implements Callable { for (String s : api.getDepEnt()) { try { - File f = new File(ent.getAbsolutePath() + File.separator + s + ".java"); + File f = new File(ent.getAbsolutePath(), s + ".java"); if (!f.exists()) { System.out.println("文件" + f.getAbsolutePath() + "不存在"); continue; @@ -311,7 +311,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaClassReader.getModuleName()); - File entity = new File(stringBuffer.toString() + File.separator + "entity"); + File entity = new File(stringBuffer.toString(), "entity"); entity.mkdirs(); { @@ -324,7 +324,7 @@ public class SDKCallable implements Callable { ctx.put("className", javaClassReader.getClassName().replaceAll("Entity", "")); ctx.put("body", javaClassReader.getBody()); ctx.put("tool", tool); - File file = new File(entity.getAbsolutePath() + File.separator + f.getName()); + File file = new File(entity.getAbsolutePath(), f.getName()); freeMarkerManager.outputTemp(file, "Java_api/module/entity/entity.ftl", ctx); System.out.println("生成文件" + file.getName() + "成功"); } @@ -336,7 +336,7 @@ public class SDKCallable implements Callable { for (String s : api.getDepEnum()) { try { - File f = new File(enums.getAbsolutePath() + File.separator + s + ".java"); + File f = new File(enums, s + ".java"); if (!f.exists()) { System.err.println("文件" + f.getAbsolutePath() + "不存在"); continue; @@ -358,7 +358,7 @@ public class SDKCallable implements Callable { stringBuffer.append(javaEnumReader.getModuleName()); - File enums_ = new File(stringBuffer.toString() + File.separator + "enums"); + File enums_ = new File(stringBuffer.toString(), "enums"); enums_.mkdirs(); { @@ -371,7 +371,7 @@ public class SDKCallable implements Callable { ctx.put("body", javaEnumReader.getBody()); ctx.put("tool", tool); - File file = new File(enums_.getAbsolutePath() + File.separator + f.getName()); + File file = new File(enums_, f.getName()); freeMarkerManager.outputTemp(file, "Java_api/module/enums/type.ftl", ctx); System.out.println("生成文件" + file.getName() + "成功"); } @@ -607,90 +607,90 @@ public class SDKCallable implements Callable { ctx.put("domain", domain); ctx.put("module", module); { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiEntity.java"); + File file = new File(frameWork, "ApiEntity.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiEntity.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "AESUtil.java"); + File file = new File(frameWork, "AESUtil.java"); freeMarkerManager.outputTemp(file, "/Java_api/AESUtil.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiClient.java"); + File file = new File(frameWork, "ApiClient.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiRequest.java"); + File file = new File(frameWork, "ApiRequest.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiRequest.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiFindRequest.java"); + File file = new File(frameWork, "ApiFindRequest.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiFindRequest.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiSearchRequest.java"); + File file = new File(frameWork, "ApiSearchRequest.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiSearchRequest.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiResponse.java"); + File file = new File(frameWork, "ApiResponse.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiResponse.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ApiFindResponse.java"); + File file = new File(frameWork, "ApiFindResponse.java"); freeMarkerManager.outputTemp(file, "/Java_api/ApiFindResponse.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "Base64Util.java"); + File file = new File(frameWork, "Base64Util.java"); freeMarkerManager.outputTemp(file, "/Java_api/Base64Util.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "DownloadUtil.java"); + File file = new File(frameWork, "DownloadUtil.java"); freeMarkerManager.outputTemp(file, "/Java_api/DownloadUtil.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "Error.java"); + File file = new File(frameWork, "Error.java"); freeMarkerManager.outputTemp(file, "/Java_api/Error.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ErrorType.java"); + File file = new File(frameWork, "ErrorType.java"); freeMarkerManager.outputTemp(file, "/Java_api/ErrorType.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "FileUploadRequest.java"); + File file = new File(frameWork, "FileUploadRequest.java"); freeMarkerManager.outputTemp(file, "/Java_api/FileUploadRequest.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "FileUploadResponse.java"); + File file = new File(frameWork, "FileUploadResponse.java"); freeMarkerManager.outputTemp(file, "/Java_api/FileUploadResponse.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "MapperUtil.java"); + File file = new File(frameWork, "MapperUtil.java"); freeMarkerManager.outputTemp(file, "/Java_api/MapperUtil.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "MD5Util.java"); + File file = new File(frameWork, "MD5Util.java"); freeMarkerManager.outputTemp(file, "/Java_api/MD5Util.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "RSAUtil.java"); + File file = new File(frameWork, "RSAUtil.java"); freeMarkerManager.outputTemp(file, "/Java_api/RSAUtil.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "ProgressRequestBody.java"); + File file = new File(frameWork, "ProgressRequestBody.java"); freeMarkerManager.outputTemp(file, "/Java_api/ProgressRequestBody.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "SortType.java"); + File file = new File(frameWork, "SortType.java"); freeMarkerManager.outputTemp(file, "/Java_api/SortType.ftl", ctx); } { - File file = new File(frameWork.getAbsolutePath() + File.separator + "StringUtils.java"); + File file = new File(frameWork, "StringUtils.java"); freeMarkerManager.outputTemp(file, "/Java_api/StringUtils.ftl", ctx); } //4.0.1 去掉验证 减少体积 // { -// File file = new File(frameWork.getAbsolutePath() + File.separator + "ValidationUtil.java"); +// File file = new File(frameWork , "ValidationUtil.java"); // freeMarkerManager.outputTemp(file, "/Java_api/ValidationUtil.ftl", ctx); // } System.out.println("finish"); 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 1346e286..60b54cec 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 @@ -40,7 +40,7 @@ public class SpringBootCallable implements Callable { dBmapper = ProjectManager.dBmapper; // 创建项目文件夹 - File projectDir = new File(root + File.separator + project.getProjectName()); + File projectDir = new File(root , project.getProjectName()); if (!projectDir.exists()) { projectDir.mkdir(); } else { @@ -588,7 +588,7 @@ public class SpringBootCallable implements Callable { dbtool.mkdirs(); { XmlManager xmlManager = ManagerFactory.getXmlManager(); - xmlManager.saveAs(dbtool.getAbsolutePath(), project); + xmlManager.saveAs(dbtool, project); } for (Module module : project.getModules()) { diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringMVCMybatisCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringMVCMybatisCallable.java index 4e7d27b6..d0f522f9 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringMVCMybatisCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringMVCMybatisCallable.java @@ -524,7 +524,7 @@ public class SpringMVCMybatisCallable implements Callable { dbtool.mkdirs(); { XmlManager xmlManager = ManagerFactory.getXmlManager(); - xmlManager.saveAs(dbtool.getAbsolutePath(), project); + xmlManager.saveAs(dbtool, project); } try { 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 830e7ee6..4b1c4c5c 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java @@ -497,9 +497,8 @@ public class Dialog { }); ProjectManager dBmanger = ManagerFactory.getdBManager(); - String path = dBmanger.getPath(); - File file = new File(path); + File file = dBmanger.getPath(); File[] files = file.listFiles(); s: for (File f : files) { @@ -575,7 +574,7 @@ public class Dialog { public void handle(ActionEvent event) { ProjectManager dBmanger = ManagerFactory.getdBManager(); DirectoryChooser directoryChooser = new DirectoryChooser(); - directoryChooser.setInitialDirectory(new File(dBmanger.getPath())); + directoryChooser.setInitialDirectory(dBmanger.getPath()); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); if (file != null) { @@ -636,7 +635,7 @@ public class Dialog { public void handle(ActionEvent event) { ProjectManager dBmanger = ManagerFactory.getdBManager(); DirectoryChooser directoryChooser = new DirectoryChooser(); - directoryChooser.setInitialDirectory(new File(dBmanger.getPath())); + directoryChooser.setInitialDirectory(dBmanger.getPath()); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); if (file != null) { diff --git a/src/main/resources/fxml/main.fxml b/src/main/resources/fxml/main.fxml index 95f7c159..ff6ee307 100644 --- a/src/main/resources/fxml/main.fxml +++ b/src/main/resources/fxml/main.fxml @@ -1,22 +1,27 @@ + - - + + + + + + + + + + + + - - - - - - @@ -58,9 +63,10 @@