mybatis plus 实体类自定义模板
CodeGenerate.java
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
// 配置自定义输出模板
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
templateConfig.setEntity("entity.java");
entity.java.ftl,
- 自定义类注注释
- LocalDateTime类型,自动添加json序列化注解
package ${package.Entity};
import com.baomidou.mybatisplus.annotation.TableName;
<
import ${pkg};
</
<
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
</
<
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
</
/**
* All rights Reserved, Designed By
*
* Description : ${table.comment!}
* @author : ${author}
* Package : ${package.Entity}
* ClassName : ${entity}
* @date : ${date}
* Copyright : 2018 Inc. All rights reserved.
* 注意:
*/
<
@Data
<
@EqualsAndHashCode(callSuper = true)
<
@EqualsAndHashCode(callSuper = false)
</
@Accessors(chain = true)
</
@TableName("${table.name}")
<
@ApiModel(value="${entity}对象", description="${table.comment!}")
</
<
public class ${entity} extends ${superEntityClass}<
<
public class ${entity} extends Model<${entity}> {
<
public class ${entity} implements Serializable {
</
<
private static final long serialVersionUID = 1L;
</
<
<
<
<
</
<
<
@ApiModelProperty(value = "${field.comment}")
<
/**
* ${field.comment}
*/
</
</
<
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
</
<
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Constants.yyyy-MM-dd)
</
<
<
<
@TableId(value = "${field.name}", type = IdType.AUTO)
<
@TableId(value = "${field.name}", type = IdType.${idType})
<
@TableId("${field.name}")
</
<
<
<
<
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
<
@TableField(fill = FieldFill.${field.fill})
</
<
@TableField("${field.name}")
</
<
<
@Version
</
<
<
@TableLogic
</
private ${field.propertyType} ${field.propertyName};
</
<
<
<
<
<
<
<
</
public ${field.propertyType} ${getprefix}${field.capitalName}() {
return ${field.propertyName};
}
<
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
</
this.${field.propertyName} = ${field.propertyName};
<
return this;
</
}
</
</
<
<
public static final String ${field.name?upper_case} = "${field.name}";
</
</
<
@Override
protected Serializable pkVal() {
<
return this.${keyPropertyName};
<
return null;
</
}
</
<
@Override
public String toString() {
return "${entity}{" +
<
<
"${field.propertyName}=" + ${field.propertyName} +
<
", ${field.propertyName}=" + ${field.propertyName} +
</
</
"}";
}
</
}