All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.EntityJava.ftl Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
<#-- @ftlvariable name="m" type="cn.cloudself.query.generator.TemplateModel" -->
<#assign ClassName = m._ClassName/>
<#assign className = m._ClassName?uncap_first/>
package ${m.packagePath};

<#if m.hasBigDecimal>
import java.math.BigDecimal;

<#if m.hasDate>
import java.util.Date;

<#if m.swaggerSupport>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * ${m.remark}
 */
<#if m.id??>
@Entity

<#if m.swaggerSupport>
@ApiModel(description = "${m.remark}")

@Table(name = "${m.db_name}")
public class ${ClassName} implements Serializable {
    private static final long serialVersionUID = 1L;

<#list m.enums as enum>
    public enum ${enum.name} { <#list enum.enums as en>${en}<#sep>,  }


<#list m.columns as field>
    /** ${field.remark} */
<#if m.id?? && m.id.column == field.db_name>
    @Id<#if m.id.autoIncrement>
    @GeneratedValue(strategy = GenerationType.IDENTITY)

<#if m.swaggerSupport>
    @ApiModelProperty("${field.remark}")

    @Column(name = "${field.db_name}")
<#list field.annotations as annotation>
    ${annotation}

    private ${field.javaTypeStr} ${field.propertyName};


<#list m.columns as field>
    public ${field.javaTypeStr} get<#if field.propertyName?ends_with("_column")>${field.propertyName?remove_ending("_column")?cap_first}<#else>${field.propertyName?cap_first}() {
        return ${field.propertyName};
    }

    public <#if m.chainForModel>${ClassName}<#if !m.chainForModel>void set<#if field.propertyName?ends_with("_column")>${field.propertyName?remove_ending("_column")?cap_first}<#else>${field.propertyName?cap_first}(${field.javaTypeStr} ${field.propertyName}) {
        this.${field.propertyName} = ${field.propertyName};
    <#if m.chainForModel>
        return this;
    
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ${ClassName} ${className} = (${ClassName}) o;
        return <#list m.columns as field>Objects.equals(${field.propertyName}, ${className}.${field.propertyName})<#sep> && ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(<#list m.columns as field>${field.propertyName}<#sep>, );
    }

    @Override
    public String toString() {
        return "${ClassName}{" +
            <#list m.columns as field>
                ", ${field.propertyName}=<#if field.javaTypeStr == "String">'" + ${field.propertyName} +<#if field.javaTypeStr == "String"> '\'' +
            
                '}';
    }

    <#--noinspection FtlReferencesInspection-->
    <@m.entityExCodes?interpret />
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy