From 526c3867b412698f8ab08f2568a81e95010b462b Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 21 四月 2020 17:13:02 +0800 Subject: [PATCH] 代码生成Date字段添加默认格式 --- ruoyi/src/main/resources/vm/java/domain.java.vm | 7 ++++--- ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java | 1 + ruoyi/src/main/resources/vm/vue/index.vue.vm | 2 +- ruoyi/src/main/resources/vm/vue/index-tree.vue.vm | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java index 3b5b02c..f3e38a8 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java +++ b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java @@ -196,6 +196,7 @@ if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { importList.add("java.util.Date"); + importList.add("com.fasterxml.jackson.annotation.JsonFormat"); } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { diff --git a/ruoyi/src/main/resources/vm/java/domain.java.vm b/ruoyi/src/main/resources/vm/java/domain.java.vm index e99ef2c..c943c1b 100644 --- a/ruoyi/src/main/resources/vm/java/domain.java.vm +++ b/ruoyi/src/main/resources/vm/java/domain.java.vm @@ -1,5 +1,8 @@ package ${packageName}.domain; +#foreach ($import in $importList) +import ${import}; +#end import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.framework.aspectj.lang.annotation.Excel; @@ -7,9 +10,6 @@ import com.ruoyi.framework.web.domain.BaseEntity; #elseif($table.tree) import com.ruoyi.framework.web.domain.TreeEntity; -#end -#foreach ($import in $importList) -import ${import}; #end /** @@ -40,6 +40,7 @@ #if($parentheseIndex != -1) @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") #elseif($column.javaType == 'Date') + @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") #else @Excel(name = "${comment}") diff --git a/ruoyi/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi/src/main/resources/vm/vue/index-tree.vue.vm index 0cbdd3b..a578e89 100644 --- a/ruoyi/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi/src/main/resources/vm/vue/index-tree.vue.vm @@ -88,7 +88,7 @@ #elseif($column.list && $column.htmlType == "datetime") <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> <template slot-scope="scope"> - <span>{{ parseTime(scope.row.${javaField}) }}</span> + <span>{{ parseTime(scope.row.${javaField}), '{y}-{m}-{d}') }}</span> </template> </el-table-column> #elseif($column.list && "" != $column.dictType) diff --git a/ruoyi/src/main/resources/vm/vue/index.vue.vm b/ruoyi/src/main/resources/vm/vue/index.vue.vm index 8d89857..12022ca 100644 --- a/ruoyi/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi/src/main/resources/vm/vue/index.vue.vm @@ -112,7 +112,7 @@ #elseif($column.list && $column.htmlType == "datetime") <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> <template slot-scope="scope"> - <span>{{ parseTime(scope.row.${javaField}) }}</span> + <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span> </template> </el-table-column> #elseif($column.list && "" != $column.dictType) -- Gitblit v1.9.2