entity.java.vm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package $!{package.Entity};
  18. #foreach($pkg in $!{table.importPackages})
  19. import $!{pkg};
  20. #end
  21. #if($!{entityLombokModel})
  22. import lombok.Data;
  23. import lombok.EqualsAndHashCode;
  24. #end
  25. #if($!{swagger2})
  26. import io.swagger.annotations.ApiModel;
  27. import io.swagger.annotations.ApiModelProperty;
  28. #end
  29. /**
  30. * $!{table.comment}实体类
  31. *
  32. * @author $!{author}
  33. * @since $!{date}
  34. */
  35. #if($!{entityLombokModel})
  36. @Data
  37. #end
  38. #if($!{table.convert})
  39. @TableName("$!{table.name}")
  40. #end
  41. #if($!{superEntityClass})
  42. @EqualsAndHashCode(callSuper = true)
  43. #end
  44. #if($!{swagger2})
  45. @ApiModel(value = "$!{entity}对象", description = #if ("$!{table.comment}"=="")"$!{entity}对象"#else"$!{table.comment}"#end)
  46. #end
  47. #if($!{superEntityClass})
  48. public class $!{entity} extends $!{superEntityClass}#if($!{activeRecord})<$!{entity}>#end {
  49. #elseif($!{activeRecord})
  50. @Accessors(chain = true)
  51. public class $!{entity} extends Model<$!{entity}> {
  52. #else
  53. public class $!{entity} implements Serializable {
  54. #end
  55. private static final long serialVersionUID = 1L;
  56. ## ---------- BEGIN 字段循环遍历 ----------
  57. #foreach($field in $!{table.fields})
  58. #if($!{field.name}!=$!{cfg.tenantColumn})
  59. #if($!{field.keyFlag})
  60. #set($keyPropertyName=$!{field.propertyName})
  61. #end
  62. #if("$!field.comment" != "")
  63. /**
  64. * $!{field.comment}
  65. */
  66. #if($!{swagger2})
  67. @ApiModelProperty(value = "$!{field.comment}")
  68. #end
  69. #end
  70. #if($!{field.keyFlag})
  71. ## 主键
  72. #if($!{field.keyIdentityFlag})
  73. @TableId(value = "$!{field.name}", type = IdType.AUTO)
  74. #elseif(!$null.isNull($!{idType}) && "$!idType" != "")
  75. @TableId(value = "$!{field.name}", type = IdType.$!{idType})
  76. #elseif($!{field.convert})
  77. @TableId("$!{field.name}")
  78. #end
  79. ## 普通字段
  80. #elseif($!{field.fill})
  81. ## ----- 存在字段填充设置 -----
  82. #if($!{field.convert})
  83. @TableField(value = "$!{field.name}", fill = FieldFill.$!{field.fill})
  84. #else
  85. @TableField(fill = FieldFill.$!{field.fill})
  86. #end
  87. #elseif($!{field.convert})
  88. @TableField("$!{field.name}")
  89. #end
  90. ## 乐观锁注解
  91. #if($!{versionFieldName}==$!{field.name})
  92. @Version
  93. #end
  94. ## 逻辑删除注解
  95. #if($!{logicDeleteFieldName}==$!{field.name})
  96. @TableLogic
  97. #end
  98. private $!{field.propertyType} $!{field.propertyName};
  99. #end
  100. #end
  101. ## ---------- END 字段循环遍历 ----------
  102. #if(!$!{entityLombokModel})
  103. #foreach($field in $!{table.fields})
  104. #if($!{field.propertyType.equals("boolean")})
  105. #set($getprefix="is")
  106. #else
  107. #set($getprefix="get")
  108. #end
  109. public $!{field.propertyType} $!{getprefix}$!{field.capitalName}() {
  110. return $!{field.propertyName};
  111. }
  112. #if($!{entityBuilderModel})
  113. public $!{entity} set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
  114. #else
  115. public void set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
  116. #end
  117. this.$!{field.propertyName} = $!{field.propertyName};
  118. #if($!{entityBuilderModel})
  119. return this;
  120. #end
  121. }
  122. #end
  123. #end
  124. #if($!{entityColumnConstant})
  125. #foreach($field in $!{table.fields})
  126. public static final String $!{field.name.toUpperCase()} = "$!{field.name}";
  127. #end
  128. #end
  129. #if($!{activeRecord})
  130. @Override
  131. protected Serializable pkVal() {
  132. #if($!{keyPropertyName})
  133. return this.$!{keyPropertyName};
  134. #else
  135. return this.id;
  136. #end
  137. }
  138. #end
  139. #if(!$!{entityLombokModel})
  140. @Override
  141. public String toString() {
  142. return "$!{entity}{" +
  143. #foreach($field in $!{table.fields})
  144. #if($!{velocityCount}==1)
  145. "$!{field.propertyName}=" + $!{field.propertyName} +
  146. #else
  147. ", $!{field.propertyName}=" + $!{field.propertyName} +
  148. #end
  149. #end
  150. "}";
  151. }
  152. #end
  153. }