逆向工程调整

This commit is contained in:
zhangchenbiao
2023-08-14 11:34:26 +08:00
parent c937038d75
commit f7c446ba8d
5 changed files with 16 additions and 72 deletions

View File

@@ -15,7 +15,7 @@ public class GeneratorCodeMain {
try {
// 解析
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(GeneratorCodeMain.class.getResourceAsStream("/mybatis-generator-tk.xml"));
Configuration config = cp.parseConfiguration(GeneratorCodeMain.class.getResourceAsStream("/mybatis-generator.xml"));
// 是否覆盖
DefaultShellCallback dsc = new DefaultShellCallback(false);
MyBatisGenerator mg = new MyBatisGenerator(config, dsc, warnings);

View File

@@ -1,5 +1,6 @@
package generator.defined;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
@@ -63,6 +64,8 @@ public class MyCommentGenerator extends DefaultCommentGenerator implements Comme
topLevelClass.addJavaDocLine(" * @author " + author);
topLevelClass.addJavaDocLine(" * @date " + currentDateStr);
topLevelClass.addJavaDocLine(" */");
String tableName = "\"" +introspectedTable.getFullyQualifiedTableNameAtRuntime()+"\"";
topLevelClass.addAnnotation("@Table(name = "+tableName+")");
}
@Override

View File

@@ -14,7 +14,6 @@ import org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl;
import org.mybatis.generator.codegen.mybatis3.ListUtilities;
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
import org.mybatis.generator.codegen.mybatis3.javamapper.JavaMapperGenerator;
import org.mybatis.generator.codegen.mybatis3.javamapper.elements.SelectByExampleWithBLOBsMethodGenerator;
import org.mybatis.generator.codegen.mybatis3.xmlmapper.XMLMapperGenerator;
import org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.AbstractXmlElementGenerator;
import org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.InsertSelectiveElementGenerator;
@@ -71,17 +70,6 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
return JavaBeansUtil.getCamelCaseString(tableName,true);
}
private boolean isConfigTable() {
String tableName = this.getTableConfiguration().getTableName();
String tableSuffix = tableName.substring(tableName.lastIndexOf("_") + 1);
if(StringUtils.isNotBlank(tableSuffix) && tableSuffix.length() == 32){
//企业库
return false;
}
//平台库
return true;
}
@Override
protected String calculateMyBatis3XmlMapperFileName() {
StringBuilder sb = new StringBuilder();
@@ -210,7 +198,7 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
addResultMapWithBLOBsElement(answer);
addBaseColumnListElement(answer);
addBlobColumnListElement(answer);
addInsertSelectiveElement(answer);
/*addInsertSelectiveElement(answer);
addUpdateByPrimaryKeySelectiveElement(answer);
addMyBatis3UpdateByExampleWhereClauseElement(answer);
addExampleWhereClauseElement(answer);
@@ -218,7 +206,7 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
addSelectByExampleWithoutBLOBsElement(answer);
addUpdateByExampleWithBLOBsElement(answer);
addUpdateByExampleWithoutBLOBsElement(answer);
addUpdateByExampleSelectiveElement(answer);
addUpdateByExampleSelectiveElement(answer);*/
return answer;
}
@@ -276,9 +264,11 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
interfaze.addSuperInterface(fqjt);
interfaze.addImportedType(fqjt);
}
interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param"));
addInsertSelectiveMethod(interfaze);
addUpdateByPrimaryKeySelectiveMethod(interfaze);
interfaze.addSuperInterface(new FullyQualifiedJavaType("tk.mybatis.mapper.common.Mapper<"+getTableNameFromConfigFile()+"DO>"));
interfaze.addImportedType(new FullyQualifiedJavaType("tk.mybatis.mapper.common.Mapper"));
interfaze.addImportedType(new FullyQualifiedJavaType(calculateJavaModelPackage() + "."+getTableNameFromConfigFile()+"DO"));
//addInsertSelectiveMethod(interfaze);
//addUpdateByPrimaryKeySelectiveMethod(interfaze);
List<Method> methods = interfaze.getMethods();
for (Method method : methods) {
List<Parameter> parameters = method.getParameters();
@@ -287,10 +277,10 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
parameter.addAnnotation("@Param(\""+ name+"\")");
}
}
addSelectByExampleWithBLOBsMethod(interfaze);
/*addSelectByExampleWithBLOBsMethod(interfaze);
addSelectByExampleWithoutBLOBsMethod(interfaze);
addUpdateByExampleSelectiveMethod(interfaze);
addUpdateByExampleWithoutBLOBsMethod(interfaze);
addUpdateByExampleWithoutBLOBsMethod(interfaze);*/
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().clientGenerated(interfaze, null, introspectedTable)) {
answer.add(interfaze);
@@ -491,54 +481,4 @@ public class MyIntrospectedTableMyBatis3Impl extends IntrospectedTableMyBatis3Im
}
}
}
public class MySelectByExampleWithBLOBsMethodGenerator extends SelectByExampleWithBLOBsMethodGenerator {
public MySelectByExampleWithBLOBsMethodGenerator() {
super();
}
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(
introspectedTable.getExampleType());
importedTypes.add(type);
importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType returnType = FullyQualifiedJavaType
.getNewListInstance();
FullyQualifiedJavaType listType;
if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
listType = new FullyQualifiedJavaType(introspectedTable
.getRecordWithBLOBsType());
} else {
// the blob fields must be rolled up into the base class
listType = new FullyQualifiedJavaType(introspectedTable
.getBaseRecordType());
}
importedTypes.add(listType);
returnType.addTypeArgument(listType);
method.setReturnType(returnType);
method.setName(introspectedTable
.getSelectByExampleWithBLOBsStatementId());
method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
context.getCommentGenerator().addGeneralMethodComment(method,
introspectedTable);
addMapperAnnotations(interfaze, method);
if (context.getPlugins()
.clientSelectByExampleWithBLOBsMethodGenerated(method, interfaze,
introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
}
}

View File

@@ -42,6 +42,7 @@ public class MyPluginAdapter extends PluginAdapter {
topLevelClass.addImportedType("lombok.NoArgsConstructor");
topLevelClass.addImportedType("lombok.AllArgsConstructor");
topLevelClass.addImportedType("io.swagger.annotations.ApiModelProperty");
topLevelClass.addImportedType("javax.persistence.Table");
topLevelClass.addAnnotation("@Data");
topLevelClass.addAnnotation("@Builder");
topLevelClass.addAnnotation("@NoArgsConstructor");

View File

@@ -29,8 +29,8 @@
<!-- targetPackagemapper接口生成的位置 -->
<javaClientGenerator targetPackage="com.cool.store.mapper" targetProject="coolstore-partner-dao/src/main/java" type="XMLMAPPER" />
<table tableName="${table.name}" enableCountByExample="false" enableUpdateByExample="true" enableDeleteByExample="false"
enableSelectByExample="true" selectByExampleQueryId="true">
<table tableName="${table.name}" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true" type=""/>
</table>
</context>