entity.java.btl 2.9 KB

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