123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- package ${package.Entity};
- <#list table.importPackages as pkg>
- import ${pkg};
- </#list>
- <#if swagger2>
- import io.swagger.annotations.ApiModel;
- import io.swagger.annotations.ApiModelProperty;
- </#if>
- import javax.validation.constraints.NotEmpty;
- import javax.validation.constraints.NotNull;
- import org.hibernate.validator.constraints.Length;
- import org.hibernate.validator.constraints.Range;
- import java.time.LocalDateTime;
- <#if entityLombokModel>
- import lombok.AllArgsConstructor;
- import lombok.Builder;
- import lombok.Data;
- import lombok.EqualsAndHashCode;
- import lombok.NoArgsConstructor;
- import lombok.ToString;
- import lombok.experimental.Accessors;
- </#if>
- <#if cfg.filedTypes??>
- <#list cfg.filedTypes as fieldType>
- <#list table.fields as field>
- <#if field.propertyName == fieldType.name && table.name==fieldType.table && field.propertyType=="String">
- import ${fieldType.packagePath};
- <#break>
- </#if>
- </#list>
- </#list>
- </#if>
- import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;
- <#assign tableComment = "${table.comment!''}"/>
- <#if table.comment?? && table.comment!?contains('\n')>
- <#assign tableComment = "${table.comment!?substring(0,table.comment?index_of('\n'))?trim}"/>
- </#if>
- /**
- * <p>
- * 实体类
- * ${table.comment!?replace("\n","\n * ")}
- * </p>
- *
- * @since ${date}
- */
- <#if entityLombokModel>
- @Data
- @NoArgsConstructor
- @ToString(callSuper = true)
- </#if>
- <#if table.convert>
- @TableName("${table.name}")
- </#if>
- <#if swagger2>
- @ApiModel(value = "${entity}", description = "${tableComment}")
- </#if>
- <#if superEntityClass??>
- @AllArgsConstructor
- <#assign hasCustomAnno="0"/>
- <#if superEntityClass?? && superEntityClass=="TreeEntity">
- <#assign hasCustomAnno="1"/>
- </#if>
- public class ${entity} {
- <#elseif activeRecord>
- @AllArgsConstructor
- public class ${entity} extends Model<${entity}> {
- <#else>
- public class ${entity} implements Serializable {
- </#if>
- private static final long serialVersionUID = 1L;
- <#setting number_format="0">
- <#-- ---------- BEGIN 字段循环遍历 ---------->
- <#list table.fields as field>
- <#if field.keyFlag>
- <#assign keyPropertyName="${field.propertyName}"/>
- </#if>
- <#assign fieldComment="${field.comment!}"/>
- <#if field.comment!?length gt 0>
- /**
- * ${field.comment!?replace("\n","\n * ")}
- */
- <#if field.comment!?contains("\n") >
- <#assign fieldComment="${field.comment!?substring(0,field.comment?index_of('\n'))?replace('\r\n','')?replace('\r','')?replace('\n','')?trim}"/>
- </#if>
- </#if>
- <#if swagger2>
- @ApiModelProperty(value = "${fieldComment}")
- </#if>
- <#assign myPropertyType="${field.propertyType}"/>
- <#assign isEnumType="1"/>
- <#list cfg.filedTypes as fieldType>
- <#if fieldType.name == field.propertyName && table.name==fieldType.table && field.propertyType=="String">
- <#assign myPropertyType="${fieldType.type}"/>
- <#assign isEnumType="2"/>
- </#if>
- </#list>
- <#if field.customMap.Null == "NO" >
- <#if (field.columnType!"") == "STRING" && isEnumType == "1">
- @NotEmpty(message = "${fieldComment}不能为空")
- <#else>
- @NotNull(message = "${fieldComment}不能为空")
- </#if>
- </#if>
- <#if (field.columnType!"") == "STRING" && isEnumType == "1">
- <#assign max = 255/>
- <#if field.type?starts_with("varchar") || field.type?starts_with("char")>
- <#if field.type?contains("(")>
- <#assign max = field.type?substring(field.type?index_of("(") + 1, field.type?index_of(")"))/>
- </#if>
- @Length(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("text")>
- <#assign max = 65535/>
- @Length(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("mediumtext")>
- <#assign max = 16777215/>
- @Length(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("longtext")>
- </#if>
- <#else>
- <#if field.propertyType?starts_with("Short")>
- @Range(min = Short.MIN_VALUE, max = Short.MAX_VALUE, message = "${fieldComment}长度不能超过"+Short.MAX_VALUE)
- </#if>
- <#if field.propertyType?starts_with("Byte")>
- @Range(min = Byte.MIN_VALUE, max = Byte.MAX_VALUE, message = "${fieldComment}长度不能超过"+Byte.MAX_VALUE)
- </#if>
- <#if field.propertyType?starts_with("Short")>
- @Range(min = Short.MIN_VALUE, max = Short.MAX_VALUE, message = "${fieldComment}长度不能超过"+Short.MAX_VALUE)
- </#if>
- </#if>
- <#if field.keyFlag>
- <#-- 主键 -->
- <#if field.keyIdentityFlag>
- @TableId(value = "${field.name}", type = IdType.AUTO)
- <#elseif idType??>
- @TableId(value = "${field.name}", type = IdType.${idType})
- <#elseif field.convert>
- @TableId("${field.name}")
- </#if>
- <#-- 普通字段 -->
- <#elseif field.fill??>
- <#-- ----- 存在字段填充设置 ----->
- <#if field.convert>
- @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
- <#else>
- @TableField(fill = FieldFill.${field.fill})
- </#if>
- <#elseif field.convert>
- <#if (field.type?starts_with("varchar") || field.type?starts_with("char")) && myPropertyType == "String">
- @TableField(value = "${field.name}", condition = LIKE)
- <#else>
- @TableField("${field.name}")
- </#if>
- </#if>
- <#-- 乐观锁注解 -->
- <#if (versionFieldName!"") == field.name>
- @Version
- </#if>
- <#-- 逻辑删除注解 -->
- <#if (logicDeleteFieldName!"") == field.name>
- @TableLogic
- </#if>
- <#assign myPropertyName="${field.propertyName}"/>
- <#-- 自动注入注解 -->
- <#if field.customMap.annotation??>
- ${field.customMap.annotation}
- @ExcelEntity(name = "")
- <#assign myPropertyType="${field.customMap.type}"/>
- <#if field.propertyName?ends_with("Id")>
- <#assign myPropertyName="${field.propertyName!?substring(0,field.propertyName?index_of('Id'))}"/>
- </#if>
- </#if>
- private ${myPropertyType} ${myPropertyName};
- </#list>
- <#------------ END 字段循环遍历 ---------->
- <#if !entityLombokModel>
- <#list table.fields as field>
- <#if field.propertyType == "boolean">
- <#assign getprefix="is"/>
- <#else>
- <#assign getprefix="get"/>
- </#if>
- public ${field.propertyType} ${getprefix}${field.capitalName}() {
- return ${field.propertyName};
- }
- <#if entityBuilderModel>
- public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
- <#else>
- public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
- </#if>
- this.${field.propertyName} = ${field.propertyName};
- <#if entityBuilderModel>
- return this;
- </#if>
- }
- </#list>
- </#if>
- <#if activeRecord>
- @Override
- protected Serializable pkVal() {
- <#if keyPropertyName??>
- return this.${keyPropertyName};
- <#else>
- return null;
- </#if>
- }
- </#if>
- <#if !entityLombokModel>
- @Override
- public String toString() {
- return "${entity}{" +
- <#list table.fields as field>
- <#if field_index==0>
- "${field.propertyName}=" + ${field.propertyName} +
- <#else>
- ", ${field.propertyName}=" + ${field.propertyName} +
- </#if>
- </#list>
- "}";
- }
- </#if>
- }
|