Skip to content

Commit

Permalink
handle more element and format
Browse files Browse the repository at this point in the history
  • Loading branch information
donhui committed Sep 19, 2019
1 parent d728f6d commit 7470e10
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

public class MyBatisMapperXmlHandler {

private void handleMapperElement(Document document){
private void handleMapperElement(Document document) {
Element root = document.getRootElement();
// iterate through child elements of root
List<Element> elementList = root.elements();
for (Element element : elementList) {
if ("resultMap".equals(element.getName())) {
// remove resultMap element
if ("resultMap".equals(element.getName()) || "parameterMap".equals(element.getName())
|| "cache".equals(element.getName()) || "cache-ref".equals(element.getName())) {
// remove resultMap,parameterMap,cache,cache-ref element
root.remove(element);
} else {
// handle attributes
Expand All @@ -30,7 +31,7 @@ private void handleMapperElement(Document document){
for (Attribute attribute : attributeList) {
// generate toRemoveAttributeList
if ("parameterType".equals(attribute.getName()) || "resultMap".equals(attribute.getName())
|| "resultType".equals(attribute.getName())) {
|| "resultType".equals(attribute.getName()) || "parameterMap".equals(attribute.getName())) {
toRemoveAttributeList.add(attribute);
}
}
Expand All @@ -41,13 +42,21 @@ private void handleMapperElement(Document document){
element.remove(attribute);
}
}
// handle selectKey child element
List<Element> childElementList = element.elements();
for(Element childElement : childElementList){
if("selectKey".equals(childElement.getName())) {
element.remove(childElement);
}
}

}
// handle TypeHandler,javaType,jdbcType,resultMap
String text = element.getText();
text = text.replaceAll(",[\\s]*typeHandler=[.*A-Za-z0-9_=,]*}","}");
text = text.replaceAll(",[\\s]*javaType=[.A-Za-z0-9_=,]*}","}");
text = text.replaceAll(",[\\s]*jdbcType=[.A-Za-z0-9_=,]*}","}");
text = text.replaceAll(",[\\s]*resultMap=[.A-Za-z0-9_=,]*}","}");
text = text.replaceAll(",[\\s]*typeHandler=[.*A-Za-z0-9_=,]*}", "}");
text = text.replaceAll(",[\\s]*javaType=[.A-Za-z0-9_=,]*}", "}");
text = text.replaceAll(",[\\s]*jdbcType=[.A-Za-z0-9_=,]*}", "}");
text = text.replaceAll(",[\\s]*resultMap=[.A-Za-z0-9_=,]*}", "}");
element.setText(text);
}

Expand Down

0 comments on commit 7470e10

Please sign in to comment.