因为这里只是个简单的Demo,所以设计上就简单点了。
大概的想法就是一个通讯录跟博客,当然是非常简单的那种。
一共有4张表。
用户表,联系人表,联系人类别表,博客表。
简单介绍下
每个用户都有个人通讯录,通讯录下添加联系人,联系人可以分类。
用户还可以写Blog,其他用户可以查看你公开的Blog。
当然这个基础上,可以加入例如好友,收藏,评论等等功能,这个根据后面的情况,如果能反映某个技术难点的话,再添加上去。
简述下这个过程:
新建一个数据库
打开PowerDesigner,新建一个PDM(Physical Data Model),其实就是表设计
使用Palette上控件,完成数据库设计
设计结果
直接生成SQL文
在数据库中执行SQL文
如果你也是使用Navicat执行SQL文的话,这里要注意一点,生成的SQL文开头部分,有删除索引的语句,在第一次执行时,要先删掉这段,否则会报错,无法建立表。
执行成功后,可以看到表建立好了
生成的SQL文如下:
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2011-2-20 23:25:35 */
/*==============================================================*/
drop index titleIndex on t_blog;
drop index modifyTimeIndex on t_blog;
drop table if exists t_blog;
drop index emailIndex on t_contact;
drop index cellphoneIndex on t_contact;
drop index userNameIndex on t_contact;
drop table if exists t_contact;
drop index userTypeIndex on t_contact_type;
drop table if exists t_contact_type;
drop table if exists t_user;
/*==============================================================*/
/* Table: t_blog */
/*==============================================================*/
create table t_blog
(
id int not null auto_increment comment '唯一主键',
userId int comment '用户id',
title varchar(100) comment '标题',
content varchar(1000) comment '内容',
isPublic varchar(4) comment '是否公开(1.私有 2.公开)',
createTime timestamp comment '创建时间',
modifyTime timestamp comment '修改时间',
primary key (id)
);
alter table t_blog comment '博客表';
/*==============================================================*/
/* Index: modifyTimeIndex */
/*==============================================================*/
create index modifyTimeIndex on t_blog
(
modifyTime
);
/*==============================================================*/
/* Index: titleIndex */
/*==============================================================*/
create index titleIndex on t_blog
(
title
);
/*==============================================================*/
/* Table: t_contact */
/*==============================================================*/
create table t_contact
(
id int not null auto_increment comment '唯一主键',
userId int comment '用户id',
contactTypeId int comment '联系人类别Id',
contactName varchar(50) comment '联系人名',
sex varchar(10) comment '性别',
birthday date comment '生日',
telephone varchar(20) comment '电话',
mobilephone varchar(20) comment '手机',
qq varchar(20) comment 'QQ号',
msn varchar(20) comment 'MSN号',
email varchar(50) comment '电子邮件',
address varchar(50) comment '家庭住址',
remark varchar(100) comment '备注',
primary key (id)
);
alter table t_contact comment '联系人表';
/*==============================================================*/
/* Index: userNameIndex */
/*==============================================================*/
create index userNameIndex on t_contact
(
contactName
);
/*==============================================================*/
/* Index: cellphoneIndex */
/*==============================================================*/
create index cellphoneIndex on t_contact
(
mobilephone
);
/*==============================================================*/
/* Index: emailIndex */
/*==============================================================*/
create index emailIndex on t_contact
(
email
);
/*==============================================================*/
/* Table: t_contact_type */
/*==============================================================*/
create table t_contact_type
(
id int not null auto_increment comment '唯一主键',
userId int comment '用户id',
typeName varchar(20) comment '类别名称',
primary key (id)
);
alter table t_contact_type comment '联系人类别表';
/*==============================================================*/
/* Index: userTypeIndex */
/*==============================================================*/
create unique index userTypeIndex on t_contact_type
(
typeName
);
/*==============================================================*/
/* Table: t_user */
/*==============================================================*/
create table t_user
(
id int not null auto_increment comment '唯一主键',
userName varchar(30) comment '用户名',
password varchar(20) comment '密码',
userType varchar(10) comment '用户类型(1.管理员 2.普通用户)',
primary key (id)
);
alter table t_user comment '用户表';
alter table t_blog add constraint FK_Reference_4 foreign key (userId)
references t_user (id) on delete restrict on update restrict;
alter table t_contact add constraint FK_Reference_1 foreign key (contactTypeId)
references t_contact_type (id) on delete restrict on update restrict;
alter table t_contact add constraint FK_Reference_2 foreign key (userId)
references t_user (id) on delete restrict on update restrict;
alter table t_contact_type add constraint FK_Reference_3 foreign key (userId)
references t_user (id) on delete restrict on update restrict;
以上操作,其中关于Powerdesigner的使用问题,可以参照另一篇Blog(http://pangwu86.iteye.com/blog/910647),这里不再重复。
下一集,将开始讲述后台代码的Dao这层的编写。
分享到:
相关推荐
NULL 博文链接:https://pangwu86.iteye.com/blog/911090
dao层使用nutz,view层使用beetl,数据源使用阿里的druid
企业级应用,高可扩展性,模块低耦合,可删改,附详细文档协助开发。适合有一定基础的同学练习。
每次项目验收写文档是一个很凌乱的事情,作为一个程序员,应该是用技术解决问题。当然有很多工具也可以实现。比如PDman就可以导出word或者pdf文档。 这个案例主要是学习springboot...以及使用nutz poi第三方工具的使用
NULL 博文链接:https://senhui19.iteye.com/blog/1344393
利用easyui整理的一套cms管理系统, easyui、nutz、c3po、 mysql、tomcat7、jdk1.7、eclipse4.5
nutz应用示例,mysql/jdk1.6 数据库文件在src/config中。
NULL 博文链接:https://pangwu86.iteye.com/blog/1076177
可以自动生成数据库脚本,生成代码项目,数据库文档生成
SpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架介绍.pdfSpringMVC+Nutz框架...
SpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+Nutz框架介绍.docxSpringMVC+...
NutzWk 4.0.x 前后端分离版 (vue + nutz + dubbo) 开发中.. NutzWk 3.3.x CMS+微信+系统+权限+常用功能封装 (beetl / beetl+velocity) NutzWk 2.0.x 试验版(不建议使用) NutzWk 1.0.x 传统版(velocity 支持IE6) ...
ExtJs整合的Desktop 数据库为mysql。 框架为Nutz。
Nutz, 它是一组轻便小型的框架的集合。...如果你觉得 Java 语法不如 Ruby 便捷, Nutz.Castor 以及 Nutz.Lang 专为你设计 如果你以前根本没接触过 SSH ,只使用 JDBC 编程, 整个 Nutz 专门为你设计
数据库访问层 -- Nutz.Dao 反转注入支持 -- Nutz.Ioc Mvc 框架 -- Nutz.Mvc Json 解析器 -- Nutz.Json 更多的简化Java语法的函数和类 -- Nutz.Lang 以及 Nutz.Castors 不依赖任何第三方 Jar 包,从而便于程序员建立...
nutz框架使用手册,从零到有深入学习nutz平台开发
nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册 nutz 使用手册