From e75e36af588cd1f9e5a2d762fe13733e86ce3a5c Mon Sep 17 00:00:00 2001 From: hewei Date: Fri, 4 Aug 2017 23:46:33 +0800 Subject: [PATCH] =?UTF-8?q?bugfix[issues#10]:=E4=BF=AE=E6=AD=A3=E5=9C=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AEautoDelimitKeywords=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E6=AD=A3=E5=88=99=E8=8E=B7=E5=8F=96columnNam?= =?UTF-8?q?e=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/plugins/IncrementsPlugin.java | 4 ++-- .../plugins/SelectiveEnhancedPlugin.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java b/src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java index 4a0499f..38c5b25 100644 --- a/src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java +++ b/src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java @@ -206,9 +206,9 @@ public class IncrementsPlugin extends BasePlugin { // 找到text节点且格式为 set xx = xx 或者 xx = xx if (ele instanceof TextElement) { String text = ((TextElement) ele).getContent().trim(); - if (text.matches("(set\\s)?\\S+\\s?=.*")) { + if (text.matches("(^set\\s)?\\S+\\s?=.*")) { // 清理 set 操作 - text = text.replaceFirst("set\\s", "").trim(); + text = text.replaceFirst("^set\\s", "").trim(); String columnName = text.split("=")[0].trim(); IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName); // 查找判断是否需要进行节点替换 diff --git a/src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java b/src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java index 3f5a10a..b3ca7ae 100644 --- a/src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java +++ b/src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java @@ -34,6 +34,7 @@ import java.util.regex.Pattern; * --------------------------------------------------------------------------- * Selective 增强插件 * --------------------------------------------------------------------------- + * * @author: hewei * @time:2017/4/20 15:39 * --------------------------------------------------------------------------- @@ -61,6 +62,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { /** * Model Methods 生成 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html + * * @param topLevelClass * @param introspectedTable * @return @@ -116,6 +118,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { /** * SQL Map Methods 生成 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html + * * @param document * @param introspectedTable * @return @@ -182,6 +185,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { /** * 替换节点if信息 + * * @param element * @param prefix * @param introspectedTable @@ -194,7 +198,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { whenEle.addAttribute(new Attribute("test", prefix + "isSelective()")); for (Element ele : element.getElements()) { // 对于字符串主键,是没有if判断节点的 - if (ele instanceof XmlElement){ + if (ele instanceof XmlElement) { // if的text节点 XmlElement xmlElement = (XmlElement) ele; @@ -205,7 +209,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { if (text.matches("#\\{.*\\},?")) { Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?"); Matcher matcher = pattern.matcher(text); - if (matcher.find()){ + if (matcher.find()) { String field = matcher.group(1); // 查找对应column for (IntrospectedColumn column : introspectedTable.getAllColumns()) { @@ -215,7 +219,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { } } } else { - if (text.matches(".*=.*")){ + if (text.matches(".*=.*")) { columnName = text.split("=")[0]; } else { columnName = text.replaceAll(",", ""); @@ -228,8 +232,8 @@ public class SelectiveEnhancedPlugin extends BasePlugin { XmlElement ifEle = new XmlElement("if"); - ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + MyBatis3FormattingUtilities.getEscapedColumnName(column) + "\')")); - for (Element ifChild : xmlElement.getElements()){ + ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + column.getActualColumnName() + "\')")); + for (Element ifChild : xmlElement.getElements()) { ifEle.addElement(ifChild); } whenEle.addElement(ifEle); @@ -254,6 +258,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { /** * 替换节点upsertByExampleSelective if信息 + * * @param element * @param prefix * @param introspectedTable