代码生成使用绝对路径,兼容IDEA和Eclipse
This commit is contained in:
parent
5e0311a602
commit
f16a0e9208
|
@ -56,7 +56,9 @@ public class MybatisGeneratorUtil {
|
|||
serviceImpl_vm = MybatisGeneratorUtil.class.getResource(serviceImpl_vm).getPath().replaceFirst("/", "");
|
||||
|
||||
String targetProject = module + "/" + module + "-dao";
|
||||
String module_path = module + "/" + module + "-dao/src/main/resources/generatorConfig.xml";
|
||||
String basePath = MybatisGeneratorUtil.class.getResource("/").getPath().replace("/target/classes/", "").replace(targetProject, "").replaceFirst("/", "");
|
||||
String generatorConfig_xml = MybatisGeneratorUtil.class.getResource("/").getPath().replace("/target/classes/", "") + "/src/main/resources/generatorConfig.xml";
|
||||
targetProject = basePath + targetProject;
|
||||
String sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '" + database + "' AND table_name LIKE '" + table_prefix + "_%';";
|
||||
|
||||
System.out.println("========== 开始生成generatorConfig.xml文件 ==========");
|
||||
|
@ -77,7 +79,7 @@ public class MybatisGeneratorUtil {
|
|||
}
|
||||
jdbcUtil.release();
|
||||
|
||||
String targetProject_sqlMap = module + "/" + module + "-rpc-service";
|
||||
String targetProject_sqlMap = basePath + module + "/" + module + "-rpc-service";
|
||||
context.put("tables", tables);
|
||||
context.put("generator_javaModelGenerator_targetPackage", package_name + ".dao.model");
|
||||
context.put("generator_sqlMapGenerator_targetPackage", package_name + ".dao.mapper");
|
||||
|
@ -86,7 +88,7 @@ public class MybatisGeneratorUtil {
|
|||
context.put("targetProject_sqlMap", targetProject_sqlMap);
|
||||
context.put("generator_jdbc_password", AESUtil.AESDecode(jdbc_password));
|
||||
context.put("last_insert_id_tables", last_insert_id_tables);
|
||||
VelocityUtil.generate(generatorConfig_vm, module_path, context);
|
||||
VelocityUtil.generate(generatorConfig_vm, generatorConfig_xml, context);
|
||||
// 删除旧代码
|
||||
deleteDir(new File(targetProject + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/dao/model"));
|
||||
deleteDir(new File(targetProject + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/dao/mapper"));
|
||||
|
@ -98,7 +100,7 @@ public class MybatisGeneratorUtil {
|
|||
|
||||
System.out.println("========== 开始运行MybatisGenerator ==========");
|
||||
List<String> warnings = new ArrayList<>();
|
||||
File configFile = new File(module_path);
|
||||
File configFile = new File(generatorConfig_xml);
|
||||
ConfigurationParser cp = new ConfigurationParser(warnings);
|
||||
Configuration config = cp.parseConfiguration(configFile);
|
||||
DefaultShellCallback callback = new DefaultShellCallback(true);
|
||||
|
@ -111,8 +113,8 @@ public class MybatisGeneratorUtil {
|
|||
|
||||
System.out.println("========== 开始生成Service ==========");
|
||||
String ctime = new SimpleDateFormat("yyyy/M/d").format(new Date());
|
||||
String servicePath = module + "/" + module + "-rpc-api" + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/rpc/api";
|
||||
String serviceImplPath = module + "/" + module + "-rpc-service" + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/rpc/service/impl";
|
||||
String servicePath = basePath + module + "/" + module + "-rpc-api" + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/rpc/api";
|
||||
String serviceImplPath = basePath + module + "/" + module + "-rpc-service" + "/src/main/java/" + package_name.replaceAll("\\.", "/") + "/rpc/service/impl";
|
||||
for (int i = 0; i < tables.size(); i++) {
|
||||
String model = StringUtil.lineToHump(ObjectUtils.toString(tables.get(i).get("table_name")));
|
||||
String service = servicePath + "/" + model + "Service.java";
|
||||
|
|
Loading…
Reference in New Issue