@Override
public void addMappedStatement(MappedStatement ms) {
// …
}
// … 省略若干行
/**
* 使用自己的 MybatisMapperRegistry
*/
@Override
public void addMapper(Class type) {
mybatisMapperRegistry.addMapper(type);
}
// … 省略若干行
}
在MybatisMapperRegistry中,MP将mybatis的MapperAnnotationBuilder替换为MP自己的MybatisMapperAnnotationBuilder
public class MybatisMapperRegistry extends MapperRegistry {
@Override
public void addMapper(Class type) {
// … 省略若干行
MybatisMapperAnnotationBuilder parser = new MybatisMapperAnnotationBuilder(config, type);
parser.parse();
// … 省略若干行
}
}
在MybatisMapperRegistry类的addMapper方法中,真正进入到MP的核心类MybatisMapperAnnotationBuilder,MybatisMapperAnnotationBuilder这个类是MP实现动态脚本的关键类。
MybatisMapperAnnotationBuilder动态构造
在MP的核心类MybatisMapperAnnotationBuilder的parser方法中,MP逐一遍历要加载的Mapper类,加载的方法包括下面几个
public class MybatisMapperAnnotationBuilder extends MapperAnnotationBuilder {
@Override
public void parse() {
//… 省略若干行
fo