MyBatis-generator-core 生成的Dao 怎么自定义名字 (或者手动修改哪些源码可以实现)
下载 MyBatis-generator-core jar包 并解压
把解压后的 MyBatis-generator-core 下的org 拷贝到eclipse中
写一个测试类
public class test {
public static void main(String[] args){
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}
修改 IntrospectedTable.java 下的 calculateJavaClientAttributes 方法下的 【sb.append(“Mapper”);】,把他改为【sb.append(“Dao”);】
protected void calculateJavaClientAttributes() {
StringBuilder sb = new StringBuilder();
sb.append(calculateJavaClientImplementationPackage());
sb.append('.');
sb.append(fullyQualifiedTable.getDomainObjectName());
sb.append("DAOImpl"); //$NON-NLS-1$
setDAOImplementationType(sb.toString());
sb.setLength(0);
sb.append(calculateJavaClientInterfacePackage());
sb.append('.');
sb.append(fullyQualifiedTable.getDomainObjectName());
sb.append("DAO"); //$NON-NLS-1$
setDAOInterfaceType(sb.toString());
sb.setLength(0);
sb.append(calculateJavaClientInterfacePackage());
sb.append('.');
sb.append(fullyQualifiedTable.getDomainObjectName());
//sb.append("Mapper"); //$NON-NLS-1$
sb.append("Dao"); //$NON-NLS-1$
setMyBatis3JavaMapperType(sb.toString());
sb.setLength(0);
sb.append(calculateJavaClientInterfacePackage());
sb.append('.');
sb.append(fullyQualifiedTable.getDomainObjectName());
sb.append("SqlProvider"); //$NON-NLS-1$
setMyBatis3SqlProviderType(sb.toString());
}
最后直行test,运行结果如下