快速入门
快速入门将引导你迅速了解Util应用框架的开发流程.
前置条件
- 准备下列任意一种数据库:
- Sql Server
- PostgreSql
- MySql
- 下载Util应用框架配套生成器项目.
开发流程概述
-
创建代码生成专用数据库.
Util应用框架需要专门用来生成代码的数据库,该数据库仅用于代码生成.
约定: 代码生成数据库应以 .Generator 结尾.
当然你也可以随意起名,但使用约定名称能更清晰的说明数据库用途.
-
使用配套代码生成器生成代码.
Util配套代码生成器连接到代码生成数据库,读取元数据,创建项目基架.
快速入门示例项目概述
-
项目名称: Demo
-
代码生成数据库名称: Demo.Generator
创建示例数据库
创建快速入门示例数据库.
本节创建快速入门示例项目的代码生成数据库.
共提供三种数据库建库脚本,你只需选择一种即可.
创建 Sql Server 代码生成数据库
如果你使用Sql Server数据库,请按下面步骤创建Sql Server示例数据库和示例表.
创建 Demo.Generator 数据库
打开 SQL Server Management Studio ,新建数据库 Demo.Generator .
点击 确定 按钮,创建数据库.
添加示例表 Student
选中 Demo.Generator 数据库,点击 新建查询 按钮.
复制下面Sql语句,创建 Student 示例表.
Sql建库脚本通常使用 PowerDesigner 等数据建模工具生成.
CREATE TABLE [dbo].[Student](
[StudentId] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](200) NOT NULL,
[Gender] [int] NULL,
[Age] [int] NULL,
[Birthday] [datetime] NULL,
[IdCard] [nvarchar](50) NULL,
[Enabled] [bit] NOT NULL,
[CreationTime] [datetime] NULL,
[CreatorId] [uniqueidentifier] NULL,
[LastModificationTime] [datetime] NULL,
[LastModifierId] [uniqueidentifier] NULL,
[IsDeleted] [bit] NOT NULL,
[Version] [timestamp] NULL,
[ExtraProperties] [nvarchar](max) NULL,
CONSTRAINT [PK_STUDENT] PRIMARY KEY CLUSTERED
(
[StudentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'学生标识' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'StudentId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'姓名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Name'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'性别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Gender'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'年龄' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Age'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'出生日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Birthday'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'身份证' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'IdCard'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'启用' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Enabled'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'CreationTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人标识' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'CreatorId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'LastModificationTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改人标识' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'LastModifierId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否删除' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'IsDeleted'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'版本号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Version'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'扩展' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'ExtraProperties'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'学生' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student'
GO
点击 执行 按钮, Student 示例表创建完成.
创建 PostgreSql 代码生成数据库
如果你使用 PostgreSql 数据库,请按下面步骤创建 PostgreSql 示例数据库和示例表.
创建 Demo.Generator 数据库
打开 PostgreSql 客户端,新建数据库 Demo.Generator .
create database "Demo.Generator"
with owner admin;
添加示例表 Student
运行下面Sql之前先切换到 Demo.Generator 数据库.
create table "Student"
(
"StudentId" uuid not null
constraint "PK_Student"
primary key,
"Name" varchar(200) not null,
"Gender" integer,
"Age" integer,
"Birthday" timestamp with time zone,
"IdCard" varchar(50),
"Enabled" boolean not null,
"CreationTime" timestamp with time zone,
"CreatorId" uuid,
"LastModificationTime" timestamp with time zone,
"LastModifierId" uuid,
"IsDeleted" boolean not null,
"ExtraProperties" text,
"Version" bytea
);
comment on table "Student" is '学生';
comment on column "Student"."StudentId" is '学生标识';
comment on column "Student"."Name" is '姓名';
comment on column "Student"."Gender" is '性别';
comment on column "Student"."Age" is '年龄';
comment on column "Student"."Birthday" is '出生日期';
comment on column "Student"."IdCard" is '身份证';
comment on column "Student"."Enabled" is '启用';
comment on column "Student"."CreationTime" is '创建时间';
comment on column "Student"."CreatorId" is '创建人标识';
comment on column "Student"."LastModificationTime" is '最后修改时间';
comment on column "Student"."LastModifierId" is '最后修改人标识';
comment on column "Student"."IsDeleted" is '是否删除';
comment on column "Student"."ExtraProperties" is '扩展属性';
comment on column "Student"."Version" is '版本号';
alter table "Student"
owner to admin;
创建 MySql 代码生成数据库
如果你使用 MySql 数据库,请按下面步骤创建 MySql 示例数据库和示例表.
创建 Demo.Generator 数据库
打开 MySql 客户端,新建数据库 Demo.Generator .
create database `Demo.Generator`
添加示例表 Student
运行下面Sql之前先切换到 Demo.Generator 数据库.
create table Student
(
StudentId char(36) charset ascii not null comment '学生标识'
primary key,
Name varchar(200) not null comment '姓名',
Gender int null comment '性别',
Age int null comment '年龄',
Birthday datetime(6) null comment '出生日期',
IdCard varchar(50) null comment '身份证',
Enabled tinyint(1) not null comment '启用',
CreationTime datetime(6) null comment '创建时间',
CreatorId char(36) charset ascii null comment '创建人标识',
LastModificationTime datetime(6) null comment '最后修改时间',
LastModifierId char(36) charset ascii null comment '最后修改人标识',
IsDeleted tinyint(1) not null comment '是否删除',
ExtraProperties longtext null comment '扩展属性',
Version longblob null comment '版本号'
)
comment '学生';
Util应用框架交流群: 24791014