From d2ecab49911f7904f015cfe5a574576c62ff9872 Mon Sep 17 00:00:00 2001 From: Owen Zou Date: Fri, 3 Feb 2017 18:31:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MainUIController.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java index 9126b529..5e8d660b 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java @@ -94,7 +94,7 @@ public void initialize(URL location, ResourceBundle resources) { dbImage.setFitWidth(40); connectionLabel.setGraphic(dbImage); connectionLabel.setOnMouseClicked(event -> { - NewConnectionController controller = (NewConnectionController) loadFXMLPage("新建连接", FXMLPage.NEW_CONNECTION, false); + NewConnectionController controller = (NewConnectionController) loadFXMLPage("新建数据库连接", FXMLPage.NEW_CONNECTION, false); controller.setMainUIController(this); controller.showDialogStage(); }); @@ -214,6 +214,11 @@ public void generateCode() { AlertUtil.showWarnAlert("请先在左侧选择数据库表"); return; } + String result = validateConfig(); + if (result != null) { + AlertUtil.showErrorAlert(result); + return; + } GeneratorConfig generatorConfig = getGeneratorConfigFromUI(); if (!checkDirs(generatorConfig)) { return; @@ -234,7 +239,22 @@ public void generateCode() { } } - @FXML + private String validateConfig() { + String projectFolder = projectFolderField.getText(); + if (StringUtils.isEmpty(projectFolder)) { + return "项目目录不能为空"; + } + if (StringUtils.isEmpty(domainObjectNameField.getText())) { + return "类名不能为空"; + } + if (StringUtils.isAnyEmpty(modelTargetPackage.getText(), mapperTargetPackage.getText(), daoTargetPackage.getText())) { + return "包名不能为空"; + } + + return null; + } + + @FXML public void saveGeneratorConfig() { TextInputDialog dialog = new TextInputDialog("保存配置"); dialog.setTitle("保存当前配置"); @@ -320,6 +340,7 @@ public void setColumnOverrides(List columnOverrides) { */ private boolean checkDirs(GeneratorConfig config) { List dirs = new ArrayList<>(); + dirs.add(config.getProjectFolder()); dirs.add(FilenameUtils.normalize(config.getProjectFolder().concat("/").concat(config.getModelPackageTargetFolder()))); dirs.add(FilenameUtils.normalize(config.getProjectFolder().concat("/").concat(config.getDaoTargetFolder()))); dirs.add(FilenameUtils.normalize(config.getProjectFolder().concat("/").concat(config.getMappingXMLTargetFolder())));