From 0ac6bb0d61be07c9a50da21c509fa94e82142593 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 8 Aug 2017 05:09:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0toString/hashCode/equals?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/MybatisGeneratorBridge.java | 12 +++++++++++- .../generator/controller/MainUIController.java | 3 +++ .../generator/model/GeneratorConfig.java | 12 +++++++++++- src/main/resources/fxml/MainUI.fxml | 18 +++++++++++++----- 4 files changed, 38 insertions(+), 7 deletions(-) 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 aaa4adad..11cd1d7e 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -133,7 +133,17 @@ public void generate() throws Exception { serializablePluginConfiguration.addProperty("type", "org.mybatis.generator.plugins.SerializablePlugin"); serializablePluginConfiguration.setConfigurationType("org.mybatis.generator.plugins.SerializablePlugin"); context.addPluginConfiguration(serializablePluginConfiguration); - + // toString, hashCode, equals插件 + if (generatorConfig.isNeedToStringHashcodeEquals()) { + PluginConfiguration pluginConfiguration1 = new PluginConfiguration(); + pluginConfiguration1.addProperty("type", "org.mybatis.generator.plugins.EqualsHashCodePlugin"); + pluginConfiguration1.setConfigurationType("org.mybatis.generator.plugins.EqualsHashCodePlugin"); + context.addPluginConfiguration(pluginConfiguration1); + PluginConfiguration pluginConfiguration2 = new PluginConfiguration(); + pluginConfiguration2.addProperty("type", "org.mybatis.generator.plugins.ToStringPlugin"); + pluginConfiguration2.setConfigurationType("org.mybatis.generator.plugins.ToStringPlugin"); + context.addPluginConfiguration(pluginConfiguration2); + } // limit/offset插件 if (generatorConfig.isOffsetLimit()) { if (DbType.MySQL.name().equals(selectedDatabaseConfig.getDbType()) 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 53f04bdf..18870e48 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java @@ -71,6 +71,8 @@ public class MainUIController extends BaseFXController { @FXML private CheckBox commentCheckBox; @FXML + private CheckBox needToStringHashcodeEquals; + @FXML private CheckBox annotationCheckBox; @FXML private CheckBox useActualColumnNamesCheckbox; @@ -298,6 +300,7 @@ public GeneratorConfig getGeneratorConfigFromUI() { generatorConfig.setDomainObjectName(domainObjectNameField.getText()); generatorConfig.setOffsetLimit(offsetLimitCheckBox.isSelected()); generatorConfig.setComment(commentCheckBox.isSelected()); + generatorConfig.setNeedToStringHashcodeEquals(needToStringHashcodeEquals.isSelected()); generatorConfig.setAnnotation(annotationCheckBox.isSelected()); generatorConfig.setUseActualColumnNames(useActualColumnNamesCheckbox.isSelected()); return generatorConfig; diff --git a/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java b/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java index 1dc352f6..aee1ee0f 100644 --- a/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java +++ b/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java @@ -40,6 +40,8 @@ public class GeneratorConfig { private boolean comment; + private boolean needToStringHashcodeEquals; + private boolean annotation; private boolean useActualColumnNames; @@ -150,7 +152,15 @@ public void setComment(boolean comment) { this.comment = comment; } - public boolean isAnnotation() { + public boolean isNeedToStringHashcodeEquals() { + return needToStringHashcodeEquals; + } + + public void setNeedToStringHashcodeEquals(boolean needToStringHashcodeEquals) { + this.needToStringHashcodeEquals = needToStringHashcodeEquals; + } + + public boolean isAnnotation() { return annotation; } diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml index 35e47075..45a6b5be 100644 --- a/src/main/resources/fxml/MainUI.fxml +++ b/src/main/resources/fxml/MainUI.fxml @@ -1,11 +1,14 @@ + + + @@ -61,8 +64,8 @@ - - + +