entity.java.ftl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package ${package.Entity};
  2. <#list importEntityFrameworkPackages as pkg>
  3. import ${pkg};
  4. </#list>
  5. <#list importEntityJavaPackages as pkg>
  6. import ${pkg};
  7. </#list>
  8. /**
  9. * <p>
  10. * ${table.comment!}
  11. * </p>
  12. *
  13. * @author ${author}
  14. * @since ${date}
  15. */
  16. <#list entityClassAnnotations as an>
  17. ${an.displayName}
  18. </#list>
  19. <#if superEntityClass??>
  20. public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
  21. <#elseif activeRecord>
  22. public class ${entity} extends Model<${entity}> {
  23. <#elseif entitySerialVersionUID>
  24. public class ${entity} implements Serializable {
  25. <#else>
  26. public class ${entity} {
  27. </#if>
  28. <#if entitySerialVersionUID>
  29. <#if entitySerialAnnotation>
  30. @Serial
  31. </#if>
  32. private static final long serialVersionUID = 1L;
  33. </#if>
  34. <#-- ---------- BEGIN 字段循环遍历 ---------->
  35. <#list table.fields as field>
  36. <#if field.keyFlag>
  37. <#assign keyPropertyName="${field.propertyName}"/>
  38. </#if>
  39. <#if field.comment!?length gt 0>
  40. <#if entityFieldUseJavaDoc>
  41. /**
  42. * ${field.comment}
  43. */
  44. </#if>
  45. </#if>
  46. <#list field.annotationAttributesList as an>
  47. ${an.displayName}
  48. </#list>
  49. private ${field.propertyType} ${field.propertyName};
  50. </#list>
  51. <#------------ END 字段循环遍历 ---------->
  52. <#if !entityLombokModel>
  53. <#list table.fields as field>
  54. <#if field.propertyType == "boolean">
  55. <#assign getprefix="is"/>
  56. <#else>
  57. <#assign getprefix="get"/>
  58. </#if>
  59. public ${field.propertyType} ${getprefix}${field.capitalName}() {
  60. return ${field.propertyName};
  61. }
  62. <#if chainModel>
  63. public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
  64. <#else>
  65. public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
  66. </#if>
  67. this.${field.propertyName} = ${field.propertyName};
  68. <#if chainModel>
  69. return this;
  70. </#if>
  71. }
  72. </#list>
  73. </#if>
  74. <#if entityColumnConstant>
  75. <#list table.fields as field>
  76. public static final String ${field.name?upper_case} = "${field.name}";
  77. </#list>
  78. </#if>
  79. <#if activeRecord>
  80. @Override
  81. public Serializable pkVal() {
  82. <#if keyPropertyName??>
  83. return this.${keyPropertyName};
  84. <#else>
  85. return null;
  86. </#if>
  87. }
  88. </#if>
  89. <#if !entityLombokModel && entityToString>
  90. @Override
  91. public String toString() {
  92. return "${entity}{" +
  93. <#list table.fields as field>
  94. <#if field_index==0>
  95. "${field.propertyName} = " + ${field.propertyName} +
  96. <#else>
  97. ", ${field.propertyName} = " + ${field.propertyName} +
  98. </#if>
  99. </#list>
  100. "}";
  101. }
  102. </#if>
  103. }