diff --git a/src/main/resources/codegen/controller/vo/_column.vm b/src/main/resources/codegen/controller/vo/_column.vm new file mode 100644 index 000000000..2e2222509 --- /dev/null +++ b/src/main/resources/codegen/controller/vo/_column.vm @@ -0,0 +1,13 @@ +## 提供给 baseVO、createVO、updateVO 生成字段 + @ApiModelProperty(value = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) +#if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解 +#if (${field.fieldType} == 'String') + @NotEmpty(message = "${column.columnComment}不能为空") +#else + @NotNull(message = "${column.columnComment}不能为空") +#end +#end +#if (${column.javaType} == "Date")## 时间类型 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) +#end + private ${column.javaType} ${column.javaField}; diff --git a/src/main/resources/codegen/controller/vo/baseVO.vm b/src/main/resources/codegen/controller/vo/baseVO.vm index e0f64fc3f..324e60e8f 100644 --- a/src/main/resources/codegen/controller/vo/baseVO.vm +++ b/src/main/resources/codegen/controller/vo/baseVO.vm @@ -14,14 +14,7 @@ public class ${table.className}BaseVO { #foreach ($column in $columns) #if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult})##通用操作 - @ApiModelProperty(value = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) -#if (!${column.nullable})#if (${field.fieldType} == 'String')## 判断 @NotEmpty 和 @NotNull 注解 - @NotEmpty(message = "${column.columnComment}不能为空") -#else - @NotNull(message = "${column.columnComment}不能为空") -#end -#end - private ${column.javaType} ${column.javaField}; + #parse("codegen/controller/vo/_column.vm") #end #end diff --git a/src/main/resources/codegen/controller/vo/createReqVO.vm b/src/main/resources/codegen/controller/vo/createReqVO.vm index d59f20bbd..82c191107 100644 --- a/src/main/resources/codegen/controller/vo/createReqVO.vm +++ b/src/main/resources/codegen/controller/vo/createReqVO.vm @@ -4,6 +4,16 @@ import lombok.*; import java.util.*; import io.swagger.annotations.*; import javax.validation.constraints.*; +## 处理 Date 字段的引入 +#foreach ($column in $columns) +#if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}) + && ${column.javaType} == "Date")## 时间类型 +import org.springframework.format.annotation.DateTimeFormat; + +import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +#break +#end +#end @ApiModel("${table.classComment}创建 Request VO") @Data @@ -13,14 +23,7 @@ public class ${table.className}CreateReqVO extends ${table.className}BaseVO { #foreach ($column in $columns) #if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}))##不是通用字段 - @ApiModelProperty(value = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) -#if (!${column.nullable})#if (${field.fieldType} == 'String')## 判断 @NotEmpty 和 @NotNull 注解 - @NotEmpty(message = "${column.columnComment}不能为空") -#else - @NotNull(message = "${column.columnComment}不能为空") -#end -#end - private ${column.javaType} ${column.javaField}; + #parse("codegen/controller/vo/_column.vm") #end #end diff --git a/src/main/resources/codegen/controller/vo/pageReqVO.vm b/src/main/resources/codegen/controller/vo/pageReqVO.vm index ad585f227..1fe25b9c1 100644 --- a/src/main/resources/codegen/controller/vo/pageReqVO.vm +++ b/src/main/resources/codegen/controller/vo/pageReqVO.vm @@ -4,42 +4,39 @@ import lombok.*; import java.util.*; import io.swagger.annotations.*; import ${PageParamClassName}; -#if (${hasDateColumn}) +## 处理 Date 字段的引入 +#foreach ($column in $columns) +#if (${column.listOperation} && ${column.javaType} == "Date")## 时间类型 import org.springframework.format.annotation.DateTimeFormat; import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +#break +#end +#end +## 字段模板 +#macro(columnTpl $prefix $prefixStr) +#if (${column.javaType} == "Date")## 时间类型 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) +#end + @ApiModelProperty(value = "${prefixStr}${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end) + private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end; #end @ApiModel("${table.classComment}分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor 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 的时候 - @ApiModelProperty(value = "开始${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end) -#if (${column.javaType} == "Date")## 时间类型 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) -#end - private ${column.javaType} begin${JavaField}; + #columnTpl('begin', '开始') - @ApiModelProperty(value = "结束${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end) -#if (${column.javaType} == "Date")## 时间类型 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) -#end - private ${column.javaType} end${JavaField}; + #columnTpl('end', '结束') #else##情况二,非 Between 的时间 -#if (${column.javaType} == "Date")## 时间类型 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) -#end - @ApiModelProperty(value = "${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end) - private ${column.javaType} ${column.javaField}; +#columnTpl('', '') #end #end diff --git a/src/main/resources/codegen/controller/vo/updateReqVO.vm b/src/main/resources/codegen/controller/vo/updateReqVO.vm index 6108b4621..62acbf799 100644 --- a/src/main/resources/codegen/controller/vo/updateReqVO.vm +++ b/src/main/resources/codegen/controller/vo/updateReqVO.vm @@ -4,6 +4,16 @@ import lombok.*; import java.util.*; import io.swagger.annotations.*; import javax.validation.constraints.*; +## 处理 Date 字段的引入 +#foreach ($column in $columns) +#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult})) + && ${column.javaType} == "Date")## 时间类型 +import org.springframework.format.annotation.DateTimeFormat; + +import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +#break +#end +#end @ApiModel("${table.classComment}更新 Request VO") @Data @@ -13,8 +23,7 @@ public class ${table.className}UpdateReqVO extends ${table.className}BaseVO { #foreach ($column in $columns) #if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}))##不是通用字段 - @ApiModelProperty(value = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) - private ${column.javaType} ${column.javaField}; + #parse("codegen/controller/vo/_column.vm") #end #end diff --git a/src/main/resources/codegen/dal/mapper.vm b/src/main/resources/codegen/dal/mapper.vm index 13a3d71b2..942f17a95 100644 --- a/src/main/resources/codegen/dal/mapper.vm +++ b/src/main/resources/codegen/dal/mapper.vm @@ -6,6 +6,11 @@ import ${BaseMapperClassName}; import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; import org.apache.ibatis.annotations.Mapper; +/** +* ${table.classComment} Mapper +* +* @author ${table.author} +*/ @Mapper public interface ${table.className}Mapper extends BaseMapperX<${table.className}DO> {