1414
1515public class MyBatisMapperXmlHandler {
1616
17- private void handleMapperElement (Document document ){
17+ private void handleMapperElement (Document document ) {
1818 Element root = document .getRootElement ();
1919 // iterate through child elements of root
2020 List <Element > elementList = root .elements ();
2121 for (Element element : elementList ) {
22- if ("resultMap" .equals (element .getName ())) {
23- // remove resultMap element
22+ if ("resultMap" .equals (element .getName ()) || "parameterMap" .equals (element .getName ())
23+ || "cache" .equals (element .getName ()) || "cache-ref" .equals (element .getName ())) {
24+ // remove resultMap,parameterMap,cache,cache-ref element
2425 root .remove (element );
2526 } else {
2627 // handle attributes
@@ -30,7 +31,7 @@ private void handleMapperElement(Document document){
3031 for (Attribute attribute : attributeList ) {
3132 // generate toRemoveAttributeList
3233 if ("parameterType" .equals (attribute .getName ()) || "resultMap" .equals (attribute .getName ())
33- || "resultType" .equals (attribute .getName ())) {
34+ || "resultType" .equals (attribute .getName ()) || "parameterMap" . equals ( attribute . getName ()) ) {
3435 toRemoveAttributeList .add (attribute );
3536 }
3637 }
@@ -41,13 +42,21 @@ private void handleMapperElement(Document document){
4142 element .remove (attribute );
4243 }
4344 }
45+ // handle selectKey child element
46+ List <Element > childElementList = element .elements ();
47+ for (Element childElement : childElementList ){
48+ if ("selectKey" .equals (childElement .getName ())) {
49+ element .remove (childElement );
50+ }
51+ }
52+
4453 }
4554 // handle TypeHandler,javaType,jdbcType,resultMap
4655 String text = element .getText ();
47- text = text .replaceAll (",[\\ s]*typeHandler=[.*A-Za-z0-9_=,]*}" ,"}" );
48- text = text .replaceAll (",[\\ s]*javaType=[.A-Za-z0-9_=,]*}" ,"}" );
49- text = text .replaceAll (",[\\ s]*jdbcType=[.A-Za-z0-9_=,]*}" ,"}" );
50- text = text .replaceAll (",[\\ s]*resultMap=[.A-Za-z0-9_=,]*}" ,"}" );
56+ text = text .replaceAll (",[\\ s]*typeHandler=[.*A-Za-z0-9_=,]*}" , "}" );
57+ text = text .replaceAll (",[\\ s]*javaType=[.A-Za-z0-9_=,]*}" , "}" );
58+ text = text .replaceAll (",[\\ s]*jdbcType=[.A-Za-z0-9_=,]*}" , "}" );
59+ text = text .replaceAll (",[\\ s]*resultMap=[.A-Za-z0-9_=,]*}" , "}" );
5160 element .setText (text );
5261 }
5362
0 commit comments