Skip to content

2.解析xml中静态sql的mapper

FuriousPws002 edited this page Apr 7, 2024 · 1 revision

代码分支:02-xml-mapper-parse

先由XPathParser工具类解析xml文件为文档对象,XNode为封装解析文档中节点的工具,XMLMapperBuilder为解析mapper节点的入口,会获取到mapper节点的子节点列表,每个子节点由XMLStatementBuilder解析,解析的结果抽象为SqlSource,最终SqlSource会组装成MappedStatement添加到Configuration中。

单元测试:

public class MapperRegistryTest {

    @Test
    public void xmlParse() {
        Configuration configuration = new Configuration();
        configuration.addMapper(UserMapper.class);
        MappedStatement ms = configuration.getMappedStatement(UserMapper.class.getName() + "." + "insert");
        Assert.assertNotNull(ms);
    }
}
Clone this wiki locally