Skip to content

Commit

Permalink
添加toString/hashCode/equals方法生成
Browse files Browse the repository at this point in the history
  • Loading branch information
zouzg committed Aug 7, 2017
1 parent 08d35ac commit 0ac6bb0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class GeneratorConfig {

private boolean comment;

private boolean needToStringHashcodeEquals;

private boolean annotation;

private boolean useActualColumnNames;
Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 13 additions & 5 deletions src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<?import java.lang.*?>

<BorderPane prefHeight="613.0" prefWidth="918.0" stylesheets="@../style.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zzg.mybatis.generator.controller.MainUIController">
<top>
<VBox>
Expand Down Expand Up @@ -61,8 +64,8 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="72.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="63.0" minHeight="8.0" prefHeight="63.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="92.0" minHeight="62.0" prefHeight="62.0" />
<RowConstraints maxHeight="114.0" minHeight="8.0" prefHeight="58.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="99.0" minHeight="11.0" prefHeight="95.0" />
</rowConstraints>
<children>
<Label text="表名" />
Expand Down Expand Up @@ -166,12 +169,17 @@
<GridPane.margin>
<Insets left="5.0" />
</GridPane.margin></TextField>
<VBox spacing="5.0" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="7">
<VBox prefHeight="53.0" prefWidth="536.0" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="7">
<children>
<HBox alignment="CENTER_LEFT" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="8">
<children>
<CheckBox fx:id="offsetLimitCheckBox" minWidth="100.0" mnemonicParsing="false" selected="true" text="分页" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<CheckBox fx:id="commentCheckBox" mnemonicParsing="false" selected="true" text="数据库表注释所有POJO的注释" />
<CheckBox fx:id="commentCheckBox" mnemonicParsing="false" selected="true" text="生成实体域注释(来自表注释)" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<CheckBox fx:id="needToStringHashcodeEquals" mnemonicParsing="false" selected="true" text="生成toString/hashCode/equals方法" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="18.0">
Expand All @@ -185,7 +193,7 @@
<Insets left="5.0" />
</padding>
</VBox>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="8">
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="8">
<children>
<Button mnemonicParsing="false" onAction="#generateCode" text="代码生成">
<styleClass>
Expand Down

0 comments on commit 0ac6bb0

Please sign in to comment.