Commit 276d0e20 authored by hewei's avatar hewei

优化IncrementsPlugin,辅助字段不要使用get&set方法,会导致JSON格式化的时候会把改字段输出

parent 4077b1cc
...@@ -46,6 +46,7 @@ import java.util.List; ...@@ -46,6 +46,7 @@ import java.util.List;
public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginHook, IIncrementsPluginHook, ILombokPluginHook { public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginHook, IIncrementsPluginHook, ILombokPluginHook {
public static final String PRO_INCREMENTS_COLUMNS = "incrementsColumns"; // incrementsColumns property public static final String PRO_INCREMENTS_COLUMNS = "incrementsColumns"; // incrementsColumns property
public static final String FIELD_INC_MAP = "incrementsColumnsInfoMap"; // 为了防止和用户数据库字段冲突,特殊命名 public static final String FIELD_INC_MAP = "incrementsColumnsInfoMap"; // 为了防止和用户数据库字段冲突,特殊命名
public static final String METHOD_GET_INC_MAP = "incrementsColumnsInfoMap"; // 获取inc map
public static final String METHOD_INC_CHECK = "hasIncsForColumn"; // inc 检查方法名称 public static final String METHOD_INC_CHECK = "hasIncsForColumn"; // inc 检查方法名称
private List<IntrospectedColumn> incColumns; // 表启用增量操作的字段 private List<IntrospectedColumn> incColumns; // 表启用增量操作的字段
...@@ -316,7 +317,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH ...@@ -316,7 +317,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
builderCls.addField(fIncrements); builderCls.addField(fIncrements);
// Builder 构造函数增加 自增Map // Builder 构造函数增加 自增Map
constructor.addBodyLine("this." + IncrementsPlugin.FIELD_INC_MAP + " = builder." + IncrementsPlugin.FIELD_INC_MAP + ";"); constructor.addBodyLine("this." + IncrementsPlugin.FIELD_INC_MAP + ".putAll(builder." + IncrementsPlugin.FIELD_INC_MAP + ");");
} }
FullyQualifiedJavaType builderType2 = new FullyQualifiedJavaType(topLevelClass.getType().getShortName() + "." + topLevelClass.getType().getShortName() + "Builder"); FullyQualifiedJavaType builderType2 = new FullyQualifiedJavaType(topLevelClass.getType().getShortName() + "." + topLevelClass.getType().getShortName() + "Builder");
...@@ -473,8 +474,8 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH ...@@ -473,8 +474,8 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
)); ));
TextElement spec = new TextElement( TextElement spec = new TextElement(
MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn)
+ " ${" + (prefix != null ? prefix : "") + " ${" + (prefix != null ? prefix : "_parameter.")
+ IncrementsPlugin.FIELD_INC_MAP + "." + MyBatis3FormattingUtilities.escapeStringForMyBatis3(introspectedColumn.getActualColumnName()) + ".value} " + IncrementsPlugin.METHOD_GET_INC_MAP + "()." + MyBatis3FormattingUtilities.escapeStringForMyBatis3(introspectedColumn.getActualColumnName()) + ".value} "
+ MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix)); + MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix));
when.addElement(spec); when.addElement(spec);
choose.addElement(when); choose.addElement(when);
...@@ -519,7 +520,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH ...@@ -519,7 +520,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
sb.append("column.value"); sb.append("column.value");
when.addAttribute(new Attribute("test", sb.toString())); when.addAttribute(new Attribute("test", sb.toString()));
when.addElement(new TextElement("${column.escapedColumnName} = ${column.escapedColumnName} ${record." + FIELD_INC_MAP + "." when.addElement(new TextElement("${column.escapedColumnName} = ${column.escapedColumnName} ${record." + METHOD_GET_INC_MAP + "()."
+ introspectedColumn.getActualColumnName() + introspectedColumn.getActualColumnName()
+ ".value} #{record.${column.javaProperty},jdbcType=${column.jdbcType}}")); + ".value} #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
choose.addElement(when); choose.addElement(when);
...@@ -561,18 +562,24 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH ...@@ -561,18 +562,24 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
new FullyQualifiedJavaType("Map<String, " + this.getIncEnum(builderCls, introspectedTable).getFullyQualifiedName() + ">"), new FullyQualifiedJavaType("Map<String, " + this.getIncEnum(builderCls, introspectedTable).getFullyQualifiedName() + ">"),
"new HashMap<String, " + this.getIncEnum(builderCls, introspectedTable).getFullyQualifiedName() + ">()" "new HashMap<String, " + this.getIncEnum(builderCls, introspectedTable).getFullyQualifiedName() + ">()"
); );
fIncrements.setFinal(true);
commentGenerator.addFieldComment(fIncrements, introspectedTable); commentGenerator.addFieldComment(fIncrements, introspectedTable);
topLevelClass.addField(fIncrements); topLevelClass.addField(fIncrements);
topLevelClass.addImportedType("java.util.Map"); topLevelClass.addImportedType("java.util.Map");
topLevelClass.addImportedType("java.util.HashMap"); topLevelClass.addImportedType("java.util.HashMap");
// getter&setter // inc map 获取方法
if (!withLombok) { if (withLombok) {
Method mGetter = JavaElementGeneratorTools.generateGetterMethod(fIncrements); topLevelClass.addImportedType(LombokPlugin.EnumLombokAnnotations.ACCESSORS_FLUENT_TRUE.getClazz());
commentGenerator.addGetterComment(mGetter, introspectedTable, null); fIncrements.addAnnotation(LombokPlugin.EnumLombokAnnotations.ACCESSORS_FLUENT_TRUE.getAnnotation());
FormatTools.addMethodWithBestPosition(topLevelClass, mGetter); } else {
Method mSetter = JavaElementGeneratorTools.generateSetterMethod(fIncrements); Method getIncMapMethod = JavaElementGeneratorTools.generateMethod(
commentGenerator.addSetterComment(mSetter, introspectedTable, null); METHOD_GET_INC_MAP,
FormatTools.addMethodWithBestPosition(topLevelClass, mSetter); JavaVisibility.PUBLIC,
fIncrements.getType()
);
commentGenerator.addGeneralMethodComment(getIncMapMethod, introspectedTable);
getIncMapMethod.addBodyLine("return this." + FIELD_INC_MAP + ";");
FormatTools.addMethodWithBestPosition(topLevelClass, getIncMapMethod);
} }
// 增加判断方法 // 增加判断方法
Method mHasIncsForColumn = JavaElementGeneratorTools.generateMethod( Method mHasIncsForColumn = JavaElementGeneratorTools.generateMethod(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment