From 88f169629ce807704e96e500c5c69a8537add67a Mon Sep 17 00:00:00 2001 From: Owen Date: Sat, 17 Jun 2017 17:20:10 +0800 Subject: [PATCH] =?UTF-8?q?fix=E5=B7=A6=E4=BE=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=A0=91=E4=B8=8D=E8=83=BD=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E5=90=8D=E7=A7=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ .../bridge/MybatisGeneratorBridge.java | 3 --- .../controller/BaseFXController.java | 20 +++++++--------- .../controller/DbConnectionController.java | 4 +++- .../controller/MainUIController.java | 13 ++++++----- .../SelectTableColumnController.java | 6 ++--- .../generator/model/DatabaseConfig.java | 13 +++++++++++ .../plugins/DbRemarksCommentGenerator.java | 1 - .../generator/plugins/MySQLLimitPlugin.java | 11 +++------ .../mybatis/generator/util/ConfigHelper.java | 22 +++++++++--------- .../generator/util/ConnectionManager.java | 7 ------ .../zzg/mybatis/generator/util/DbUtil.java | 4 ---- .../generator/view/LeftDbTreeCell.java | 1 - src/main/resources/fxml/MainUI.fxml | 10 +++----- src/main/resources/fxml/generatorConfigs.fxml | 5 ++-- src/main/resources/fxml/newConnection.fxml | 8 ++----- .../resources/fxml/selectTableColumn.fxml | 4 +--- src/main/resources/sqlite3.db | Bin 20480 -> 28672 bytes 18 files changed, 59 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index f4e7d7d4..a278b3ff 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ mybatis-generator-gui是基于[mybatis generator](http://www.mybatis.org/generat ![MainUI](https://cloud.githubusercontent.com/assets/3505708/22870467/834ed1c2-f1e2-11e6-9ae5-650b88722a7c.png) +### 注意事项 +* 0.8.3版本请删除版本之前版本config目录下的sqlite3.db文件,重新`mvn install`安装 + ### 核心特性 * 按照界面步骤轻松生成代码,省去XML繁琐的学习与配置过程 * 保存数据库连接与Generator配置,每次代码生成轻松搞定 diff --git a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java index 5522fd7b..0dbade9c 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -12,7 +12,6 @@ import org.mybatis.generator.api.ShellCallback; import org.mybatis.generator.config.*; import org.mybatis.generator.internal.DefaultShellCallback; -import org.mybatis.generator.internal.ObjectFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,8 +20,6 @@ import java.util.List; import java.util.Set; -import static org.mybatis.generator.internal.util.ClassloaderUtility.getCustomClassloader; - /** * The bridge between GUI and the mybatis generator. All the operation to mybatis generator should proceed through this * class diff --git a/src/main/java/com/zzg/mybatis/generator/controller/BaseFXController.java b/src/main/java/com/zzg/mybatis/generator/controller/BaseFXController.java index cc84af1d..2cd1b9e6 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/BaseFXController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/BaseFXController.java @@ -1,22 +1,20 @@ package com.zzg.mybatis.generator.controller; -import java.io.IOException; -import java.lang.ref.SoftReference; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - import com.zzg.mybatis.generator.view.AlertUtil; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Modality; +import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javafx.fxml.FXMLLoader; -import javafx.fxml.Initializable; -import javafx.scene.Parent; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; +import java.io.IOException; +import java.lang.ref.SoftReference; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; public abstract class BaseFXController implements Initializable { private static final Logger _LOG = LoggerFactory.getLogger(BaseFXController.class); diff --git a/src/main/java/com/zzg/mybatis/generator/controller/DbConnectionController.java b/src/main/java/com/zzg/mybatis/generator/controller/DbConnectionController.java index 05ebbb27..cdd5f38a 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/DbConnectionController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/DbConnectionController.java @@ -36,6 +36,7 @@ public class DbConnectionController extends BaseFXController { private ChoiceBox dbTypeChoice; private MainUIController mainUIController; private boolean isUpdate = false; + private Integer primayKey; @Override @@ -49,7 +50,7 @@ void saveConnection() { return; } try { - ConfigHelper.saveDatabaseConfig(this.isUpdate, config); + ConfigHelper.saveDatabaseConfig(this.isUpdate, primayKey, config); getDialogStage().close(); mainUIController.loadLeftDBTree(); } catch (Exception e) { @@ -110,6 +111,7 @@ private DatabaseConfig extractConfigForUI() { public void setConfig(DatabaseConfig config) { isUpdate = true; + primayKey = config.getId(); // save id for update config nameField.setText(config.getName()); hostField.setText(config.getHost()); portField.setText(config.getPort()); 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 5b990150..53f04bdf 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java @@ -35,8 +35,6 @@ import java.util.Optional; import java.util.ResourceBundle; -import static org.junit.Assert.assertNotNull; - public class MainUIController extends BaseFXController { private static final Logger _LOG = LoggerFactory.getLogger(MainUIController.class); @@ -135,7 +133,7 @@ public void initialize(URL location, ResourceBundle resources) { item3.setOnAction(event1 -> { DatabaseConfig selectedConfig = (DatabaseConfig) treeItem.getGraphic().getUserData(); try { - ConfigHelper.deleteDatabaseConfig(selectedConfig.getName()); + ConfigHelper.deleteDatabaseConfig(selectedConfig); this.loadLeftDBTree(); } catch (Exception e) { AlertUtil.showErrorAlert("Delete connection failed! Reason: " + e.getMessage()); @@ -188,9 +186,8 @@ public void initialize(URL location, ResourceBundle resources) { void loadLeftDBTree() { TreeItem rootTreeItem = leftDBTree.getRoot(); rootTreeItem.getChildren().clear(); - List dbConfigs = null; try { - dbConfigs = ConfigHelper.loadDatabaseConfig(); + List dbConfigs = ConfigHelper.loadDatabaseConfig(); for (DatabaseConfig dbConfig : dbConfigs) { TreeItem treeItem = new TreeItem<>(); treeItem.setValue(dbConfig.getName()); @@ -265,12 +262,16 @@ private String validateConfig() { @FXML public void saveGeneratorConfig() { - TextInputDialog dialog = new TextInputDialog("保存配置"); + TextInputDialog dialog = new TextInputDialog(""); dialog.setTitle("保存当前配置"); dialog.setContentText("请输入配置名称"); Optional result = dialog.showAndWait(); if (result.isPresent()) { String name = result.get(); + if (StringUtils.isEmpty(name)) { + AlertUtil.showErrorAlert("名称不能为空"); + return; + } _LOG.info("user choose name: {}", name); try { GeneratorConfig generatorConfig = getGeneratorConfigFromUI(); diff --git a/src/main/java/com/zzg/mybatis/generator/controller/SelectTableColumnController.java b/src/main/java/com/zzg/mybatis/generator/controller/SelectTableColumnController.java index cb2918bf..d65e9960 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/SelectTableColumnController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/SelectTableColumnController.java @@ -1,12 +1,10 @@ package com.zzg.mybatis.generator.controller; -import com.zzg.mybatis.generator.model.DatabaseConfig; import com.zzg.mybatis.generator.model.UITableColumnVO; -import javafx.application.Platform; -import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.control.*; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.TextFieldTableCell; diff --git a/src/main/java/com/zzg/mybatis/generator/model/DatabaseConfig.java b/src/main/java/com/zzg/mybatis/generator/model/DatabaseConfig.java index 6accf1ba..e0fc7f94 100644 --- a/src/main/java/com/zzg/mybatis/generator/model/DatabaseConfig.java +++ b/src/main/java/com/zzg/mybatis/generator/model/DatabaseConfig.java @@ -7,6 +7,11 @@ */ public class DatabaseConfig { + /** + * The primary key in the sqlite db + */ + private Integer id; + private String dbType; /** * The name of the config @@ -25,6 +30,14 @@ public class DatabaseConfig { private String encoding; + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + public String getName() { return name; } diff --git a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java index 5d28c3d2..9656327b 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/DbRemarksCommentGenerator.java @@ -87,7 +87,6 @@ public void addModelClassComment(TopLevelClass topLevelClass, topLevelClass.addJavaDocLine(" * @author "); topLevelClass.addJavaDocLine(" */"); if(isAnnotations) { - topLevelClass.addAnnotation("@Talbe(name=\"" + introspectedTable.getFullyQualifiedTableNameAtRuntime() + "\")"); } } diff --git a/src/main/java/com/zzg/mybatis/generator/plugins/MySQLLimitPlugin.java b/src/main/java/com/zzg/mybatis/generator/plugins/MySQLLimitPlugin.java index 1bfb1c90..a428b396 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/MySQLLimitPlugin.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/MySQLLimitPlugin.java @@ -3,21 +3,16 @@ /** * Created by zouzhigang on 2016/6/14. */ -import java.util.List; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.PluginAdapter; -import org.mybatis.generator.api.dom.java.Field; -import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; -import org.mybatis.generator.api.dom.java.JavaVisibility; -import org.mybatis.generator.api.dom.java.Method; -import org.mybatis.generator.api.dom.java.Parameter; -import org.mybatis.generator.api.dom.java.PrimitiveTypeWrapper; -import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.api.dom.java.*; import org.mybatis.generator.api.dom.xml.Attribute; import org.mybatis.generator.api.dom.xml.TextElement; import org.mybatis.generator.api.dom.xml.XmlElement; +import java.util.List; + public class MySQLLimitPlugin extends PluginAdapter { @Override diff --git a/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java b/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java index f6f912db..7aa5e802 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java +++ b/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java @@ -4,15 +4,15 @@ import com.zzg.mybatis.generator.model.DatabaseConfig; import com.zzg.mybatis.generator.model.DbType; import com.zzg.mybatis.generator.model.GeneratorConfig; -import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.*; -import java.net.URISyntaxException; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; @@ -68,10 +68,10 @@ public static List loadDatabaseConfig() throws Exception { rs = stat.executeQuery("SELECT * FROM dbs"); List configs = new ArrayList<>(); while (rs.next()) { - String name = rs.getString("name"); + int id = rs.getInt("id"); String value = rs.getString("value"); DatabaseConfig databaseConfig = JSON.parseObject(value, DatabaseConfig.class); - databaseConfig.setName(name); + databaseConfig.setId(id); configs.add(databaseConfig); } @@ -83,7 +83,7 @@ public static List loadDatabaseConfig() throws Exception { } } - public static void saveDatabaseConfig(boolean isUpdate, DatabaseConfig dbConfig) throws Exception { + public static void saveDatabaseConfig(boolean isUpdate, Integer primaryKey, DatabaseConfig dbConfig) throws Exception { String configName = dbConfig.getName(); Connection conn = null; Statement stat = null; @@ -100,9 +100,9 @@ public static void saveDatabaseConfig(boolean isUpdate, DatabaseConfig dbConfig) String jsonStr = JSON.toJSONString(dbConfig); String sql; if (isUpdate) { - sql = String.format("UPDATE dbs SET value = '%s' where name = '%s'", jsonStr, configName); + sql = String.format("UPDATE dbs SET name = '%s', value = '%s' where id = %d", configName, jsonStr, primaryKey); } else { - sql = String.format("INSERT INTO dbs values('%s', '%s')", configName, jsonStr); + sql = String.format("INSERT INTO dbs (name, value) values('%s', '%s')", configName, jsonStr); } stat.executeUpdate(sql); } finally { @@ -112,14 +112,14 @@ public static void saveDatabaseConfig(boolean isUpdate, DatabaseConfig dbConfig) } } - public static void deleteDatabaseConfig(String name) throws Exception { + public static void deleteDatabaseConfig(DatabaseConfig databaseConfig) throws Exception { Connection conn = null; Statement stat = null; ResultSet rs = null; try { conn = ConnectionManager.getConnection(); stat = conn.createStatement(); - String sql = String.format("delete from dbs where name='%s'", name); + String sql = String.format("delete from dbs where id=%d", databaseConfig.getId()); stat.executeUpdate(sql); } finally { if (rs != null) rs.close(); diff --git a/src/main/java/com/zzg/mybatis/generator/util/ConnectionManager.java b/src/main/java/com/zzg/mybatis/generator/util/ConnectionManager.java index 244d2c53..a23ecec8 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/ConnectionManager.java +++ b/src/main/java/com/zzg/mybatis/generator/util/ConnectionManager.java @@ -1,14 +1,7 @@ package com.zzg.mybatis.generator.util; -import com.alibaba.fastjson.JSON; -import com.zzg.mybatis.generator.model.DatabaseConfig; - import java.sql.Connection; import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; /** * Created by Owen on 8/21/16. diff --git a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java index 0a2475cd..b1254a3b 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java +++ b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java @@ -3,8 +3,6 @@ import com.zzg.mybatis.generator.model.DatabaseConfig; import com.zzg.mybatis.generator.model.DbType; import com.zzg.mybatis.generator.model.UITableColumnVO; -import org.apache.commons.lang3.StringUtils; -import org.mybatis.generator.config.JDBCConnectionConfiguration; import org.mybatis.generator.internal.util.ClassloaderUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,8 +10,6 @@ import java.sql.*; import java.util.*; -import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; - /** * Created by Owen on 6/12/16. */ diff --git a/src/main/java/com/zzg/mybatis/generator/view/LeftDbTreeCell.java b/src/main/java/com/zzg/mybatis/generator/view/LeftDbTreeCell.java index 664b52b2..cf421b95 100644 --- a/src/main/java/com/zzg/mybatis/generator/view/LeftDbTreeCell.java +++ b/src/main/java/com/zzg/mybatis/generator/view/LeftDbTreeCell.java @@ -4,7 +4,6 @@ import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.WeakInvalidationListener; -import javafx.scene.Node; import javafx.scene.control.TreeCell; import javafx.scene.control.TreeItem; import javafx.scene.layout.HBox; diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml index b38154ec..35e47075 100644 --- a/src/main/resources/fxml/MainUI.fxml +++ b/src/main/resources/fxml/MainUI.fxml @@ -1,15 +1,11 @@ - - - + - - - - + + diff --git a/src/main/resources/fxml/generatorConfigs.fxml b/src/main/resources/fxml/generatorConfigs.fxml index e82aa126..a474d30f 100644 --- a/src/main/resources/fxml/generatorConfigs.fxml +++ b/src/main/resources/fxml/generatorConfigs.fxml @@ -1,9 +1,8 @@ - - + + - diff --git a/src/main/resources/fxml/newConnection.fxml b/src/main/resources/fxml/newConnection.fxml index 1d43f509..fd2cc526 100644 --- a/src/main/resources/fxml/newConnection.fxml +++ b/src/main/resources/fxml/newConnection.fxml @@ -1,13 +1,9 @@ - + - - - - - + diff --git a/src/main/resources/fxml/selectTableColumn.fxml b/src/main/resources/fxml/selectTableColumn.fxml index 3c0465e9..18cf955f 100644 --- a/src/main/resources/fxml/selectTableColumn.fxml +++ b/src/main/resources/fxml/selectTableColumn.fxml @@ -1,10 +1,8 @@ - - - + diff --git a/src/main/resources/sqlite3.db b/src/main/resources/sqlite3.db index 2be34ed45a7f24d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