Commit 24368c58 authored by hewei's avatar hewei

新增增量插件

parent a4980ab0
......@@ -40,17 +40,6 @@ public class ModelBuilderPlugin extends BasePlugin {
public static final String BUILDER_CLASS_NAME = "Builder"; // Builder 类名
private FullyQualifiedJavaType inc; // 是否支持Increments
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param introspectedTable
* @return
*/
@Override
public void initialized(IntrospectedTable introspectedTable) {
this.inc = null;
}
/**
* Model Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
......@@ -153,8 +142,28 @@ public class ModelBuilderPlugin extends BasePlugin {
InnerEnum eIncrements = new InnerEnum(new FullyQualifiedJavaType("Inc"));
eIncrements.setVisibility(JavaVisibility.PUBLIC);
eIncrements.setStatic(true);
eIncrements.addEnumConstant("INC,DEC");
eIncrements.addEnumConstant("INC(\"+\")");
eIncrements.addEnumConstant("DEC(\"-\")");
commentGenerator.addEnumComment(eIncrements, introspectedTable);
// 生成属性和构造函数
Field fValue = new Field("value", FullyQualifiedJavaType.getStringInstance());
fValue.setVisibility(JavaVisibility.PRIVATE);
fValue.setFinal(true);
commentGenerator.addFieldComment(fValue, introspectedTable);
eIncrements.addField(fValue);
Method mInc = new Method("Inc");
mInc.setConstructor(true);
mInc.addBodyLine("this.value = value;");
mInc.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "value"));
commentGenerator.addGeneralMethodComment(mInc, introspectedTable);
eIncrements.addMethod(mInc);
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加构造方法和column属性。");
Method mValue = JavaElementGeneratorTools.generateGetterMethod(fValue);
commentGenerator.addGeneralMethodComment(mValue, introspectedTable);
eIncrements.addMethod(mValue);
innerClass.addInnerEnum(eIncrements);
// 增加field
Field fIncrements = JavaElementGeneratorTools.generateField(
......@@ -208,5 +217,4 @@ public class ModelBuilderPlugin extends BasePlugin {
return innerClass;
}
}
......@@ -228,7 +228,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
}
} else {
String columnName;
if (text.matches(".*\\s*=.*")){
if (text.matches(".*=.*")){
columnName = text.split("=")[0];
} else {
columnName = text.replaceAll(",", "");
......
......@@ -25,6 +25,7 @@ import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
import org.mybatis.generator.config.GeneratedKey;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
......@@ -377,4 +378,25 @@ public class XmlElementGeneratorTools {
return eleTrim;
}
/**
* 查找指定xml节点下指定节点名称的元素
*
* @param xmlElement
* @param name
* @return
*/
public static List<XmlElement> findXmlElements(XmlElement xmlElement, String name){
List<XmlElement> list = new ArrayList<>();
List<Element> elements = xmlElement.getElements();
for (Element ele : elements) {
if (ele instanceof XmlElement) {
XmlElement xmlElement1 = (XmlElement) ele;
if (name.equalsIgnoreCase(xmlElement1.getName())) {
list.add(xmlElement1);
}
}
}
return list;
}
}
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