Skip to content

Commit

Permalink
自定义Example类后缀,优化UI
Browse files Browse the repository at this point in the history
  • Loading branch information
leecho committed Dec 13, 2018
1 parent f974b1f commit fd765d4
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 102 deletions.
Binary file removed lib/mybatis-generator-lombok-plugin-1.1-SNAPSHOT.jar
Binary file not shown.
2 changes: 0 additions & 2 deletions mybatis-generator-plus.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="mybatis-generator-lombok-plugin-1.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="javaparser-core-3.6.25" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.github.leecho.idea.plugin.mybatis.generator</id>
<name>MyBatis Generator Plus</name>
<version>1.0</version>
<version>1.1</version>
<vendor email="[email protected]" url="http://wwww.github.com/leecho">Leecho</vendor>

<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.github.leecho.idea.plugin.mybatis.generator.model.DbType;
import com.github.leecho.idea.plugin.mybatis.generator.setting.MyBatisGeneratorConfiguration;
import com.github.leecho.idea.plugin.mybatis.generator.util.StringUtils;
import org.mybatis.generator.api.GeneratedXmlFile;
import org.mybatis.generator.api.ShellCallback;
import org.mybatis.generator.config.*;
import org.mybatis.generator.internal.DefaultShellCallback;
Expand Down Expand Up @@ -180,10 +179,10 @@ public void run(ProgressIndicator indicator) {
}

