diff --git a/README.md b/README.md
index b3c8140f..245149ea 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ mybatis-generator-gui
mybatis-generator-gui是基于[mybatis generator](http://www.mybatis.org/generator/index.html)开发一款界面工具, 本工具可以使你非常容易及快速生成Mybatis的Java POJO文件及数据库Mapping文件。
-![MainUI](https://cloud.githubusercontent.com/assets/3505708/22870467/834ed1c2-f1e2-11e6-9ae5-650b88722a7c.png)
+![image](https://user-images.githubusercontent.com/3505708/38157772-8cd08a7e-34bc-11e8-948b-bccbfa59848f.png)
### 核心特性
* 按照界面步骤轻松生成代码,省去XML繁琐的学习与配置过程
diff --git a/pom.xml b/pom.xml
index 4b2e8aa0..457f67c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.zzg
mybatis-generator-gui
- 0.8.4
+ 0.8.5
UTF-8
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 ceaafee0..b97fe0d6 100644
--- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java
+++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java
@@ -15,6 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -86,9 +87,6 @@ public void generate() throws Exception {
tableConfig.setGeneratedKey(new GeneratedKey(generatorConfig.getGenerateKeys(), selectedDatabaseConfig.getDbType(), true, null));
}
- if (generatorConfig.getMapperName() != null) {
- tableConfig.setMapperName(generatorConfig.getMapperName());
- }
// add ignore columns
if (ignoredColumns != null) {
ignoredColumns.stream().forEach(ignoredColumn -> {
@@ -103,6 +101,11 @@ public void generate() throws Exception {
if (generatorConfig.isUseActualColumnNames()) {
tableConfig.addProperty("useActualColumnNames", "true");
}
+
+ if(generatorConfig.isUseTableNameAlias()){
+ tableConfig.setAlias(generatorConfig.getTableName());
+ }
+
JDBCConnectionConfiguration jdbcConfig = new JDBCConnectionConfiguration();
// http://www.mybatis.org/generator/usage/mysql.html
if (DbType.MySQL.name().equals(selectedDatabaseConfig.getDbType())) {
@@ -180,8 +183,29 @@ public void generate() throws Exception {
Set contexts = new HashSet<>();
ShellCallback shellCallback = new DefaultShellCallback(true); // override=true
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, shellCallback, warnings);
+ // if overrideXML selected, delete oldXML ang generate new one
+ if (generatorConfig.isOverrideXML()) {
+ String mappingXMLFilePath = getMappingXMLFilePath(generatorConfig);
+ File mappingXMLFile = new File(mappingXMLFilePath);
+ if (mappingXMLFile.exists()) {
+ mappingXMLFile.delete();
+ }
+ }
+
myBatisGenerator.generate(progressCallback, contexts, fullyqualifiedTables);
}
+
+ private String getMappingXMLFilePath(GeneratorConfig generatorConfig) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(generatorConfig.getProjectFolder()).append("/");
+ sb.append(generatorConfig.getMappingXMLTargetFolder()).append("/");
+ String mappingXMLPackage = generatorConfig.getMappingXMLPackage();
+ if (StringUtils.isNotEmpty(mappingXMLPackage)) {
+ sb.append(mappingXMLPackage.replace(".", "/")).append("/");
+ }
+ sb.append(generatorConfig.getDomainObjectName()).append("Mapper.xml");
+ return sb.toString();
+ }
public void setProgressCallback(ProgressCallback progressCallback) {
this.progressCallback = progressCallback;
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 0f4c0f00..a47d082e 100644
--- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java
+++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java
@@ -55,7 +55,7 @@ public class MainUIController extends BaseFXController {
@FXML
private TextField domainObjectNameField;
@FXML
- private TextField generateKeysField; //添加输入框
+ private TextField generateKeysField; //主键ID
@FXML
private TextField modelTargetProject;
@FXML
@@ -63,16 +63,18 @@ public class MainUIController extends BaseFXController {
@FXML
private TextField daoTargetProject;
@FXML
- private TextField mapperName;
- @FXML
private TextField projectFolderField;
@FXML
private CheckBox offsetLimitCheckBox;
@FXML
private CheckBox commentCheckBox;
+ @FXML
+ private CheckBox overrideXML;
@FXML
private CheckBox needToStringHashcodeEquals;
@FXML
+ private CheckBox useTableNameAliasCheckbox;
+ @FXML
private CheckBox annotationCheckBox;
@FXML
private CheckBox useActualColumnNamesCheckbox;
@@ -186,9 +188,17 @@ public void initialize(URL location, ResourceBundle resources) {
return cell;
});
loadLeftDBTree();
- encodingChoice.setItems(FXCollections.observableArrayList("UTF-8"));
- encodingChoice.setValue("UTF-8");
- }
+ setTooltip();
+ }
+
+ private void setTooltip() {
+ encodingChoice.setTooltip(new Tooltip("生成文件的编码,必选"));
+ generateKeysField.setTooltip(new Tooltip("insert时可以返回主键ID"));
+ offsetLimitCheckBox.setTooltip(new Tooltip("是否要生成分页查询代码"));
+ commentCheckBox.setTooltip(new Tooltip("使用数据库的列注释作为实体类字段名的Java注释 "));
+ useActualColumnNamesCheckbox.setTooltip(new Tooltip("是否使用数据库实际的列名作为实体类域的名称"));
+ useTableNameAliasCheckbox.setTooltip(new Tooltip("在Mapper XML文件中表名使用别名,并且列全部使用as查询"));
+ }
void loadLeftDBTree() {
TreeItem rootTreeItem = leftDBTree.getRoot();
@@ -298,14 +308,15 @@ public GeneratorConfig getGeneratorConfigFromUI() {
generatorConfig.setModelPackageTargetFolder(modelTargetProject.getText());
generatorConfig.setDaoPackage(daoTargetPackage.getText());
generatorConfig.setDaoTargetFolder(daoTargetProject.getText());
- generatorConfig.setMapperName(mapperName.getText());
generatorConfig.setMappingXMLPackage(mapperTargetPackage.getText());
generatorConfig.setMappingXMLTargetFolder(mappingTargetProject.getText());
generatorConfig.setTableName(tableNameField.getText());
generatorConfig.setDomainObjectName(domainObjectNameField.getText());
generatorConfig.setOffsetLimit(offsetLimitCheckBox.isSelected());
generatorConfig.setComment(commentCheckBox.isSelected());
+ generatorConfig.setOverrideXML(overrideXML.isSelected());
generatorConfig.setNeedToStringHashcodeEquals(needToStringHashcodeEquals.isSelected());
+ generatorConfig.setUseTableNameAlias(useTableNameAliasCheckbox.isSelected());
generatorConfig.setAnnotation(annotationCheckBox.isSelected());
generatorConfig.setUseActualColumnNames(useActualColumnNamesCheckbox.isSelected());
generatorConfig.setEncoding(encodingChoice.getValue());
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 829bd398..052be26d 100644
--- a/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java
+++ b/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java
@@ -39,6 +39,8 @@ public class GeneratorConfig {
private boolean offsetLimit;
private boolean comment;
+
+ private boolean overrideXML;
private boolean needToStringHashcodeEquals;
@@ -51,6 +53,8 @@ public class GeneratorConfig {
private String generateKeys;
private String encoding;
+
+ private boolean useTableNameAlias;
public boolean isUseExampe() {
return useExampe;
@@ -188,14 +192,6 @@ public void setUseActualColumnNames(boolean useActualColumnNames) {
this.useActualColumnNames = useActualColumnNames;
}
- public String getMapperName() {
- return mapperName;
- }
-
- public void setMapperName(String mapperName) {
- this.mapperName = mapperName;
- }
-
public String getGenerateKeys() {
return generateKeys;
}
@@ -211,4 +207,24 @@ public String getEncoding() {
public void setEncoding(String encoding) {
this.encoding = encoding;
}
+
+ public boolean getUseTableNameAlias() {
+ return useTableNameAlias;
+ }
+
+ public void setUseTableNameAlias(boolean useTableNameAlias) {
+ this.useTableNameAlias = useTableNameAlias;
+ }
+
+ public boolean isUseTableNameAlias() {
+ return useTableNameAlias;
+ }
+
+ public boolean isOverrideXML() {
+ return overrideXML;
+ }
+
+ public void setOverrideXML(boolean overrideXML) {
+ this.overrideXML = overrideXML;
+ }
}
diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml
index 80e29b49..6212cfbf 100644
--- a/src/main/resources/fxml/MainUI.fxml
+++ b/src/main/resources/fxml/MainUI.fxml
@@ -1,5 +1,6 @@
+
@@ -7,6 +8,7 @@
+
@@ -53,8 +55,7 @@
-
-
+
@@ -155,7 +156,7 @@
-
+
@@ -174,7 +175,13 @@
-
+
+
+
+
+
+
+
@@ -192,6 +199,7 @@
+
@@ -214,15 +222,10 @@
-
-
+
-
-
+
+