前言
mybatis的配置文件格式为xml,通过修改配置文件,可以控制其运行时的行为。
本节简单介绍mybatis读取xml文件的方法。
常见的xml文件读取方法
- 第三方
- JDK自带
mybatis使用的方式是JDK自带的dom
例子
test.xml
<people attr="asdf">
<name>hombio</name>
<age>18</age>
</people>
demo
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.xml"));
XPathFactory factory = XPathFactory.newInstance();
XPath xPath &