tablego生成entity

第一步:配置数据源

 

 第二步:选择数据源

 

 第三步:新建entity模板,在TableGo的ftl目录下新建模板目录,例如“新模板”,将模板拷贝到该目录,新模板内容如下:

  1 package ${jsonParam.packagePath};
  2 <#-- 用于生成JavaBean的自定义模板 -->
  3 /******************************************************************
  4 ** 类    名:${tableInfo.upperCamelCase}
  5 ** 描    述:${tableInfo.remark}
  6 ** 创 建 者:${paramConfig.author}
  7 ** 创建时间:${today} ${currentTime}
  8 ******************************************************************/
  9 <#-- 初始化文件合并增量更新需要的参数 -->
 10 <#if paramConfig.fileUpdateMode == 0 || paramConfig.fileUpdateMode == 1>
 11     <#assign String = staticModels["java.lang.String"]>
 12 </#if>
 13 <#assign importDate = false />
 14 <#assign importBigDecimal = false />
 15 <#list tableInfo.fieldInfos as fieldInfo>
 16     <#if !importDate && fieldInfo.javaType == "Date">
 17         <#assign importDate = true />
 18     <#elseif !importBigDecimal && fieldInfo.javaType == "BigDecimal">
 19         <#assign importBigDecimal = true />
 20     </#if>
 21 </#list>
 22 import javax.persistence.Entity;
 23 import javax.persistence.Id;
 24 import lombok.Data;
 25 import org.apache.commons.lang3.builder.EqualsBuilder;
 26 import org.apache.commons.lang3.builder.HashCodeBuilder;
 27 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 28 import io.swagger.annotations.ApiModel;
 29 import io.swagger.annotations.ApiModelProperty;
 30 import com.shieh.entity.base.BaseEntity;
 31 <#if importDate>
 32 import java.util.Date;
 33 import com.fasterxml.jackson.annotation.JsonFormat;
 34 </#if>
 35 <#if importBigDecimal>
 36 import java.math.BigDecimal;
 37 </#if>
 38 <#assign importNotBlank = false />
 39 <#assign importNotNull = false />
 40 <#if tableInfo.fieldInfos?? && tableInfo.fieldInfos?size gt 0>
 41     <#list tableInfo.fieldInfos as fieldInfo>
 42     <#if !fieldInfo.primaryKey && fieldInfo.isNotNull>
 43         <#if !importNotBlank && fieldInfo.javaType == "String">
 44             <#assign importNotBlank = true />
 45 import javax.validation.constraints.NotBlank;
 46         <#elseif !importNotNull && fieldInfo.javaType != "String">
 47             <#assign importNotNull = true />
 48 import javax.validation.constraints.NotNull;
 49         </#if>
 50     </#if>
 51     </#list>
 52 </#if>
 53 import javax.validation.constraints.Size;
 54 
 55 @Data
 56 @ApiModel(value = "${tableInfo.tableName}")
 57 @Entity(name = "${tableInfo.tableName}")
 58 public class ${tableInfo.upperCamelCase} extends BaseEntity {
 59     /** 版本号 */
 60     private static final long serialVersionUID = ${tableInfo.serialVersionUID!'1'}L;
 61 <#if tableInfo.fieldInfos?? && tableInfo.fieldInfos?size gt 0>
 62     <#if paramConfig.fileUpdateMode == 0 || paramConfig.fileUpdateMode == 1>
 63 
 64     /* ${String.format("${paramConfig.mergeFileMarkBegin}", 1)} */
 65     </#if>
 66     <#list tableInfo.fieldInfos as fieldInfo>
 67 
 68 <#if paramConfig.buildFieldRemark == 0>
 69     /** <#if fieldInfo.remark?? && fieldInfo.remark?trim != "">${fieldInfo.remark}<#else>${fieldInfo.proName}</#if> */
 70 </#if>
 71     <#if fieldInfo.primaryKey>
 72     @Id
 73     </#if>
 74     <#if fieldInfo.javaType == "Date">
 75     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 76     </#if>
 77     <#if !fieldInfo.primaryKey && fieldInfo.isNotNull>
 78         <#if fieldInfo.javaType == "String">
 79     @NotBlank(message = "${fieldInfo.simpleRemark!fieldInfo.proName}不能为空!")
 80         <#else>
 81     @NotNull(message = "${fieldInfo.simpleRemark!fieldInfo.proName}不能为空!")
 82         </#if>
 83     </#if>
 84     <#if fieldInfo.javaType == "String">
 85     @Size(min = 0, max = ${fieldInfo.length}, message = "${fieldInfo.remark}长度不能超过${fieldInfo.length}个字符")
 86     </#if>
 87     @ApiModelProperty(name = "${fieldInfo.proName}",value = "${fieldInfo.simpleRemark}")
 88     private ${fieldInfo.javaType} ${fieldInfo.proName};
 89     </#list>
 90 
 91 </#if>
 92 
 93     @Override
 94     public boolean equals(Object obj) {
 95         return EqualsBuilder.reflectionEquals(obj, this);
 96     }
 97     
 98     @Override
 99     public int hashCode() {
100         return HashCodeBuilder.reflectionHashCode(this);
101     }
102     
103     @Override
104     public String toString() {
105         return ReflectionToStringBuilder.toString(this);
106     }
107 
108 }

第四步:生成自定义文件

 

 

 

 

 

posted @ 2020-10-25 19:43  疯狗强尼  阅读(481)  评论(0编辑  收藏  举报