Skip to content

Commit

Permalink
Merge pull request zouzg#44 from liu870825yi/develop
Browse files Browse the repository at this point in the history
添加Mybatis自带序列化插件和增加GeneratedKey主键生成功能
  • Loading branch information
zouzg authored Dec 21, 2016
2 parents 1171f5f + da85383 commit edbb946
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void generate() throws Exception {
TableConfiguration tableConfig = new TableConfiguration(context);
tableConfig.setTableName(generatorConfig.getTableName());
tableConfig.setDomainObjectName(generatorConfig.getDomainObjectName());
//添加GeneratedKey主键生成
tableConfig.setGeneratedKey(new GeneratedKey(generatorConfig.getGenerateKeys(), selectedDatabaseConfig.getDbType(), true, null));

if (generatorConfig.getMapperName() != null) {
tableConfig.setMapperName(generatorConfig.getMapperName());
}
Expand Down Expand Up @@ -113,6 +116,13 @@ public void generate() throws Exception {
commentConfig.addProperty("annotations", "true");
}
context.setCommentGeneratorConfiguration(commentConfig);

//实体添加序列化
PluginConfiguration serializablePluginConfiguration = new PluginConfiguration();
serializablePluginConfiguration.addProperty("type", "org.mybatis.generator.plugins.SerializablePlugin");
serializablePluginConfiguration.setConfigurationType("org.mybatis.generator.plugins.SerializablePlugin");
context.addPluginConfiguration(serializablePluginConfiguration);

// limit/offset插件
if (generatorConfig.isOffsetLimit()) {
PluginConfiguration pluginConfiguration = new PluginConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class MainUIController extends BaseFXController {
@FXML
private TextField domainObjectNameField;
@FXML
private TextField generateKeysField; //添加输入框
@FXML
private TextField modelTargetProject;
@FXML
private TextField mappingTargetProject;
Expand Down Expand Up @@ -274,6 +276,7 @@ public GeneratorConfig getGeneratorConfigFromUI() {
generatorConfig.setConnectorJarPath(connectorPathField.getText());
generatorConfig.setProjectFolder(projectFolderField.getText());
generatorConfig.setModelPackage(modelTargetPackage.getText());
generatorConfig.setGenerateKeys(generateKeysField.getText());
generatorConfig.setModelPackageTargetFolder(modelTargetProject.getText());
generatorConfig.setDaoPackage(daoTargetPackage.getText());
generatorConfig.setDaoTargetFolder(daoTargetProject.getText());
Expand All @@ -292,6 +295,7 @@ public void setGeneratorConfigIntoUI(GeneratorConfig generatorConfig) {
connectorPathField.setText(generatorConfig.getConnectorJarPath());
projectFolderField.setText(generatorConfig.getProjectFolder());
modelTargetPackage.setText(generatorConfig.getModelPackage());
generateKeysField.setText(generatorConfig.getGenerateKeys());
modelTargetProject.setText(generatorConfig.getModelPackageTargetFolder());
daoTargetPackage.setText(generatorConfig.getDaoPackage());
daoTargetProject.setText(generatorConfig.getDaoTargetFolder());
Expand Down
227 changes: 120 additions & 107 deletions src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,160 +2,173 @@

/**
*
* GeneratorConfig is the Config of mybatis generator config exclude database config
* GeneratorConfig is the Config of mybatis generator config exclude database
* config
*
* Created by Owen on 6/16/16.
*/
public class GeneratorConfig {

/**
* 本配置的名称
*/
private String name;
/**
* 本配置的名称
*/
private String name;

private String connectorJarPath;
private String connectorJarPath;

private String projectFolder;
private String projectFolder;

private String modelPackage;
private String modelPackage;

private String modelPackageTargetFolder;
private String modelPackageTargetFolder;

private String daoPackage;
private String daoPackage;

private String daoTargetFolder;
private String daoTargetFolder;

private String mapperName;
private String mapperName;

private String mappingXMLPackage;
private String mappingXMLPackage;

private String mappingXMLTargetFolder;
private String mappingXMLTargetFolder;

private String tableName;
private String tableName;

private String domainObjectName;
private String domainObjectName;

private boolean offsetLimit;
private boolean offsetLimit;

private boolean comment;
private boolean comment;

private boolean annotation;
private boolean annotation;

public String getName() {
return name;
}
private String generateKeys;

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}

public String getTableName() {
return tableName;
}
public void setName(String name) {
this.name = name;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getTableName() {
return tableName;
}

public String getDomainObjectName() {
return domainObjectName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}

public void setDomainObjectName(String domainObjectName) {
this.domainObjectName = domainObjectName;
}
public String getDomainObjectName() {
return domainObjectName;
}

public String getConnectorJarPath() {
return connectorJarPath;
}
public void setDomainObjectName(String domainObjectName) {
this.domainObjectName = domainObjectName;
}

public void setConnectorJarPath(String connectorJarPath) {
this.connectorJarPath = connectorJarPath;
}
public String getConnectorJarPath() {
return connectorJarPath;
}

public String getProjectFolder() {
return projectFolder;
}
public void setConnectorJarPath(String connectorJarPath) {
this.connectorJarPath = connectorJarPath;
}

public void setProjectFolder(String projectFolder) {
this.projectFolder = projectFolder;
}
public String getProjectFolder() {
return projectFolder;
}

public String getModelPackage() {
return modelPackage;
}
public void setProjectFolder(String projectFolder) {
this.projectFolder = projectFolder;
}

public void setModelPackage(String modelPackage) {
this.modelPackage = modelPackage;
}
public String getModelPackage() {
return modelPackage;
}

public String getModelPackageTargetFolder() {
return modelPackageTargetFolder;
}
public void setModelPackage(String modelPackage) {
this.modelPackage = modelPackage;
}

public void setModelPackageTargetFolder(String modelPackageTargetFolder) {
this.modelPackageTargetFolder = modelPackageTargetFolder;
}
public String getModelPackageTargetFolder() {
return modelPackageTargetFolder;
}

public String getDaoPackage() {
return daoPackage;
}
public void setModelPackageTargetFolder(String modelPackageTargetFolder) {
this.modelPackageTargetFolder = modelPackageTargetFolder;
}

public void setDaoPackage(String daoPackage) {
this.daoPackage = daoPackage;
}
public String getDaoPackage() {
return daoPackage;
}

public String getDaoTargetFolder() {
return daoTargetFolder;
}
public void setDaoPackage(String daoPackage) {
this.daoPackage = daoPackage;
}

public void setDaoTargetFolder(String daoTargetFolder) {
this.daoTargetFolder = daoTargetFolder;
}
public String getDaoTargetFolder() {
return daoTargetFolder;
}

public String getMappingXMLPackage() {
return mappingXMLPackage;
}
public void setDaoTargetFolder(String daoTargetFolder) {
this.daoTargetFolder = daoTargetFolder;
}

public void setMappingXMLPackage(String mappingXMLPackage) {
this.mappingXMLPackage = mappingXMLPackage;
}
public String getMappingXMLPackage() {
return mappingXMLPackage;
}

public String getMappingXMLTargetFolder() {
return mappingXMLTargetFolder;
}
public void setMappingXMLPackage(String mappingXMLPackage) {
this.mappingXMLPackage = mappingXMLPackage;
}

public void setMappingXMLTargetFolder(String mappingXMLTargetFolder) {
this.mappingXMLTargetFolder = mappingXMLTargetFolder;
}
public String getMappingXMLTargetFolder() {
return mappingXMLTargetFolder;
}

public boolean isOffsetLimit() {
return offsetLimit;
}
public void setMappingXMLTargetFolder(String mappingXMLTargetFolder) {
this.mappingXMLTargetFolder = mappingXMLTargetFolder;
}

public void setOffsetLimit(boolean offsetLimit) {
this.offsetLimit = offsetLimit;
}
public boolean isOffsetLimit() {
return offsetLimit;
}

public boolean isComment() {
return comment;
}
public void setOffsetLimit(boolean offsetLimit) {
this.offsetLimit = offsetLimit;
}

public void setComment(boolean comment) {
this.comment = comment;
}
public boolean isComment() {
return comment;
}

public boolean isAnnotation(){return annotation;}
public void setComment(boolean comment) {
this.comment = comment;
}

public void setAnnotation(boolean annotation){
this.annotation=annotation;
}
public boolean isAnnotation() {
return annotation;
}

public String getMapperName() {
return mapperName;
}
public void setAnnotation(boolean annotation) {
this.annotation = annotation;
}

public void setMapperName(String mapperName) {
this.mapperName = mapperName;
}
public String getMapperName() {
return mapperName;
}

public void setMapperName(String mapperName) {
this.mapperName = mapperName;
}

public String getGenerateKeys() {
return generateKeys;
}

public void setGenerateKeys(String generateKeys) {
this.generateKeys = generateKeys;
}
}
Loading

0 comments on commit edbb946

Please sign in to comment.