JDOM解析mybatis的XML输出sql

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 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)