123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- 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 javax.validation.constraints.Size;
- import java.time.LocalDateTime;
- import java.util.HashMap;
- import java.util.Map;
- <#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>
- *
- * @author ${author}
- * @since ${date}
- */
- <#if entityLombokModel>
- @Data
- @NoArgsConstructor
- @ToString(callSuper = true)
- <#if superEntityClass??>
- @EqualsAndHashCode(callSuper = true)
- <#else>
- @EqualsAndHashCode(callSuper = false)
- </#if>
- @Accessors(chain = 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} extends Entity<Long> {
- <#elseif activeRecord>
- @AllArgsConstructor
- public class ${entity} extends Entity<Long> {
- <#else>
- public class ${entity} extends Entity<Long> {
- </#if>
- private static final long serialVersionUID = 1L;
- @TableField(exist = false)
- private Map<String, Object> echoMap = new HashMap<>();
- <#setting number_format="0">
- <#-- ---------- BEGIN 字段循环遍历 ---------->
- <#list table.fields as field>
- <#-- 如果有父类,排除公共字段 -->
- <#if (superEntityClass?? && cfg.superExtend?? && field.propertyName !="id") || (superEntityClass?? && field.propertyName !="id" && field.propertyName !="createTime" && field.propertyName != "updateTime" && field.propertyName !="createUser" && field.propertyName !="updateUser") || !superEntityClass??>
- <#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>
- @Size(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("text")>
- <#assign max = 65535/>
- @Size(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("mediumtext")>
- <#assign max = 16777215/>
- @Size(max = ${max}, message = "${fieldComment}长度不能超过${max}")
- <#elseif field.type?starts_with("longtext")>
- </#if>
- <#else>
- <#if field.propertyType?starts_with("Short")>
- @Size(min = Short.MIN_VALUE, max = Short.MAX_VALUE, message = "${fieldComment}长度不能超过"+Short.MAX_VALUE)
- </#if>
- <#if field.propertyType?starts_with("Byte")>
- @Size(min = Byte.MIN_VALUE, max = Byte.MAX_VALUE, message = "${fieldComment}长度不能超过"+Byte.MAX_VALUE)
- </#if>
- <#if field.propertyType?starts_with("Short")>
- @Size(min = Short.MIN_VALUE, max = Short.MAX_VALUE, message = "${fieldComment}长度不能超过"+Short.MAX_VALUE)
- </#if>
- </#if>
- <#if field.keyFlag>
- <#-- 主键 -->
- @TableId(value = "${field.name}"<#if field.keyIdentityFlag>, type = IdType.AUTO<#elseif idType??>, type = IdType.${idType}</#if>)
- <#else>
- @TableField(value = "${field.name}"<#if field.fill??>, fill = FieldFill.${field.fill}</#if><#if myPropertyType == "String">, condition = LIKE<#else></#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}
- <#-- <#assign myPropertyType="${field.customMap.type}"/>-->
- <#-- <#if field.propertyName?ends_with("Id")>-->
- <#-- <#assign myPropertyName="${field.propertyName!?substring(0,field.propertyName?index_of('Id'))}"/>-->
- <#-- </#if>-->
- </#if>
- @Excel(name = "${fieldComment}"<#if myPropertyType!?contains("Local")>, format = "yyyy-MM-dd", width = 20</#if><#if myPropertyType!?contains("Boolean")>, replace = {"是_true", "否_false", "_null"}</#if><#if isEnumType=="2">, replace = {<#list field.customMap.enumCustom.list?keys as key>"${field.customMap.enumCustom.list[key][0]}_${key?upper_case}", </#list> "_null"}</#if>)
- private ${myPropertyType} ${myPropertyName};
- </#if>
- </#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>
- <#-- 如果有父类,自定义无全参构造方法 -->
- @Builder
- public ${entity}(<#list table.commonFields as cf><#if cf.propertyName!="tenantCode">${cf.propertyType} ${cf.propertyName}, </#if></#list>
- <#list table.fields as field><#assign myPropertyType="${field.propertyType}"/><#list cfg.filedTypes as fieldType><#if fieldType.name == field.propertyName && table.name==fieldType.table && field.propertyType=="String"><#assign myPropertyType="${fieldType.type}"/></#if></#list><#if field_has_next>${((field_index + 1) % 6 ==0)?string('\r\n ', '')}${myPropertyType} ${field.propertyName}, <#else>${myPropertyType} ${field.propertyName}</#if></#list>) {
- <#list table.commonFields as cf>
- <#if cf.propertyName!="tenantCode">
- this.${cf.propertyName} = ${cf.propertyName};
- </#if>
- </#list>
- <#list table.fields as field>
- <#assign myPropertyName="${field.propertyName}"/>
- <#-- 自动注入注解 -->
- <#-- <#if field.customMap.annotation?? && field.propertyName?ends_with("Id")>-->
- <#-- <#assign myPropertyName="${field.propertyName!?substring(0,field.propertyName?index_of('Id'))}"/>-->
- <#-- </#if>-->
- this.${myPropertyName} = ${field.propertyName};
- </#list>
- }
- <#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>
- }
|