Commit df7be169 authored by hewei's avatar hewei

bugfix: Selective增强插件,对于主键为字符串是没有if节点的,不需要进行isSelective()操作

parent 4d02bb9b
...@@ -232,37 +232,42 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -232,37 +232,42 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
XmlElement whenEle = new XmlElement("when"); XmlElement whenEle = new XmlElement("when");
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的text节点 // 对于字符串主键,是没有if判断节点的
XmlElement xmlElement = (XmlElement) ele; if (ele instanceof XmlElement){
TextElement textElement = (TextElement) xmlElement.getElements().get(0); // if的text节点
XmlElement xmlElement = (XmlElement) ele;
// 找出field 名称 TextElement textElement = (TextElement) xmlElement.getElements().get(0);
String text = textElement.getContent().trim();
String field = ""; // 找出field 名称
if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) { String text = textElement.getContent().trim();
Pattern pattern = Pattern.compile("(.*?)\\s*=\\s*#\\{.*},?"); String field = "";
Matcher matcher = pattern.matcher(text); if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) {
if (matcher.find()){ Pattern pattern = Pattern.compile("(.*?)\\s*=\\s*#\\{.*},?");
field = matcher.group(1); Matcher matcher = pattern.matcher(text);
} if (matcher.find()){
} else if (text.matches("#\\{.*\\},?")) { field = matcher.group(1);
Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?"); }
Matcher matcher = pattern.matcher(text); } else if (text.matches("#\\{.*\\},?")) {
if (matcher.find()){ Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?");
field = matcher.group(1); Matcher matcher = pattern.matcher(text);
if (matcher.find()){
field = matcher.group(1);
}
} else {
field = text.replaceAll(",", "");
} }
} else {
field = text.replaceAll(",", "");
}
XmlElement ifEle = new XmlElement("if"); XmlElement ifEle = new XmlElement("if");
// bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题 // bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题
field = field.replaceAll("`", "").replaceAll("\"", "").replaceAll("'", ""); field = field.replaceAll("`", "").replaceAll("\"", "").replaceAll("'", "");
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')")); ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')"));
ifEle.addElement(textElement); ifEle.addElement(textElement);
whenEle.addElement(ifEle); whenEle.addElement(ifEle);
} else {
whenEle.addElement(ele);
}
} }
// otherwise // otherwise
......
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