Commit f62d78d1 authored by hewei's avatar hewei

bugfix: Selective增强插件在对于 #{xxx,jdbcType=INTEGER},这种节点处理时之前采用正则取column名称是错误的,这里取得的其实是model的属性名称

parent 24368c58
...@@ -219,15 +219,20 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -219,15 +219,20 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
// 找出field 名称 // 找出field 名称
String text = ((TextElement) xmlElement.getElements().get(0)).getContent(); String text = ((TextElement) xmlElement.getElements().get(0)).getContent();
String field = ""; String columnName = "";
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()){
field = matcher.group(1); String field = matcher.group(1);
// 查找对应column
for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
if (column.getJavaProperty().equals(field)) {
columnName = column.getActualColumnName();
}
}
} }
} else { } else {
String columnName;
if (text.matches(".*=.*")){ if (text.matches(".*=.*")){
columnName = text.split("=")[0]; columnName = text.split("=")[0];
} else { } else {
...@@ -235,13 +240,11 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -235,13 +240,11 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
} }
// bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题 // bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题
columnName = columnName.trim().replaceAll("`", "").replaceAll("\"", "").replaceAll("'", ""); columnName = columnName.trim().replaceAll("`", "").replaceAll("\"", "").replaceAll("'", "");
IntrospectedColumn column = introspectedTable.getColumn(columnName);
field = MyBatis3FormattingUtilities.getEscapedColumnName(column);
} }
XmlElement ifEle = new XmlElement("if"); XmlElement ifEle = new XmlElement("if");
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')")); ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + MyBatis3FormattingUtilities.getEscapedColumnName(introspectedTable.getColumn(columnName)) + "\')"));
for (Element ifChild : xmlElement.getElements()){ for (Element ifChild : xmlElement.getElements()){
ifEle.addElement(ifChild); ifEle.addElement(ifChild);
} }
......
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