private String getRelativePath(Project project) {
if (entityConfig.getProjectRootPath().equals(project.getBasePath())) {
if (entityConfig.getModuleRootPath().equals(project.getBasePath())) {
return "";
} else {
return entityConfig.getProjectRootPath().replace(project.getBasePath() + "/", "") + "/";
return entityConfig.getModuleRootPath().replace(project.getBasePath() + "/", "") + "/";
}
}

Expand All @@ -196,8 +195,8 @@ private String getRelativePath(Project project) {
private void createFolderForNeed(EntityConfig entityConfig) {


String sourcePath = entityConfig.getProjectRootPath() + "/" + entityConfig.getSourcePath() + "/";
String resourcePath = entityConfig.getProjectRootPath() + "/" + entityConfig.getResourcePath() + "/";
String sourcePath = entityConfig.getModuleRootPath() + "/" + entityConfig.getSourcePath() + "/";
String resourcePath = entityConfig.getModuleRootPath() + "/" + entityConfig.getResourcePath() + "/";

File sourceFile = new File(sourcePath);
if (!sourceFile.exists() && !sourceFile.isDirectory()) {
Expand Down Expand Up @@ -351,7 +350,7 @@ private TableConfiguration buildTableConfig(Context context) {
* @return
*/
private JavaModelGeneratorConfiguration buildModelConfig() {
String projectFolder = entityConfig.getProjectRootPath();
String projectFolder = entityConfig.getModuleRootPath();
String entityPackage = entityConfig.getEntityPackage();
String sourcePath = entityConfig.getSourcePath();

Expand All @@ -373,7 +372,7 @@ private JavaModelGeneratorConfiguration buildModelConfig() {
*/
private SqlMapGeneratorConfiguration buildMapperXmlConfig() {

String projectFolder = entityConfig.getProjectRootPath();
String projectFolder = entityConfig.getModuleRootPath();
String mappingXMLPackage = entityConfig.getXmlPackage();
String resourcePath = entityConfig.getResourcePath();

Expand Down Expand Up @@ -406,7 +405,7 @@ private SqlMapGeneratorConfiguration buildMapperXmlConfig() {
*/
private JavaClientGeneratorConfiguration buildMapperConfig() {

String projectFolder = entityConfig.getProjectRootPath();
String projectFolder = entityConfig.getModuleRootPath();
String mapperPackage = entityConfig.getMapperPackage();
String mapperPath = entityConfig.getSourcePath();

Expand Down Expand Up @@ -472,8 +471,8 @@ private void addPluginConfiguration(Context context) {

if (entityConfig.isLombokAnnotation()) {
PluginConfiguration lombokPlugin = new PluginConfiguration();
lombokPlugin.addProperty("type", "com.softwareloop.mybatis.generator.plugins.LombokPlugin");
lombokPlugin.setConfigurationType("com.softwareloop.mybatis.generator.plugins.LombokPlugin");
lombokPlugin.addProperty("type", "com.github.leecho.idea.plugin.mybatis.generator.plugin.LombokPlugin");
lombokPlugin.setConfigurationType("com.github.leecho.idea.plugin.mybatis.generator.plugin.LombokPlugin");
if (entityConfig.isLombokBuilderAnnotation()) {
lombokPlugin.addProperty("builder", "true");
lombokPlugin.addProperty("allArgsConstructor", "true");
Expand All @@ -482,6 +481,14 @@ private void addPluginConfiguration(Context context) {
context.addPluginConfiguration(lombokPlugin);
}

if (entityConfig.isUseExample()) {
PluginConfiguration renameExamplePlugin = new PluginConfiguration();
renameExamplePlugin.addProperty("type", "com.github.leecho.idea.plugin.mybatis.generator.plugin.RenameExampleClassPlugin");
renameExamplePlugin.setConfigurationType("com.github.leecho.idea.plugin.mybatis.generator.plugin.RenameExampleClassPlugin");
renameExamplePlugin.addProperty("target", entityConfig.getExamplePackage() + "." + entityConfig.getExampleName());
context.addPluginConfiguration(renameExamplePlugin);
}


// limit/offset插件
if (entityConfig.isOffsetLimit()) {
Expand Down Expand Up @@ -546,7 +553,7 @@ private String getMappingXMLFilePath(EntityConfig entityConfig) {
StringBuilder sb = new StringBuilder();
String mappingXMLPackage = entityConfig.getXmlPackage();
String xmlMvnPath = entityConfig.getResourcePath();
sb.append(entityConfig.getProjectRootPath() + "/" + xmlMvnPath + "/");
sb.append(entityConfig.getModuleRootPath() + "/" + xmlMvnPath + "/");

if (!StringUtils.isEmpty(mappingXMLPackage)) {
sb.append(mappingXMLPackage.replace(".", "/")).append("/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,36 @@ public class EntityConfig {
*/
private String mapperName;

/**
* dao名称
*/
private String exampleName;

/**
* dao后缀
*/
private String mapperPostfix;

/**
* dao后缀
*/
private String examplePostfix;

/**
* 工程目录
*/
private String projectRootPath;
private String moduleRootPath;

private String sourcePath;
private String resourcePath;

private String basePackage;
private String entityPackage;

private String mapperPackage;

private String examplePackage;

private String xmlPackage;


Expand Down Expand Up @@ -182,12 +195,12 @@ public void setConnectorJarPath(String connectorJarPath) {
this.connectorJarPath = connectorJarPath;
}

public String getProjectRootPath() {
return projectRootPath;
public String getModuleRootPath() {
return moduleRootPath;
}

public void setProjectRootPath(String projectRootPath) {
this.projectRootPath = projectRootPath;
public void setModuleRootPath(String moduleRootPath) {
this.moduleRootPath = moduleRootPath;
}

public String getEntityPackage() {
Expand Down Expand Up @@ -371,4 +384,36 @@ public boolean isLombokBuilderAnnotation() {
public void setLombokBuilderAnnotation(boolean lombokBuilderAnnotation) {
this.lombokBuilderAnnotation = lombokBuilderAnnotation;
}

public String getExamplePackage() {
return examplePackage;
}

public void setExamplePackage(String examplePackage) {
this.examplePackage = examplePackage;
}

public String getExamplePostfix() {
return examplePostfix;
}

public void setExamplePostfix(String examplePostfix) {
this.examplePostfix = examplePostfix;
}

public String getExampleName() {
return exampleName;
}

public void setExampleName(String exampleName) {
this.exampleName = exampleName;
}

public String getBasePackage() {
return basePackage;
}

public void setBasePackage(String basePackage) {
this.basePackage = basePackage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

public class GlobalConfig {

private String projectRootPath;
private String moduleRootPath;
private String sourcePath;
private String resourcePath;
private String mapperPostfix;
private String examplePostfix;

private String entityPackage;
private String mapperPackage;
private String examplePackage;
private String xmlPackage;


Expand Down Expand Up @@ -262,12 +264,28 @@ public void setLombokBuilderAnnotation(boolean lombokBuilderAnnotation) {
this.lombokBuilderAnnotation = lombokBuilderAnnotation;
}

public String getProjectRootPath() {
return projectRootPath;
public String getModuleRootPath() {
return moduleRootPath;
}

public void setProjectRootPath(String projectRootPath) {
this.projectRootPath = projectRootPath;
public void setModuleRootPath(String moduleRootPath) {
this.moduleRootPath = moduleRootPath;
}

public String getExamplePostfix() {
return examplePostfix;
}

public void setExamplePostfix(String examplePostfix) {
this.examplePostfix = examplePostfix;
}

public String getExamplePackage() {
return examplePackage;
}

public void setExamplePackage(String examplePackage) {
this.examplePackage = examplePackage;
}

public static GlobalConfig getDefault() {
Expand All @@ -276,6 +294,7 @@ public static GlobalConfig getDefault() {
globalConfig.setResourcePath("src/main/resources");
globalConfig.setMapperPostfix("Mapper");
globalConfig.setXmlPackage("mapper");
globalConfig.setExamplePostfix("Example");
globalConfig.setUseExample(true);
globalConfig.setComment(true);
return globalConfig;
Expand Down
Loading

0 comments on commit fd765d4

Please sign in to comment.