From fade9bce329a8c6130de2e49443eb78ed1624d23 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Feb 2021 10:09:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=8E=B0=E6=9C=89=20vo?= =?UTF-8?q?=E3=80=81do=E3=80=81mapper=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/service/codegen/impl/ToolCodegenEngine.java | 9 +++++++-- .../resources/codegen/controller/vo/pageReqVO.vm | 12 ++++++++---- src/main/resources/codegen/dal/do.vm | 2 +- src/main/resources/codegen/dal/mapper.vm | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java index 9d7043f52..5ce35f877 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java @@ -10,8 +10,10 @@ import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO; +import cn.iocoder.dashboard.util.date.DateUtils; import org.springframework.stereotype.Component; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,9 +51,10 @@ public class ToolCodegenEngine { // 全局配置 globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包 // 全局 Java Bean - globalBindingMap.put("pageResultClassName", PageResult.class.getName()); + globalBindingMap.put("PageResultClassName", PageResult.class.getName()); + globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName()); // VO 类,独有字段 - globalBindingMap.put("pageParamClassName", PageParam.class.getName()); + globalBindingMap.put("PageParamClassName", PageParam.class.getName()); // DO 类,独有字段 globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); globalBindingMap.put("baseDOClassName", BaseDO.class.getName()); @@ -64,6 +67,8 @@ public class ToolCodegenEngine { Map bindingMap = new HashMap<>(); bindingMap.put("table", table); bindingMap.put("columns", columns); + bindingMap.put("hasDateColumn", columns.stream().anyMatch(codegenColumnDO -> + codegenColumnDO.getJavaType().equals(Date.class.getSimpleName()))); bindingMap.putAll(globalBindingMap); // 执行生成 // String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); diff --git a/src/main/resources/codegen/controller/vo/pageReqVO.vm b/src/main/resources/codegen/controller/vo/pageReqVO.vm index 30f08be44..ad585f227 100644 --- a/src/main/resources/codegen/controller/vo/pageReqVO.vm +++ b/src/main/resources/codegen/controller/vo/pageReqVO.vm @@ -2,9 +2,13 @@ package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; import lombok.*; import java.util.*; -import javax.validation.constraints.*; import io.swagger.annotations.*; -import ${pageParamClassName}; +import ${PageParamClassName}; +#if (${hasDateColumn}) +import org.springframework.format.annotation.DateTimeFormat; + +import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +#end @ApiModel("${table.classComment}分页 Request VO") @Data @@ -18,7 +22,7 @@ public class ${table.className}PageReqVO extends PageParam { #foreach ($column in $columns) #set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写 #if (${column.listOperation})##查询操作 -#if (${column.listOperationCondition} == "BETWEEN")## Between 的时候 +#if (${column.listOperationCondition} == "BETWEEN")## 情况一,Between 的时候 @ApiModelProperty(value = "开始${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end) #if (${column.javaType} == "Date")## 时间类型 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @@ -30,7 +34,7 @@ public class ${table.className}PageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) #end private ${column.javaType} end${JavaField}; -#else +#else##情况二,非 Between 的时间 #if (${column.javaType} == "Date")## 时间类型 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) #end diff --git a/src/main/resources/codegen/dal/do.vm b/src/main/resources/codegen/dal/do.vm index 6fd37b13c..70c8cc02c 100644 --- a/src/main/resources/codegen/dal/do.vm +++ b/src/main/resources/codegen/dal/do.vm @@ -3,7 +3,7 @@ package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.business import lombok.*; import java.util.*; import com.baomidou.mybatisplus.annotation.*; -import ${baseDOClassName}; +import ${BaseDOClassName}; /** * ${table.classComment} DO diff --git a/src/main/resources/codegen/dal/mapper.vm b/src/main/resources/codegen/dal/mapper.vm index 949e7dcb0..13a3d71b2 100644 --- a/src/main/resources/codegen/dal/mapper.vm +++ b/src/main/resources/codegen/dal/mapper.vm @@ -1,6 +1,6 @@ package ${basePackage}.${table.moduleName}.dal.mysql.dao.${table.businessName}; -import ${pageResultClassName}; +import ${PageResultClassName}; import ${QueryWrapperClassName}; import ${BaseMapperClassName}; import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;