是的,但您很可能需要创建自定义 javaClientGenerator。我不认为 enableSubPackages 属性是这样工作的。在您的配置文件中,您将拥有:
<javaClientGenerator type="com.mydomain.MyJavaMapperGenerator" targetPackage="com.aaa.${module}.domain.mapper" targetProject="src/main/java">
</javaClientGenerator>
然后您需要使用您自己的版本对现有的 JavaMapperGenerator 进行子类化。类似于下面的选项 1 或 2。鉴于选项 1 的意外复杂性,选项 2 是我可能会选择的选项。
选项 1 -使这变得困难的是映射器类型存储在私有变量中,因此您必须创建一个全新的 Interface 对象,从原始变量中复制值:
public class MyJavaMapperGenerator extends JavaMapperGenerator {
@Override
public List<CompilationUnit> getCompilationUnits() {
List<CompilationUnit> compliationUnits = super.getCompilationUnits();
List<CompilationUnit> newCompliationUnits = new ArrayList<>();
Interface mapper = (Interface)compliationUnits.get(0);
String mapperType = mapper.getType().getFullyQualifiedName();
Interface newMapper = new Interface(mapperType.replace("${module}",
introspectedTable.getFullyQualifiedTable().getDomainObjectName().toLowerCase()));
newMapper.getJavaDocLines().addAll(mapper.getJavaDocLines());
newMapper.setVisibility(mapper.getVisibility());
newMapper.setStatic(mapper.isStatic());
newMapper.setFinal(mapper.isFinal());
newMapper.getAnnotations().addAll(mapper.getAnnotations());
newMapper.addImportedTypes(mapper.getImportedTypes());
newMapper.getStaticImports().addAll(mapper.getStaticImports());
newMapper.getSuperInterfaceTypes().addAll(mapper.getSuperInterfaceTypes());
newMapper.getMethods().addAll(mapper.getMethods());
newMapper.getFileCommentLines().addAll(mapper.getFileCommentLines());
newCompliationUnits.add(newMapper);
return newCompliationUnits;
}
}
选项 2 -虽然有点乱,但我可能会从 JavaMapperGenerator 复制粘贴整个 getCompilationsUnits() 方法并修改设置类型的单行:
public class MyJavaMapperGenerator extends JavaMapperGenerator {
@Override
public List<CompilationUnit> getCompilationUnits() {
...
//FullyQualifiedJavaType type = new FullyQualifiedJavaType(
// introspectedTable.getMyBatis3JavaMapperType());
FullyQualifiedJavaType type = new FullyQualifiedJavaType(
introspectedTable.getMyBatis3JavaMapperType().replace("${module}",
introspectedTable.getFullyQualifiedTable().getDomainObjectName()
.toLowerCase()));
...
}
}