Easycode是idea的一个插件,可以直接对数据的表生成entity,controller,service,dao,mapper,无需任何编码,简单而强大。
domain模板
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/domain", "Domain.java")
##使用宏定义设置包后缀
#setPackageSuffix("domain")
##使用全局变量实现默认包导入
$!autoImport
import com.fy.jpa.BasicEntity;
import lombok.Data;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
@ApiModel("$!tableInfo.comment")
@Entity
@Table(name = "$tableInfo.obj.name",schema="$tableInfo.obj.dasParent.name")
public class $!{tableInfo.name}Domain extends BasicEntity {
##生成所有字段
#foreach($column in $tableInfo.fullColumn)
##如果表字段存在标注,即生成注释
#if(${column.comment})
/**
* ${column.comment}
*/#end
##遍历包含的主键
#foreach($pkColumn in $tableInfo.pkColumn)
##如果列名是主键那么生成主键id,否则生成basic字段注解
#if($pkColumn.equals($column))
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name= "${column.obj.name}")
@ApiModelProperty("$!column.comment")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#else
@Basic
@Column(name= "${column.obj.name}")
@ApiModelProperty("$!column.comment")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#end
#end
}
生成代码示例
package com.fy.appfiling.domain;
import java.util.Date;
import com.fy.jpa.BasicEntity;
import lombok.Data;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 信息表(BpmAppFiling)实体类
*
* @author fy
* @since 2020-06-10 15:55:56
*/
@Data
@ApiModel("信息表")
@Entity
@Table(name = "bpm_app_filing",schema="ec2")
public class BpmAppFilingDomain extends BasicEntity {
/**
* id主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name= "id")
@ApiModelProperty("id主键")
private Long id;
/**
* 应用名称
*/
@Basic
@Column(name= "app_name")
@ApiModelProperty("应用名称")
private String appName;
/**
* 应用类型:1内容类,2游戏类,3工具类,4新闻类,5社交类,6金融支付类,7营业厅类
*/
@Basic
@Column(name= "app_type")
@ApiModelProperty("应用类型:1内容类,2游戏类,3工具类,4新闻类,5社交类,6金融支付类,7营业厅类")
private Integer appType;
}