Commit e75e36af authored by hewei's avatar hewei

bugfix[issues#10]:修正在配置autoDelimitKeywords时,由于正则获取columnName异常问题

parent 54d68e59
...@@ -206,9 +206,9 @@ public class IncrementsPlugin extends BasePlugin { ...@@ -206,9 +206,9 @@ public class IncrementsPlugin extends BasePlugin {
// 找到text节点且格式为 set xx = xx 或者 xx = xx // 找到text节点且格式为 set xx = xx 或者 xx = xx
if (ele instanceof TextElement) { if (ele instanceof TextElement) {
String text = ((TextElement) ele).getContent().trim(); String text = ((TextElement) ele).getContent().trim();
if (text.matches("(set\\s)?\\S+\\s?=.*")) { if (text.matches("(^set\\s)?\\S+\\s?=.*")) {
// 清理 set 操作 // 清理 set 操作
text = text.replaceFirst("set\\s", "").trim(); text = text.replaceFirst("^set\\s", "").trim();
String columnName = text.split("=")[0].trim(); String columnName = text.split("=")[0].trim();
IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName); IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName);
// 查找判断是否需要进行节点替换 // 查找判断是否需要进行节点替换
......
...@@ -34,6 +34,7 @@ import java.util.regex.Pattern; ...@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
* Selective 增强插件 * Selective 增强插件
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
*
* @author: hewei * @author: hewei
* @time:2017/4/20 15:39 * @time:2017/4/20 15:39
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
...@@ -61,6 +62,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -61,6 +62,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
/** /**
* Model Methods 生成 * Model Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param topLevelClass * @param topLevelClass
* @param introspectedTable * @param introspectedTable
* @return * @return
...@@ -116,6 +118,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -116,6 +118,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
/** /**
* SQL Map Methods 生成 * SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param document * @param document
* @param introspectedTable * @param introspectedTable
* @return * @return
...@@ -182,6 +185,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -182,6 +185,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
/** /**
* 替换节点if信息 * 替换节点if信息
*
* @param element * @param element
* @param prefix * @param prefix
* @param introspectedTable * @param introspectedTable
...@@ -194,7 +198,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -194,7 +198,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
whenEle.addAttribute(new Attribute("test", prefix + "isSelective()")); whenEle.addAttribute(new Attribute("test", prefix + "isSelective()"));
for (Element ele : element.getElements()) { for (Element ele : element.getElements()) {
// 对于字符串主键,是没有if判断节点的 // 对于字符串主键,是没有if判断节点的
if (ele instanceof XmlElement){ if (ele instanceof XmlElement) {
// if的text节点 // if的text节点
XmlElement xmlElement = (XmlElement) ele; XmlElement xmlElement = (XmlElement) ele;
...@@ -205,7 +209,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -205,7 +209,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
if (text.matches("#\\{.*\\},?")) { if (text.matches("#\\{.*\\},?")) {
Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?"); Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?");
Matcher matcher = pattern.matcher(text); Matcher matcher = pattern.matcher(text);
if (matcher.find()){ if (matcher.find()) {
String field = matcher.group(1); String field = matcher.group(1);
// 查找对应column // 查找对应column
for (IntrospectedColumn column : introspectedTable.getAllColumns()) { for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
...@@ -215,7 +219,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -215,7 +219,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
} }
} }
} else { } else {
if (text.matches(".*=.*")){ if (text.matches(".*=.*")) {
columnName = text.split("=")[0]; columnName = text.split("=")[0];
} else { } else {
columnName = text.replaceAll(",", ""); columnName = text.replaceAll(",", "");
...@@ -228,8 +232,8 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -228,8 +232,8 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
XmlElement ifEle = new XmlElement("if"); XmlElement ifEle = new XmlElement("if");
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + MyBatis3FormattingUtilities.getEscapedColumnName(column) + "\')")); ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + column.getActualColumnName() + "\')"));
for (Element ifChild : xmlElement.getElements()){ for (Element ifChild : xmlElement.getElements()) {
ifEle.addElement(ifChild); ifEle.addElement(ifChild);
} }
whenEle.addElement(ifEle); whenEle.addElement(ifEle);
...@@ -254,6 +258,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -254,6 +258,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
/** /**
* 替换节点upsertByExampleSelective if信息 * 替换节点upsertByExampleSelective if信息
*
* @param element * @param element
* @param prefix * @param prefix
* @param introspectedTable * @param introspectedTable
......
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