【SSH项目实战】国税协同平台-22.逆向工程

上一次我们利用PowerDesigner设计了一个“人员组织架构”的概念模型和物理模型,并把它们生成了建表语句,并且在数据库创建了相应表。接下来我们要利用“逆向工程”来创建表和实体类。因为是测试,所以我们所有的代码均在test包下完成。首先,我们在我们工程的test.conf包下创建database.sql文件,把上一次我们得到的sql语句输入进去:/*==============================================================*//* DBMS name:MySQL 5.0*//* Created on:2015/11/14 7:39:35*//*==============================================================*/drop table if exists emp_role;drop table if exists role_pri;drop table if exists t_dept;drop table if exists t_emp;drop table if exists t_leader;drop table if exists t_org;drop table if exists t_privilege;drop table if exists t_role;/*==============================================================*//* Table: emp_role*//*==============================================================*/create table emp_role( emp_idvarchar(32) not null, role_idvarchar(32) not null, stateint, primary key (emp_id, role_id));/*==============================================================*//* Table: role_pri*//*==============================================================*/create table role_pri( role_idvarchar(32) not null, pin_idvarchar(32) not null, primary key (role_id, pin_id));/*==============================================================*//* Table: t_dept*//*==============================================================*/create table t_dept( dept_idvarchar(32) not null, org_idvarchar(32) not null, namevarchar(50), primary key (dept_id));/*==============================================================*//* Table: t_emp*//*==============================================================*/create table t_emp( emp_idvarchar(32) not null, dept_idvarchar(32), namevarchar(50) not null, primary key (emp_id));/*==============================================================*//* Table: t_leader*//*==============================================================*/create table t_leader( emp_idvarchar(32) not null, dept_idvarchar(32), namevarchar(50) not null, positionint, primary key (emp_id));/*==============================================================*//* Table: t_org*//*==============================================================*/create table t_org( org_idvarchar(32) not null, namevarchar(50), primary key (org_id));/*==============================================================*//* Table: t_privilege*//*==============================================================*/create table t_privilege( pin_idvarchar(32) not null, namevarchar(50), primary key (pin_id));/*==============================================================*//* Table: t_role*//*==============================================================*/create table t_role( role_idvarchar(32) not null, namevarchar(50), primary key (role_id));alter table emp_role add constraint FK_emp_role foreign key (emp_id)references t_emp (emp_id) on delete restrict on update restrict;alter table emp_role add constraint FK_emp_role2 foreign key (role_id)references t_role (role_id) on delete restrict on update restrict;alter table role_pri add constraint FK_belong foreign key (role_id)references t_role (role_id) on delete restrict on update restrict;alter table role_pri add constraint FK_own foreign key (pin_id)references t_privilege (pin_id) on delete restrict on update restrict;alter table t_dept add constraint FK_org_dept foreign key (org_id)references t_org (org_id) on delete restrict on update restrict;alter table t_emp add constraint FK_dept_emp foreign key (dept_id)references t_dept (dept_id) on delete restrict on update restrict;alter table t_leader add constraint FK_extends foreign key (emp_id)references t_emp (emp_id) on delete restrict on update restrict;然后我们为了方便看数据库,我们在MyEclipse中来引入数据库。首先点击Windows—>show view,在视窗上面搜索db Bower视图,然后成功创建视图,然后在新属兔上右键点击,在出现的菜单中选择“New”:

之后进行如下操作:

此时成功将数据库引入MyEclipse:

我们执行一下sql语句,和之前我们在Sqlyog图形界面管理工具中一样,我们成功创建了数据库表:

数据库表创建以后,我们正式进入我们的逆向工程实现。我们使用逆向工程之前,首先要告诉我们的编译器,我们使用了hibernate框架(因为我们是手动配置的),这样逆向工程才会去主动使用我们的hibernate规则。具体做法, 首先点击这里(高版本的是在Project Facets中):

然后我们在出现的对话框中选取如下操作:

我知道按攻略去旅行的人往往玩得过于按步就班,

【SSH项目实战】国税协同平台-22.逆向工程

相关文章:

你感兴趣的文章:

标签云: