diff --git a/renren-cloud-generator/src/main/java/io/renren/utils/GenUtils.java b/renren-cloud-generator/src/main/java/io/renren/utils/GenUtils.java index b88282d63..46141b46f 100644 --- a/renren-cloud-generator/src/main/java/io/renren/utils/GenUtils.java +++ b/renren-cloud-generator/src/main/java/io/renren/utils/GenUtils.java @@ -37,7 +37,7 @@ import java.util.zip.ZipOutputStream; /** * 代码生成器 工具类 - * + * * @author chenshun * @email sunlightcs@gmail.com */ @@ -58,7 +58,7 @@ public class GenUtils { templates.add("template/add-or-update.vue.vm"); return templates; } - + /** * 生成代码 */ @@ -75,7 +75,7 @@ public class GenUtils { String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix")); tableEntity.setClassName(className); tableEntity.setClassname(StringUtils.uncapitalize(className)); - + //列信息 List columsList = new ArrayList<>(); for(Map column : columns){ @@ -84,12 +84,12 @@ public class GenUtils { columnEntity.setDataType(column.get("dataType")); columnEntity.setComments(column.get("columnComment")); columnEntity.setExtra(column.get("extra")); - + //列名转换成Java属性名 String attrName = columnToJava(columnEntity.getColumnName()); columnEntity.setAttrName(attrName); columnEntity.setAttrname(StringUtils.uncapitalize(attrName)); - + //列的数据类型,转换成Java类型 String attrType = config.getString(columnEntity.getDataType(), "unknowType"); columnEntity.setAttrType(attrType); @@ -100,24 +100,24 @@ public class GenUtils { if("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null){ tableEntity.setPk(columnEntity); } - + columsList.add(columnEntity); } tableEntity.setColumns(columsList); - + //没主键,则第一个字段为主键 if(tableEntity.getPk() == null){ tableEntity.setPk(tableEntity.getColumns().get(0)); } - + //设置velocity资源加载器 - Properties prop = new Properties(); - prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + Properties prop = new Properties(); + prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.init(prop); String main = config.getString("main" ); main = StringUtils.isBlank(main) ? config.getString("package" ) : main; - + //封装模板数据 Map map = new HashMap<>(); map.put("tableName", tableEntity.getTableName()); @@ -129,14 +129,7 @@ public class GenUtils { map.put("columns", tableEntity.getColumns()); map.put("hasBigDecimal", hasBigDecimal); map.put("main", main); - - String moduleName = config.getString("moduleName" ); - if(StringUtils.isNotBlank(moduleName)){ - map.put("package", config.getString("package" ) + "." + moduleName); - }else { - map.put("package", config.getString("package" )); - } - + map.put("package", config.getString("package" )); map.put("moduleName", config.getString("moduleName" )); map.put("author", config.getString("author")); map.put("version", config.getString("version")); @@ -146,7 +139,7 @@ public class GenUtils { VelocityContext context = new VelocityContext(map); - + //获取模板列表 List templates = getTemplates(); for(String template : templates){ @@ -154,7 +147,7 @@ public class GenUtils { StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, "UTF-8"); tpl.merge(context, sw); - + try { //添加到zip zip.putNextEntry(new ZipEntry(getFileName(template, tableEntity.getClassName(), config.getString("package"), config.getString("moduleName")))); @@ -166,15 +159,15 @@ public class GenUtils { } } } - - + + /** * 列名转换成Java属性名 */ public static String columnToJava(String columnName) { return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", ""); } - + /** * 表名转换成Java类名 */ @@ -184,7 +177,7 @@ public class GenUtils { } return columnToJava(tableName); } - + /** * 获取配置信息 */ @@ -202,7 +195,7 @@ public class GenUtils { public static String getFileName(String template, String className, String packageName, String moduleName) { String packagePath = "main" + File.separator + "java" + File.separator; if (StringUtils.isNotBlank(packageName)) { - packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator; + packagePath += packageName.replace(".", File.separator) + File.separator; } if (template.contains("Entity.java.vm" )) { @@ -234,7 +227,7 @@ public class GenUtils { } if (template.contains("DTO.java.vm" )) { - return moduleName + File.separator + "dto" + File.separator + className + "DTO.java"; + return "dto" + File.separator + className + "DTO.java"; } if (template.contains("Dao.xml.vm" )) {