使用Enterprise Architect 将java类转换为数据库表时如何自动加入id、createTime、createBy、updateTime、updateBy等字段
使用Enterprise Architect 将java类转换为数据库表时如何自动加入id、createTime、createBy、updateTime、updateBy等字段
·
Enterprise Architect建模工具可以将UML的类转换为不同编程语言的模型,然后再根据这些模型自动生成对应的编程语言。
在将类模型转换为数据表模型时,需要在表字段中自动添加id、createTime、createBy、updateTime、updateBy等字段。
下面是完成这些操作的步骤:
1、在类模型中添加Tags变量来设置一个开关,如果为true,则生成相应的字段

2、修改类模版文件

%if classStereotype=="enumeration"%
%endTemplate%
Table
{
%TRANSFORM_REFERENCE("Table")%
%TRANSFORM_CURRENT("language", "stereotype")%
name=%qt%%CONVERT_NAME(className, "Camel Case", "Underscored")%%qt%
language=%qt%%genOptDefaultDatabase%%qt%
%if classTag:"addId" == "true"%
Column
{
name = "id"
type = "varchar(50)"
}
%endIf%
%list="Attribute" @separator="\n" @indent=" "%
%if classTag:"addCreateAndUpdte" == "true"%
Column
{
name = "create_by"
type = "varchar(32)"
}
Column
{
name = "create_time"
type = "datetime"
}
Column
{
name = "update_by"
type = "varchar(32)"
}
Column
{
name = "update_time"
type = "datetime"
}
Column
{
name = "del_flag"
type = "int(1)"
}
%endIf%
}
%list="Connector" @separator="\n"%
3、执行类模型到数据库表模型的转换

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)