When I use the following configuration to map Dao interfaces, it will recursively look for all interfaces by default, but there are many interfaces that I don't want.
<configuration>
<mappers>
<package name="org.apache.ibatis"/>
</mappers>
</configuration>
Therefore, I want a supplementary attribute to filter unnecessary classes or just add my desired classes. As shown below, I want to get the interface type I want by adding the baseClass attribute to the package element。
<mappers>
<package name="org.apache.ibatis" baseClass="org.apache.ibatis.dao.BaseDao"/>
</mappers>
XMLConfigBuilder.mapperElement changes are as follows。
if ("package".equals(child.getName())) {
String mapperPackage = child.getStringAttribute("name");
String baseClass = child.getStringAttribute("baseClass"); // TODO add baseClass attr resolve.
Class<?> baseClazz=null;
if(baseClass!=null) {
try{
baseClazz = Resources.classForName(baseClass);
}catch (Throwable e) {
// ignore exception
}
}
if(baseClazz!=null)
configuration.addMappers(mapperPackage,baseClazz); // TODO Use this method to resolve
else
configuration.addMappers(mapperPackage);
}