ssh 实体关系分析确立(ER图-实体关系图)
比較简单的方式就是依据模仿同类产品,依据同类产品的进行模仿,表单就是一个起码要加的字段,然后依据项目须要额外添加字段。
注意:实体类之间的引用关系还须要考虑性能的影响。如:单向或是双向。
表设计:
设计好后:
写实体类
建立实体类到数据库的关联关系
概述
5.实体关系分析
1.类结构:带箭头是单线关联,不带箭头是双向关联
----------------------------------------
class User
(1)<------(*) class Survey (1)-------(*) class Page (1)-------(*) class Question
{ { {
{
Integer id ;
Integer id ; Integer id ; Integer id ;
... ... ... ...
User user ; Survey survey ; Page page ;
Set<Page> pages ;
Set<Question> questions ;
} } }
}
2.表结构
------------------------------------------------------------------
[users]
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(50) | YES | | NULL | |
| password | varchar(50) | YES | | NULL | |
| nickname | varchar(50) | YES | | NULL | |
| regdate | datetime | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
[surveys]
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(200) | YES | | NULL | |
| pretext | varchar(50) | YES | | NULL | |
| nexttext | varchar(50) | YES | | NULL | |
| exittext | varchar(50) | YES | | NULL | |
| donetext | varchar(50) | YES | | NULL | |
| createtime | datetime | YES | | NULL | |
| userid | int(11) | YES | MUL | NULL | |
+---------------+--------------+------+-----+---------+----------------+
[pages]
+-------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(200) | YES | | NULL | |
| description | varchar(200) | YES | | NULL | |
| surveyid | int(11) | YES | MUL | NULL | |
+-------------+---------------+------+-----+---------+----------------+
[questions]
+---------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| questiontype | int(11) | YES | | NULL | |
| title | varchar(200) | YES | | NULL | |
| options | varchar(200) | YES | | NULL | |
| other | bit(1) | YES | | NULL | |
| otherstyle | int(11) | YES | | NULL | |
| otherselectoptions | varchar(200) | YES | | NULL | |
| matrixrowtitles | varchar(200) | YES | | NULL | |
| matrixcoltitles | varchar(200) | YES | | NULL | |
| matrixselectoptions | varchar(200) | YES | | NULL | |
| pageid | int(11) | YES | MUL | NULL | |
+---------------------+--------------+------+-----+---------+----------------+
3.映射文件
------------------------------------------
[User.hbm.xml]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.atguigu.surveypark.model.User" table="users">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="email" column="email" type="string" length="50" />
<property name="password" column="password" type="string" length="50" />
<property name="nickName" column="nickname" type="string" length="50" />
<property name="regDate" column="regdate" type="timestamp" update="false"/>
</class>
</hibernate-mapping>
[Survey.hbm.xml]
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Survey" table="surveys">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="title" column="title" type="string" length="200" />
<property name="preText" column="pretext" type="string" length="50" />
<property name="nextText" column="nexttext" type="string" length="50" />
<property name="doneText" column="donetext" type="string" length="50" />
<property name="exitText" column="exittext" type="string" length="50" />
<property name="createTime" column="createtime" type="string" length="200" />
<!-- 映射从Survey到User之间多对一关联关系 -->
<many-to-one name="user" class="User" column="userid" />
<!-- 映射从Survey到Page之间一对多关联关系 -->
<set name="pages" inverse="true">
<key column="surveyid" />
<one-to-many class="Page"/>
</set>
</class>
</hibernate-mapping>
[Page.hbm.xml]
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Page" table="pages">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="title" column="title" type="string" length="100" />
<property name="description" column="description" type="string" length="200" />
<!-- 映射从Page到Survey之间多对一关联关系 -->
<many-to-one name="survey" class="Survey" column="surveyid" />
<!-- 映射从Page到Question之间一对多关联关系 -->
<set name="questions" inverse="true">
<key column="pageid" />
<one-to-many class="Question"/>
</set>
</class>
</hibernate-mapping>
[Question.hbm.xml]
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Question" table="questions">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="questionType" column="questiontype" type="integer" />
<property name="title" column="title" type="string" length="100" />
<property name="options" column="options" type="string" length="200" />
<property name="other" column="other" type="boolean"/>
<property name="otherStyle" column="otherstyle" type="integer" />
<property name="otherSelectOptions" column="otherselectoptions" type="string" length="200" />
<property name="matrixRowTitles" column="maxtrixrowtitles" type="string" length="200" />
<property name="matrixColTitles" column="matrixcoltitles" type="string" length="200" />
<property name="matrixSelectOptions" column="matrixselectoptions" type="string" length="200" />
<!-- 映射从Question到Page之间多对一关联关系 -->
<many-to-one name="page" class="Page" column="pageid" />
</class>
</hibernate-mapping>
具体代码例如以下:
Page.java
package com.atguigu.surveypark.model; import java.util.HashSet;
import java.util.Set; /**
* 页面类
*/
public class Page {
private Integer id;
private String title = "未命名";
private String description; //简历从Page到Survey之间多对一关联关系
private Survey survey; //简历从Page到Question之间一对多关联关系
private Set<Question> questions = new HashSet<>(); public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getDescription() {
return description;
} public void setDescription(String description) {
this.description = description;
} public Survey getSurvey() {
return survey;
} public void setSurvey(Survey survey) {
this.survey = survey;
} public Set<Question> getQuestions() {
return questions;
} public void setQuestions(Set<Question> questions) {
this.questions = questions;
} }
Page.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Page" table="pages">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="title" column="title" type="string" length="100" />
<property name="description" column="description" type="string" length="200" /> <!-- 映射从Page到Survey之间多对一关联关系 -->
<many-to-one name="survey" class="Survey" column="surveyid" /> <!-- 映射从Page到Question之间一对多关联关系 -->
<set name="questions" inverse="true">
<key column="surveyid" />
<one-to-many class="Question"/>
</set>
</class>
</hibernate-mapping>
Survey.java
package com.atguigu.surveypark.model; import java.util.Date; /**
* 调查类
*/
public class Survey {
private Integer id;
private String title = "未命名";
private String preText = "上一步";
private String nextText = "下一步";
private String exitText = "退出";
private String doneText = "完毕";
private Date createTime = new Date(); //建立从Survey到User之间多对一关联关系
private User user ; public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getPreText() {
return preText;
} public void setPreText(String preText) {
this.preText = preText;
} public String getNextText() {
return nextText;
} public void setNextText(String nextText) {
this.nextText = nextText;
} public String getExitText() {
return exitText;
} public void setExitText(String exitText) {
this.exitText = exitText;
} public String getDoneText() {
return doneText;
} public void setDoneText(String doneText) {
this.doneText = doneText;
} public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} }
Survey.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Survey" table="surveys">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="title" column="title" type="string" length="200" />
<property name="preText" column="pretext" type="string" length="50" />
<property name="nextText" column="nexttext" type="string" length="50" />
<property name="doneText" column="donetext" type="string" length="50" />
<property name="exitText" column="exittext" type="string" length="50" />
<property name="createTime" column="createtime" type="string" length="200" /> <!-- 映射从Survey到User之间多对一关联关系 -->
<many-to-one name="user" class="User" column="userid" /> <!-- 映射从Survey到Page之间一对多关联关系 -->
<set name="pages" inverse="true">
<key column="surveyid" />
<one-to-many class="Page"/>
</set>
</class>
</hibernate-mapping>
Question.java:
package com.atguigu.surveypark.model; /**
* 问题类
*/
public class Question {
//
private Integer id;
// 题型0-8
private int questionType;
//
private String title;
// 选项
private String options; // 其它项
private boolean other; // 其它项样式:0-无 1-文本框 2-下拉列表
private int otherStyle; // 其它项下拉选项
private String otherSelectOptions; // 矩阵式行标题集
private String matrixRowTitles; // 矩阵式列标题集
private String matrixColTitles;
// 矩阵是下拉选项集
private String matrixSelectOptions; //建立从Question到Page之间多对一关联关系
private Page page; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public int getQuestionType() {
return questionType;
} public void setQuestionType(int questionType) {
this.questionType = questionType;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getOptions() {
return options;
} public void setOptions(String options) {
this.options = options;
} public boolean isOther() {
return other;
} public void setOther(boolean other) {
this.other = other;
} public int getOtherStyle() {
return otherStyle;
} public void setOtherStyle(int otherStyle) {
this.otherStyle = otherStyle;
} public String getOtherSelectOptions() {
return otherSelectOptions;
} public void setOtherSelectOptions(String otherSelectOptions) {
this.otherSelectOptions = otherSelectOptions;
} public String getMatrixRowTitles() {
return matrixRowTitles;
} public void setMatrixRowTitles(String matrixRowTitles) {
this.matrixRowTitles = matrixRowTitles;
} public String getMatrixColTitles() {
return matrixColTitles;
} public void setMatrixColTitles(String matrixColTitles) {
this.matrixColTitles = matrixColTitles;
} public String getMatrixSelectOptions() {
return matrixSelectOptions;
} public void setMatrixSelectOptions(String matrixSelectOptions) {
this.matrixSelectOptions = matrixSelectOptions;
} public Page getPage() {
return page;
} public void setPage(Page page) {
this.page = page;
}
}
Question.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.atguigu.surveypark.model">
<class name="Question" table="questions">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="questionType" column="questiontype" type="integer" />
<property name="title" column="title" type="string" length="100" />
<property name="options" column="options" type="string" length="200" />
<property name="other" column="other" type="boolean"/>
<property name="otherStyle" column="otherstyle" type="integer" />
<property name="otherSelectOptions" column="otherselectoptions" type="string" length="200" /> <property name="matrixRowTitles" column="maxtrixrowtitles" type="string" length="200" />
<property name="matrixColTitles" column="matrixcoltitles" type="string" length="200" />
<property name="matrixSelectOptions" column="matrixselectoptions" type="string" length="200" /> <!-- 映射从Question到Page之间多对一关联关系 -->
<many-to-one name="page" class="Page" column="pageid" />
</class>
</hibernate-mapping>
User.java
package com.atguigu.surveypark.model; import java.util.Date; /**
* 用户类
*/
public class User {
private Integer id;
private String email;
private String name;
private String password;
private String nickName;
//注冊时间
private Date regDate = new Date(); public Integer getId() {
return id;
} public Date getRegDate() {
return regDate;
} public void setRegDate(Date regDate) {
this.regDate = regDate;
} public void setId(Integer id) {
this.id = id;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getNickName() {
return nickName;
} public void setNickName(String nickName) {
this.nickName = nickName;
} }
User.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.atguigu.surveypark.model.User" table="users">
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="email" column="email" type="string" length="50" />
<property name="password" column="password" type="string" length="50" />
<property name="nickName" column="nickname" type="string" length="50" />
<property name="regDate" column="regdate" type="timestamp" update="false"/>
</class>
</hibernate-mapping>
ssh 实体关系分析确立(ER图-实体关系图)的更多相关文章
- 数据库精华知识点总结(1)—数据库的三层模式和二级映像,E-R(实体联系图)图,关系模型
Data base: 长期存储在计算机内,有组织的,可共享的大量数据集合.基本特征:永久存储,可共享,有一定的物理和逻辑结构. Data base manage system(DBMS):用户和os之 ...
- 【Java EE 学习 69 下】【数据采集系统第一天】【实体类分析和Base类书写】
之前SSH框架已经搭建完毕,现在进行实体类的分析和Base类的书写.Base类是抽象类,专门用于继承. 一.实体类关系分析 既然是数据采集系统,首先调查实体(Survey)是一定要有的,一个调查有多个 ...
- E-R图向关系模式的转换
转自: http://hi.baidu.com/qicaiqinxian/blog/item/a8bb0bdf31ae081b63279887.html E-R图向关系模型转换时犯糊涂了,找到下面这篇 ...
- 数据库——数据库设计 E-R图向关系模型的转换
1.将下列物资管理E-R图转换为关系模式: 转换原则 ⒈ 一个实体型转换为一个关系模式.关系的属性:实体型的属性关系的码:实体型的码 ⒉ 一个m:n联系转换为一个关系模式(初步,以后可能调整). ...
- E-R图转换为关系模型
E-R模型如何转换成关系模型,这里我们分成三种情况进行讲解,分别是一对一,一对多和多对多. 1.一对一的情况: 有两种方法解决这个问题.第一个方法:可以单独对应一个关系模式,由各实体的主码构成关系模式 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (10) -----第二章 实体数据建模基础之两实体间Is-a和Has-a关系建模、嵌入值映射
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 2-11 两实体间Is-a和Has-a关系建模 问题 你有两张有Is-a和Has-a ...
- Hibernate基于注解方式配置来实现实体和数据库之间存在某种映射关系
实体和数据库之间存在某种映射关系,hibernate根据这种映射关系完成数据的存取.在程序中这种映射关系由映射文件(*.hbm.xml)或者java注解(@)定义. 本文以java注解的形式总结映射关 ...
- 一步一步学EF系列1【Fluent API的方式来处理实体与数据表之间的映射关系】
EF里面的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面,还有一个就是F ...
- SSH网上商城---需求分析+表关系分析
SSH---小编初次接触的时候傻傻的以为这个跟SHE有什么关系呢?又是哪路明星歌手,后来才知道小编又土鳖了,原来SSH是这个样子滴,百度百科对她这样阐述,SSH即 Spring + Struts +H ...
随机推荐
- Android中 Bitmap Drawable Paint的获取、转换以及使用
比如Drawable中有一系列连续的图片,img_0.png, img_1.png, img_2.png ... 如果要动态获取这些图片,通过"R.drawable.img_x"的 ...
- viewDidLoad、viewDidUnload、viewWillAppear、viewDidAppear、viewWillDisappear 和 -viewDidDisappear的区别和使用
首先看一下官方解释: - (void)loadView; // This is where subclasses should create their custom view hierarchy i ...
- ALV双击单元格事件处理
*激发双击事件 FORM f_alv_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. "先引 ...
- 与众不同 windows phone (17) - Graphic and Animation(画图和动画)
原文:与众不同 windows phone (17) - Graphic and Animation(画图和动画) [索引页][源码下载] 与众不同 windows phone (17) - Grap ...
- Shell printf 命令
Shell printf 命令 printf 命令模仿 C 程序库(library)里的 printf() 程序. 标准所定义,因此使用printf的脚本比使用echo移植性好. printf 使用引 ...
- Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
配置环境说明: KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G 系统盘20G cpu 4核 Haproxy keepalived 2台 192.168.1.10 192 ...
- linux下安装node.js
1.下载 wget http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz 2.解压 tar -xvf node-v0.10.32 ...
- js弹出对话框,遮罩效果,
刚刚来到实习单位,我跟着廖哥做项目.然后他分配给我一个小小的任务,实现起来总的效果如下: 然后,但我们单击显示数目这个链接的时候,就会弹出一个又遮罩效果的对话框,如下图: 当我们在对话框中再点击里面的 ...
- 一个跨平台的 C++ 内存泄漏检测器
2004 年 3 月 01 日 内存泄漏对于C/C++程序员来说也可以算作是个永恒的话题了吧.在Windows下,MFC的一个很有用的功能就是能在程序运行结束时报告是否发生了内存泄漏.在Linux下, ...
- 调整Tomcat的并发线程到5000+
调整Tomcat的并发线程数到5000+ 1. 调整server.xml的配置 先调整maxThreads的数值,在未调整任何参数之前,默认的并发线程可以达到40. 调整此项后可以达到1800左右. ...