From a38931a637bd5248473ec572c44e4345c7c5f12e Mon Sep 17 00:00:00 2001 From: rainerosion Date: Fri, 13 Jan 2023 18:51:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/rainss/codegenerator/DDDGenerator.java | 13 - .../rainss/codegenerator/utils/DataType.java | 49 +++ .../codegenerator/utils/GeneratorUtil.java | 363 ++++++++---------- .../resources/template/applicationService.ftl | 0 src/main/resources/template/controller.ftl | 0 src/main/resources/template/domainService.ftl | 0 src/main/resources/template/entity.ftl | 20 +- src/main/resources/template/mapper.ftl | 10 +- src/main/resources/template/mapper.xml.ftl | 2 +- src/main/resources/template/po.ftl | 20 +- src/main/resources/template/repository.ftl | 0 src/main/resources/template/reqDto.ftl | 20 +- src/main/resources/template/resDto.ftl | 20 +- 13 files changed, 279 insertions(+), 238 deletions(-) create mode 100644 src/main/java/cn/rainss/codegenerator/utils/DataType.java create mode 100644 src/main/resources/template/applicationService.ftl create mode 100644 src/main/resources/template/controller.ftl create mode 100644 src/main/resources/template/domainService.ftl create mode 100644 src/main/resources/template/repository.ftl diff --git a/src/main/java/cn/rainss/codegenerator/DDDGenerator.java b/src/main/java/cn/rainss/codegenerator/DDDGenerator.java index 16fdedb..f06ca88 100644 --- a/src/main/java/cn/rainss/codegenerator/DDDGenerator.java +++ b/src/main/java/cn/rainss/codegenerator/DDDGenerator.java @@ -1,25 +1,12 @@ package cn.rainss.codegenerator; -import cn.rainss.codegenerator.utils.Column; -import cn.rainss.codegenerator.utils.DatabaseUtil; -import cn.rainss.codegenerator.utils.GenerateConfig; import cn.rainss.codegenerator.utils.GeneratorUtil; -import org.yaml.snakeyaml.Yaml; -import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.sql.SQLException; -import java.util.List; public class DDDGenerator { public static void main(String[] args) throws SQLException, FileNotFoundException, ClassNotFoundException { GeneratorUtil.Generator(); - // GeneratorUtil.package2Path(DatabaseUtil.getInstance().getConfig().getGenerate().packageName); - // List timemail = DatabaseUtil.getInstance().getTable(); - // List tm_user = DatabaseUtil.getInstance().getColumn("tm_content"); - // Yaml yaml = new Yaml(); - // InputStream resourceAsStream = DDDGenerator.class.getClass().getClassLoader().getResourceAsStream("config.yaml"); - // GenerateConfig generate = yaml.loadAs(new FileInputStream(new File("src/main/resources/config.yaml")),GenerateConfig.class); } } diff --git a/src/main/java/cn/rainss/codegenerator/utils/DataType.java b/src/main/java/cn/rainss/codegenerator/utils/DataType.java new file mode 100644 index 0000000..bccf1c9 --- /dev/null +++ b/src/main/java/cn/rainss/codegenerator/utils/DataType.java @@ -0,0 +1,49 @@ +package cn.rainss.codegenerator.utils; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +import java.sql.SQLException; + +@Getter +@AllArgsConstructor +public enum DataType { + BIT("bit", "Boolean"), + BOOL("bool", "Boolean"), + CHAR("char", "String"), + DATE("date", "LocalDate"), + DECIMAL("decimal", "BigDecimal"), + FLOAT4("float4", "Float"), + FLOAT8("float8", "Double"), + INT2("int2", "Short"), + INT4("int4", "Integer"), + INT8("int8", "Long"), + MONEY("money", "Double"), + NUMERIC("numeric", "BigDecimal"), + TEXT("text", "String"), + TIME("time", "LocalTime"), + TIMESTAMP("timestamp", "LocalDateTime"), + UUID("uuid", "String"), + VARCHAR("varchar", "String"); + + private final String sqlType; + private final String javaType; + + //private final String package + + /** + * 根据sql数据类型获取java数据类型 + * @param sqlType + * @return + */ + public static DataType find(String sqlType){ + for (DataType type : DataType.values()) { + if (StringUtils.equals(type.getSqlType(), sqlType)){ + return type; + } + } + return null; + } +} diff --git a/src/main/java/cn/rainss/codegenerator/utils/GeneratorUtil.java b/src/main/java/cn/rainss/codegenerator/utils/GeneratorUtil.java index 60caab1..57a97bc 100644 --- a/src/main/java/cn/rainss/codegenerator/utils/GeneratorUtil.java +++ b/src/main/java/cn/rainss/codegenerator/utils/GeneratorUtil.java @@ -1,20 +1,24 @@ package cn.rainss.codegenerator.utils; - import cn.rainss.codegenerator.config.Config; -import freemarker.core.ParseException; -import freemarker.template.*; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.utility.CollectionUtils; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Type; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; /** * 工具类 @@ -22,58 +26,8 @@ import java.util.Objects; * @author echo */ public class GeneratorUtil { - // 类型映射 - private final static Map SQL_TYPE_TO_JAVA_TYPE = new HashMap<>(); - // 文件后缀 - private static String SUFFIX = ".java"; - private final static Config CONFIG = DatabaseUtil.getInstance().getConfig().getGenerate(); - static { - SQL_TYPE_TO_JAVA_TYPE.put("bit", "Boolean"); - SQL_TYPE_TO_JAVA_TYPE.put("bool", "Boolean"); - // SQL_TYPE_TO_JAVA_TYPE.put("box",""); - // SQL_TYPE_TO_JAVA_TYPE.put("bytea",""); - SQL_TYPE_TO_JAVA_TYPE.put("char", "String"); - // SQL_TYPE_TO_JAVA_TYPE.put("cidr",""); - // SQL_TYPE_TO_JAVA_TYPE.put("circle",""); - SQL_TYPE_TO_JAVA_TYPE.put("date", "LocalDate"); - SQL_TYPE_TO_JAVA_TYPE.put("decimal", "BigDecimal"); - SQL_TYPE_TO_JAVA_TYPE.put("float4", "Float"); - SQL_TYPE_TO_JAVA_TYPE.put("float8", "Double"); - // SQL_TYPE_TO_JAVA_TYPE.put("inet",""); - SQL_TYPE_TO_JAVA_TYPE.put("int2", "Short"); - SQL_TYPE_TO_JAVA_TYPE.put("int4", "Integer"); - SQL_TYPE_TO_JAVA_TYPE.put("int8", "Long"); - // SQL_TYPE_TO_JAVA_TYPE.put("interval",""); - // SQL_TYPE_TO_JAVA_TYPE.put("json",""); - // SQL_TYPE_TO_JAVA_TYPE.put("jsonb",""); - // SQL_TYPE_TO_JAVA_TYPE.put("line",""); - // SQL_TYPE_TO_JAVA_TYPE.put("lseg",""); - // SQL_TYPE_TO_JAVA_TYPE.put("macaddr",""); - SQL_TYPE_TO_JAVA_TYPE.put("money", "Double"); - SQL_TYPE_TO_JAVA_TYPE.put("numeric", "BigDecimal"); - // SQL_TYPE_TO_JAVA_TYPE.put("path",""); - // SQL_TYPE_TO_JAVA_TYPE.put("point",""); - // SQL_TYPE_TO_JAVA_TYPE.put("polygon",""); - // SQL_TYPE_TO_JAVA_TYPE.put("serial2",""); - // SQL_TYPE_TO_JAVA_TYPE.put("serial4",""); - // SQL_TYPE_TO_JAVA_TYPE.put("serial8",""); - SQL_TYPE_TO_JAVA_TYPE.put("text", "String"); - SQL_TYPE_TO_JAVA_TYPE.put("time", "LocalTime"); - SQL_TYPE_TO_JAVA_TYPE.put("timestamp", "LocalDateTime"); - // SQL_TYPE_TO_JAVA_TYPE.put("timestamptz",""); - // SQL_TYPE_TO_JAVA_TYPE.put("timetz",""); - // SQL_TYPE_TO_JAVA_TYPE.put("tsquery",""); - // SQL_TYPE_TO_JAVA_TYPE.put("tsvector",""); - // SQL_TYPE_TO_JAVA_TYPE.put("txid_snapshot",""); - SQL_TYPE_TO_JAVA_TYPE.put("uuid", "String"); - // SQL_TYPE_TO_JAVA_TYPE.put("varbit",""); - SQL_TYPE_TO_JAVA_TYPE.put("varchar", "String"); - // SQL_TYPE_TO_JAVA_TYPE.put("xml",""); - - } - public static String toLowerCase(String str) { if (StringUtils.isNotEmpty(str)) { @@ -154,7 +108,7 @@ public class GeneratorUtil { DatabaseUtil instance = DatabaseUtil.getInstance(); List table = instance.getTable(); table.forEach(t -> { - System.out.println("<<<<< table: " + t + " >>>>>"); + System.out.printf("<<<<< Generate code from table: %s >>>>>%n", t); try { List column = instance.getColumn(t); generatorCode(column, t); @@ -172,22 +126,17 @@ public class GeneratorUtil { * @return */ public static String getJavaType(String key) { - return SQL_TYPE_TO_JAVA_TYPE.getOrDefault(key, "Object"); + DataType type = DataType.find(key); + return type == null ? "Object" : type.getJavaType(); } /** - * 生成实体 + * 生成所有类型的代码 */ public static void generatorCode(List list, String tableName) { -// generatorByTemplate(list,tableName,"po"); -// generatorByTemplate(list,tableName,"entity"); -// generatorByTemplate(list,tableName,"resDto"); -// generatorByTemplate(list,tableName,"reqDto"); -// generatorByTemplate(list,tableName,"repository"); -// generatorByTemplate(list,tableName,"service"); -// generatorByTemplate(null,tableName,"mapper"); - generatorByTemplate(null, tableName, "mapper.xml"); - // generatorByTemplate(list,tableName,"controller"); + for (TypeEnum typeEnum : TypeEnum.values()) { + generatorByTemplate(list, tableName, typeEnum); + } } @@ -201,153 +150,130 @@ public class GeneratorUtil { public static void generatorByTemplate(List columnList, String table, TypeEnum type) { // 文件模板路径 String templatePath = String.format("src/main/resources/template/%s.ftl", type.getTemplate()); - String destPath = null; - String projectName = CONFIG.getProjectName(); + String basePackage = CONFIG.getBasePackage(); // 去除前缀 String className = formatTableName(table); // 转换为大驼峰式命名 className = toUpperCaseFist(toCamelCase(className)); - String baseMapperXml = "%s-%s/src/main/resources/mapper/%s%s.xml"; - String baseClassFile = "%s-%s/src/main/java/%s/%s/%s%s.java"; + // 模板参数设置 + TableModelInfo tableInfo = TableModelInfo.builder() + .packages(basePackage) + .columns(columnList) + .configuration(CONFIG) + .className(className) + .tableName(table) + .build(); + setTableInfo(columnList, tableInfo); + String destPath = getDestFilePath(className, type); + if (StringUtils.isEmpty(destPath)) { + return; + } + try { + // 提取文件夹路径 + String dir = destPath.substring(0, destPath.lastIndexOf("/")); + File folder = new File(dir); + File file = new File(destPath); + if (!folder.exists()) { + // 创建目录 + folder.mkdirs(); + } + if (!file.exists()) { + // 创建不存在的文件 + file.createNewFile(); + } + System.out.println(String.format("模板文件路径:%s 目标文件路径:%s", templatePath, destPath)); + Configuration freemarker = new Configuration(Configuration.VERSION_2_3_0); + Template template = freemarker.getTemplate(templatePath); + template.process(tableInfo, new FileWriter(file)); + + } catch (IOException | TemplateException e) { + System.out.println("文件操作失败!"); + e.printStackTrace(); + throw new RuntimeException(e); + } + //System.out.println(String.format("模板文件路径:%s 目标文件路径:%s", templatePath, destPath)); + } + + private static void setTableInfo(List columnList, TableModelInfo tableInfo) { + tableInfo.setHasBigDecimal(Boolean.FALSE); + tableInfo.setHasLocalDate(Boolean.FALSE); + tableInfo.setHasLocalTime(Boolean.FALSE); + tableInfo.setHasLocalDateTime(Boolean.FALSE); + if (columnList == null || columnList.size() == 0) { + return; + } + for (Column column : columnList) { + String javaType = column.getJavaType(); + if (DataType.DECIMAL.getJavaType().equals(javaType)) { + tableInfo.setHasBigDecimal(Boolean.TRUE); + } else if (DataType.TIMESTAMP.getSqlType().equals(javaType)) { + tableInfo.setHasLocalDateTime(Boolean.TRUE); + } else if (DataType.DATE.getJavaType().equals(javaType)) { + tableInfo.setHasLocalDate(Boolean.TRUE); + } else if (DataType.TIME.getJavaType().equals(javaType)) { + tableInfo.setHasLocalTime(Boolean.TRUE); + } + } + } + + /** + * 获取文件输出路径 + * + * @param className 类名 + * @param type 类型枚举 + * @return + */ + private static String getDestFilePath(String className, TypeEnum type) { + if (TypeEnum.MAPPER_XML.equals(type)) { + return String.format("%s-%s/src/main/resources/mapper/%s%s.xml", + CONFIG.getProjectName(), + type.getModule(), + className, + toUpperCaseFist(type.getTemplate()) + ); + } + String packageLocation = ""; switch (type) { - case MAPPER_XML: - destPath = String.format(baseMapperXml, projectName, type.getModule(), className, toUpperCaseFist(type.getTemplate())); + case CONTROLLER: + packageLocation = CONFIG.getPackageLocation().getController(); + break; + case PO: + packageLocation = CONFIG.getPackageLocation().getPo(); + break; + case DOMAIN_SERVICE: + //packageLocation = CONFIG.getPackageLocation() + break; + case APPLICATION_SERVICE: + //packageLocation = CONFIG.getPackageLocation() + break; + case MAPPER: + packageLocation = CONFIG.getPackageLocation().getMapper(); + break; + case REPOSITORY: + packageLocation = CONFIG.getPackageLocation().getRepository(); + break; + case ENTITY: + packageLocation = CONFIG.getPackageLocation().getEntity(); break; case RES_DTO: - destPath = String.format(baseClassFile, projectName, type.getModule(), - package2Path(CONFIG.getPackageName()), - package2Path(CONFIG.getPackageLocation().getResDto()), - className, toUpperCaseFist(type.getTemplate())); - + packageLocation = CONFIG.getPackageLocation().getResDto(); + break; case REQ_DTO: - destPath = String.format(baseClassFile, projectName, type.getModule(), package2Path(CONFIG.getPackageName()), package2Path(CONFIG.getPackageLocation().getReqDto())); - + packageLocation = CONFIG.getPackageLocation().getReqDto(); + break; default: - destPath = String.format(baseClassFile, projectName, type.getModule(), package2Path(CONFIG.getPackageName()), package2Path("")); + System.out.println("没有匹配的类型"); } - + return String.format("%s-%s/src/main/java/%s/%s/%s%s.java", + CONFIG.getProjectName(), type.getModule(), + package2Path(CONFIG.getBasePackage()), + package2Path(packageLocation), + className, toUpperCaseFist(type.getTemplate()) + ); } /** - * create template file - * - * @param type 类型 po entity dto mapper service repository controller - */ - public static void generatorByTemplate(List list, String tableName, String type) { - String templatePath = String.format("src/main/resources/template/%s.ftl", toLowerCase(type)); - String moduleName; - String secondaryPackage = null; - - String className = tableName; - // data - Map data = new HashMap<>(); - // add base data - data.put("mapper_package", CONFIG.getMapperPackage()); - data.put("entity_package", CONFIG.getEntityPackage()); - data.put("po_package", CONFIG.getPoPackage()); - data.put("service_package", CONFIG.getServicePackage()); - data.put("repository_package", CONFIG.getRepositoryPackage()); - data.put("res_dto_package", CONFIG.getResDtoPackage()); - data.put("req_dto_package", CONFIG.getReqDtoPackage()); - data.put("controller_package", CONFIG.getControllerpackage()); - data.put("package", CONFIG.getPackageName()); - data.put("author", CONFIG.getAuthor()); - // 如果有前缀去除 - if (StringUtils.isNotEmpty(CONFIG.getTablePrefix())) { - className = formatTableName(tableName); - } - // 转换为大驼峰式命名 - className = toUpperCaseFist(toCamelCase(className)); - switch (type) { - case "po": - secondaryPackage = CONFIG.getPoPackage(); - moduleName = "server"; - break; - case "service": - secondaryPackage = CONFIG.getServicePackage(); - moduleName = "server"; - break; - case "mapper": - secondaryPackage = CONFIG.getMapperPackage(); - moduleName = "server"; - break; - case "mapper.xml": - //todo detal - SUFFIX = ".xml"; - moduleName = "server"; - break; - case "repository": - secondaryPackage = CONFIG.getRepositoryPackage(); - moduleName = "server"; - break; - case "entity": - secondaryPackage = CONFIG.getMapperPackage(); - moduleName = "server"; - break; - case "resDto": - secondaryPackage = CONFIG.getResDtoPackage(); - moduleName = "dto"; - break; - case "reqDto": - secondaryPackage = CONFIG.getReqDtoPackage(); - moduleName = "dto"; - break; - case "controller": - secondaryPackage = CONFIG.getControllerpackage(); - moduleName = "facade"; - break; - default: - System.out.println("=== 没有匹配的类型 ==="); - return; - } - String dir = ""; - String filePath = ""; - // mapper.xml file deal - if (Objects.equals(type, "mapper.xml")) { - dir = String.format("%s-%s/src/main/resources/mapper/", CONFIG.getProjectName(), moduleName); - filePath = dir + className + toUpperCaseFist(type) + SUFFIX; - } else { - dir = String.format("%s-%s/src/main/java/%s/%s/", CONFIG.getProjectName(), moduleName, package2Path(CONFIG.getPackageName()), package2Path(secondaryPackage)); - filePath = dir + className + toUpperCaseFist(type) + SUFFIX; - } - - File file = new File(filePath); - try { - // 文件夹不存在创建 - if (!new File(dir).exists()) { - if (new File(dir).mkdirs()) { - // System.out.println("PO 文件夹创建成功"); - } - //创建文件 - if (!file.exists()) { - new File(filePath).createNewFile(); - System.out.println("=== " + type + ":[" + className + " ] 创建成功 ==="); - } - - } - Configuration configuration = new Configuration(Configuration.VERSION_2_3_0); - Template template = configuration.getTemplate(templatePath); - data.put("table_name", tableName); - data.put("class_name", className); - data.put("columns", list); - template.process(data, new FileWriter(file)); - } catch (TemplateNotFoundException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } catch (MalformedTemplateNameException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (TemplateException e) { - e.printStackTrace(); - } - - } - - - /** - * 首字母大写 + * 首字母大写并去除扩展名 * * @param str * @return @@ -385,8 +311,39 @@ public class GeneratorUtil { return packageName.replace(".", "/"); } - public static String formatTableName(String str) { - //todo 待优化 - return str.replaceFirst(CONFIG.getTablePrefix(), ""); + /** + * 表名前缀处理 + * + * @param table 表名 + * @return + */ + public static String formatTableName(String table) { + if (StringUtils.isNotEmpty(CONFIG.getTablePrefix())) { + return table.replaceFirst(CONFIG.getTablePrefix(), ""); + } + return table; + } + + @Getter + @Setter + @Builder + public static class TableModelInfo { + private Boolean hasLocalDate; + + private Boolean hasLocalTime; + + private Boolean hasLocalDateTime; + + private Boolean hasBigDecimal; + + private String packages; + + private List columns; + + private Config configuration; + + private String className; + + private String tableName; } } diff --git a/src/main/resources/template/applicationService.ftl b/src/main/resources/template/applicationService.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/template/controller.ftl b/src/main/resources/template/controller.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/template/domainService.ftl b/src/main/resources/template/domainService.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/template/entity.ftl b/src/main/resources/template/entity.ftl index 8637847..a1abfc2 100644 --- a/src/main/resources/template/entity.ftl +++ b/src/main/resources/template/entity.ftl @@ -1,4 +1,4 @@ -package ${package}.${entity_package}; +package ${packages}.${configuration.packageLocation.entity}; import lombok.AllArgsConstructor; import lombok.Builder; @@ -6,18 +6,30 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +<#if hasBigDecimal> +import java.math.BigDecimal; + +<#if hasLocalDate> +import java.time.LocalDate; + +<#if hasLocalTime> +import java.time.LocalTime; + +<#if hasLocalDateTime> + import java.time.LocalDateTime; + /** -* ${table_name} +* ${tableName} * entity -* @author ${author} +* @author ${configuration.author} * @date ${.now?datetime} */ @Data @AllArgsConstructor @NoArgsConstructor @Builder -public class ${class_name} implements Serializable { +public class ${className} implements Serializable { <#list columns as column> /** diff --git a/src/main/resources/template/mapper.ftl b/src/main/resources/template/mapper.ftl index 31f6935..96e8c73 100644 --- a/src/main/resources/template/mapper.ftl +++ b/src/main/resources/template/mapper.ftl @@ -1,16 +1,16 @@ -package ${package}.${po_package}; +package ${packages}.${configuration.packageLocation.mapper}; -import ${package}.${po_package}.${class_name}; +import ${packages}.${configuration.packageLocation.mapper}.${className}; import com.baomidou.mybatisplus.core.mapper.BaseMapper; /** *

-* Mapper 接口 +* ${className}Mapper 接口 *

* -* @author ${author} +* @author ${configuration.author} * @since 2021-04-19 */ -public interface ${class_name}Mapper extends BaseMapper<${class_name}> { +public interface ${className}Mapper extends BaseMapper<${className}> { } \ No newline at end of file diff --git a/src/main/resources/template/mapper.xml.ftl b/src/main/resources/template/mapper.xml.ftl index e6a2dd7..2d585de 100644 --- a/src/main/resources/template/mapper.xml.ftl +++ b/src/main/resources/template/mapper.xml.ftl @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/src/main/resources/template/po.ftl b/src/main/resources/template/po.ftl index 78cf16b..e046764 100644 --- a/src/main/resources/template/po.ftl +++ b/src/main/resources/template/po.ftl @@ -1,4 +1,4 @@ -package ${package}.${po_package}; +package ${packages}.${configuration.packageLocation.po}; import lombok.AllArgsConstructor; import lombok.Builder; @@ -6,18 +6,30 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +<#if hasBigDecimal> + import java.math.BigDecimal; + +<#if hasLocalDate> + import java.time.LocalDate; + +<#if hasLocalTime> + import java.time.LocalTime; + +<#if hasLocalDateTime> + import java.time.LocalDateTime; + /** -* ${table_name} +* ${tableName} * po -* @author ${author} +* @author ${configuration.author} * @date ${.now?datetime} */ @Data @AllArgsConstructor @NoArgsConstructor @Builder -public class ${class_name} implements Serializable { +public class ${className} implements Serializable { <#list columns as column> /** diff --git a/src/main/resources/template/repository.ftl b/src/main/resources/template/repository.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/template/reqDto.ftl b/src/main/resources/template/reqDto.ftl index 28ae722..e05b93e 100644 --- a/src/main/resources/template/reqDto.ftl +++ b/src/main/resources/template/reqDto.ftl @@ -1,4 +1,4 @@ -package ${package}; +package ${packages}; import lombok.AllArgsConstructor; import lombok.Builder; @@ -6,18 +6,30 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +<#if hasBigDecimal> + import java.math.BigDecimal; + +<#if hasLocalDate> + import java.time.LocalDate; + +<#if hasLocalTime> + import java.time.LocalTime; + +<#if hasLocalDateTime> + import java.time.LocalDateTime; + /** -* ${table_name} +* ${tableName} * entity -* @author ${author} +* @author ${configuration.author} * @date ${.now?datetime} */ @Data @AllArgsConstructor @NoArgsConstructor @Builder -public class ${class_name} implements Serializable { +public class ${className} implements Serializable { <#list columns as column> /** diff --git a/src/main/resources/template/resDto.ftl b/src/main/resources/template/resDto.ftl index 28ae722..e05b93e 100644 --- a/src/main/resources/template/resDto.ftl +++ b/src/main/resources/template/resDto.ftl @@ -1,4 +1,4 @@ -package ${package}; +package ${packages}; import lombok.AllArgsConstructor; import lombok.Builder; @@ -6,18 +6,30 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +<#if hasBigDecimal> + import java.math.BigDecimal; + +<#if hasLocalDate> + import java.time.LocalDate; + +<#if hasLocalTime> + import java.time.LocalTime; + +<#if hasLocalDateTime> + import java.time.LocalDateTime; + /** -* ${table_name} +* ${tableName} * entity -* @author ${author} +* @author ${configuration.author} * @date ${.now?datetime} */ @Data @AllArgsConstructor @NoArgsConstructor @Builder -public class ${class_name} implements Serializable { +public class ${className} implements Serializable { <#list columns as column> /**