/**
* 代码生成
*/
public class AutoGenerator_ {
public static void main(String[] args) {
AutoGenerator generator = new AutoGenerator();
// 数据源
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDbType(DbType.ORACLE);
dataSourceConfig.setUrl("jdbc:oracle:thin:@10.22.13.65:1521/eflowtdb1");
dataSourceConfig.setUsername("bsdev");
dataSourceConfig.setPassword("bsdev");
dataSourceConfig.setDriverName("oracle.jdbc.driver.OracleDriver");
generator.setDataSource(dataSourceConfig);
// 全局配置
GlobalConfig config = new GlobalConfig();
config.setOutputDir("D:\\workspaces\\FMEA_7_23\\FMEA\\src\\main\\java");
config.setOpen(false);
config.setAuthor("聪哥");
config.setFileOverride(true);
config.setActiveRecord(true);
config.setEnableCache(false);// XML 二级缓存
config.setBaseResultMap(true);// XML ResultMap
config.setBaseColumnList(true);// XML columList
generator.setGlobalConfig(config);
// 配置包信息
PackageConfig packageConfig = new PackageConfig();
packageConfig.setParent("com.bs.it");
packageConfig.setModuleName("esi");
packageConfig.setMapper("dao");
packageConfig.setXml("mapper");
packageConfig.setService("service");
packageConfig.setServiceImpl("service.impl");
packageConfig.setEntity("entity");
packageConfig.setController("controller");
generator.setPackageInfo(packageConfig);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 【可无】
final int year = Calendar.getInstance().get(Calendar.YEAR);
final String createTime = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
final String version = "1.0";
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("year", year);
map.put("createTime", createTime);
map.put("version", version);
map.put("copyright", "NC");
this.setMap(map);
}
};
// 配置策列
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setNaming(NamingStrategy.underline_to_camel);
// strategyConfig.setTablePrefix(new String[]{"t_"});// 此处可以修改为您的表前缀
strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
strategyConfig.setCapitalMode(true);
// 指定要生成的表明,不指定生成全部
strategyConfig.setInclude("oht_application_info","oht_bay_eqpid_info","oht_change_info","oht_shift_resource_info");
generator.setStrategy(strategyConfig);
// 生成代码
generator.execute();
}
}