Skip to content

Commit

Permalink
Merge pull request #1 from zhengganglee/lombok-plugin-support
Browse files Browse the repository at this point in the history
Lombok plugin support
  • Loading branch information
CoolMoonGG authored Jul 24, 2019
2 parents 6502e46 + fbfc411 commit 1fbedfb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>com.softwareloop</groupId>
<artifactId>mybatis-generator-lombok-plugin</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ public void generate() throws Exception {
serializablePluginConfiguration.addProperty("type", "org.mybatis.generator.plugins.SerializablePlugin");
serializablePluginConfiguration.setConfigurationType("org.mybatis.generator.plugins.SerializablePlugin");
context.addPluginConfiguration(serializablePluginConfiguration);

// Lombok 插件
if (generatorConfig.isUseLombokPlugin()) {
PluginConfiguration pluginConfiguration = new PluginConfiguration();
pluginConfiguration.addProperty("type", "com.softwareloop.mybatis.generator.plugins.LombokPlugin");
pluginConfiguration.setConfigurationType("com.softwareloop.mybatis.generator.plugins.LombokPlugin");
context.addPluginConfiguration(pluginConfiguration);
}
// toString, hashCode, equals插件
if (generatorConfig.isNeedToStringHashcodeEquals()) {
else if (generatorConfig.isNeedToStringHashcodeEquals()) {
PluginConfiguration pluginConfiguration1 = new PluginConfiguration();
pluginConfiguration1.addProperty("type", "org.mybatis.generator.plugins.EqualsHashCodePlugin");
pluginConfiguration1.setConfigurationType("org.mybatis.generator.plugins.EqualsHashCodePlugin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class MainUIController extends BaseFXController {
@FXML
private CheckBox needToStringHashcodeEquals;
@FXML
private CheckBox useLombokPlugin;
@FXML
private CheckBox forUpdateCheckBox;
@FXML
private CheckBox annotationDAOCheckBox;
Expand Down Expand Up @@ -139,6 +141,10 @@ public void initialize(URL location, ResourceBundle resources) {
offsetLimitCheckBox.setDisable(true);
}
});
// selectedProperty().addListener 解决应用配置的时候未触发Clicked事件
useLombokPlugin.selectedProperty().addListener((observable, oldValue, newValue) -> {
needToStringHashcodeEquals.setDisable(newValue);
});

leftDBTree.setShowRoot(false);
leftDBTree.setRoot(new TreeItem<>());
Expand Down Expand Up @@ -231,6 +237,7 @@ private void setTooltip() {
overrideXML.setTooltip(new Tooltip("重新生成时把原XML文件覆盖,否则是追加"));
useDAOExtendStyle.setTooltip(new Tooltip("将通用接口方法放在公共接口中,DAO接口留空"));
forUpdateCheckBox.setTooltip(new Tooltip("在Select语句中增加for update后缀"));
useLombokPlugin.setTooltip(new Tooltip("实体类使用Lombok @Data简化代码"));
}

void loadLeftDBTree() {
Expand Down Expand Up @@ -376,6 +383,7 @@ public GeneratorConfig getGeneratorConfigFromUI() {
generatorConfig.setComment(commentCheckBox.isSelected());
generatorConfig.setOverrideXML(overrideXML.isSelected());
generatorConfig.setNeedToStringHashcodeEquals(needToStringHashcodeEquals.isSelected());
generatorConfig.setUseLombokPlugin(useLombokPlugin.isSelected());
generatorConfig.setUseTableNameAlias(useTableNameAliasCheckbox.isSelected());
generatorConfig.setNeedForUpdate(forUpdateCheckBox.isSelected());
generatorConfig.setAnnotationDAO(annotationDAOCheckBox.isSelected());
Expand Down Expand Up @@ -405,6 +413,7 @@ public void setGeneratorConfigIntoUI(GeneratorConfig generatorConfig) {
commentCheckBox.setSelected(generatorConfig.isComment());
overrideXML.setSelected(generatorConfig.isOverrideXML());
needToStringHashcodeEquals.setSelected(generatorConfig.isNeedToStringHashcodeEquals());
useLombokPlugin.setSelected(generatorConfig.isUseLombokPlugin());
useTableNameAliasCheckbox.setSelected(generatorConfig.getUseTableNameAlias());
forUpdateCheckBox.setSelected(generatorConfig.isNeedForUpdate());
annotationDAOCheckBox.setSelected(generatorConfig.isAnnotationDAO());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class GeneratorConfig {

private boolean needToStringHashcodeEquals;

private boolean useLombokPlugin;

private boolean needForUpdate;

private boolean annotationDAO;
Expand Down Expand Up @@ -202,6 +204,14 @@ public void setNeedToStringHashcodeEquals(boolean needToStringHashcodeEquals) {
this.needToStringHashcodeEquals = needToStringHashcodeEquals;
}

public boolean isUseLombokPlugin() {
return useLombokPlugin;
}

public void setUseLombokPlugin(boolean useLombokPlugin) {
this.useLombokPlugin = useLombokPlugin;
}

public boolean isNeedForUpdate() {
return needForUpdate;
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,17 @@
<CheckBox fx:id="offsetLimitCheckBox" disable="true" minWidth="100.0" mnemonicParsing="false" selected="true" text="分页插件(暂时只支持MySQL和PostgreSQL)" GridPane.columnIndex="1" GridPane.rowIndex="8" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0">
<HBox prefHeight="100.0" prefWidth="200.0" spacing="18.0">
<children>
<CheckBox fx:id="commentCheckBox" mnemonicParsing="false" selected="true" text="生成实体域注释(来自表注释)" />
<CheckBox fx:id="overrideXML" mnemonicParsing="false" selected="true" text="覆盖原XML" />
</children>
</HBox>
<HBox>
<HBox spacing="18.0">
<children>
<CheckBox fx:id="needToStringHashcodeEquals" mnemonicParsing="false" selected="true" text="生成toString/hashCode/equals方法">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin></CheckBox>
<CheckBox fx:id="useSchemaPrefix" mnemonicParsing="false" text="使用Schema前缀" />
<CheckBox fx:id="useLombokPlugin" mnemonicParsing="false" text="LombokPlugin" />
<CheckBox fx:id="needToStringHashcodeEquals" mnemonicParsing="false" selected="true" text="生成toString/hashCode/equals方法" />
<CheckBox fx:id="useSchemaPrefix" mnemonicParsing="false" text="使用Schema前缀" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="18.0">
Expand Down

0 comments on commit 1fbedfb

Please sign in to comment.