美文网首页mybatis解析XML
JDOM解析mybatis的XML输出sql

JDOM解析mybatis的XML输出sql

作者: 萤火之森ss | 来源:发表于2017-08-05 20:51 被阅读15次
    package com.taobao.front.util;
    
    import org.jdom.Attribute;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    
    import java.io.IOException;
    import java.util.List;
    
    /**
     * Created by Administrator on 2017/8/5.
     */
    public class JDOMtoObject {
    
        public static void main(String[] args) {
    
            //xml 的路径
            String xmlPath = "G:\\taobao\\taobao-service\\src\\main\\resources\\mapping\\GoodsMapper.xml";
    
            //创建SAX对象
            SAXBuilder saxBuilder = new SAXBuilder();
    
            try {
                Document document = saxBuilder.build(xmlPath);
                Element element = document.getRootElement();
    
                //我们先获取xml里多所有select
                List<Element> elementList =  element.getChildren("select");
    
                int len = elementList.size();//select标签的个数
                for(int i = 0 ;i< len;i++){
                    String contexty = elementList.get(i).getValue().trim();
                    if(!contexty.equals("")){
                        System.out.println(contexty +" ;");
                    }
                }
    
    
    
            } catch (JDOMException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
    
        }
    }
    

    相关文章

      网友评论

        本文标题:JDOM解析mybatis的XML输出sql

        本文链接:https://www.haomeiwen.com/subject/ycpwlxtx.html