比較简单的方式就是依据模仿同类产品,依据同类产品的进行模仿,表单就是一个起码要加的字段,然后依据项目须要额外添加字段。

注意:实体类之间的引用关系还须要考虑性能的影响。如:单向或是双向。

表设计:

设计好后:

写实体类

建立实体类到数据库的关联关系

概述

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. 数据库精华知识点总结(1)—数据库的三层模式和二级映像,E-R(实体联系图)图,关系模型

    Data base: 长期存储在计算机内,有组织的,可共享的大量数据集合.基本特征:永久存储,可共享,有一定的物理和逻辑结构. Data base manage system(DBMS):用户和os之 ...

  2. 【Java EE 学习 69 下】【数据采集系统第一天】【实体类分析和Base类书写】

    之前SSH框架已经搭建完毕,现在进行实体类的分析和Base类的书写.Base类是抽象类,专门用于继承. 一.实体类关系分析 既然是数据采集系统,首先调查实体(Survey)是一定要有的,一个调查有多个 ...

  3. E-R图向关系模式的转换

    转自: http://hi.baidu.com/qicaiqinxian/blog/item/a8bb0bdf31ae081b63279887.html E-R图向关系模型转换时犯糊涂了,找到下面这篇 ...

  4. 数据库——数据库设计 E-R图向关系模型的转换

    1.将下列物资管理E-R图转换为关系模式: 转换原则 ⒈  一个实体型转换为一个关系模式.关系的属性:实体型的属性关系的码:实体型的码   ⒉ 一个m:n联系转换为一个关系模式(初步,以后可能调整). ...

  5. E-R图转换为关系模型

    E-R模型如何转换成关系模型,这里我们分成三种情况进行讲解,分别是一对一,一对多和多对多. 1.一对一的情况: 有两种方法解决这个问题.第一个方法:可以单独对应一个关系模式,由各实体的主码构成关系模式 ...

  6. 《Entity Framework 6 Recipes》中文翻译系列 (10) -----第二章 实体数据建模基础之两实体间Is-a和Has-a关系建模、嵌入值映射

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 2-11 两实体间Is-a和Has-a关系建模 问题 你有两张有Is-a和Has-a ...

  7. Hibernate基于注解方式配置来实现实体和数据库之间存在某种映射关系

    实体和数据库之间存在某种映射关系,hibernate根据这种映射关系完成数据的存取.在程序中这种映射关系由映射文件(*.hbm.xml)或者java注解(@)定义. 本文以java注解的形式总结映射关 ...

  8. 一步一步学EF系列1【Fluent API的方式来处理实体与数据表之间的映射关系】

    EF里面的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面,还有一个就是F ...

  9. SSH网上商城---需求分析+表关系分析

    SSH---小编初次接触的时候傻傻的以为这个跟SHE有什么关系呢?又是哪路明星歌手,后来才知道小编又土鳖了,原来SSH是这个样子滴,百度百科对她这样阐述,SSH即 Spring + Struts +H ...

随机推荐

  1. 请问,如何在windows系统下面同时使用中文和英文的cmd?_百度知道

    请问,如何在windows系统下面同时使用中文和英文的cmd?_百度知道 在批处理开始加一行chcp 437就是英文的cmdchcp 936就是中文的cmd

  2. 【Cloud Foundry】Could Foundry学习(二)——核心组件分析

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 Cloud Foundry核心组件架构图例如以下: 主要组件:     Clou ...

  3. u-boot的nand驱动写过程分析

    从命令说起,在u-boot输入下列命令: nand write 40008000 0 20000 命令的意思是将内存0x40008000开始的部分写入nand,从nand地址0开始写,写入长度是0x2 ...

  4. Net Core子应用由于配置引起IIS错误500.19

    Asp.Net Core子应用由于配置中重复添加模块会引起IIS错误500.19 ASP.NET Core已经从IIS中解耦,可以作为自宿主程序运行,不再依赖IIS. 但我们还是需要强大的IIS作为前 ...

  5. Visual Studio Code中文文档

    Visual Studio Code中文文档 Visual Studio Code是一个轻量级但是十分强大的源代码编辑器,重要的是它在Windows, OS X 和Linux操作系统的桌面上均可运行. ...

  6. Esper学习之四:Context

    上周末打球实在太累了,就没来得及更新,只是列了个提纲做做准备,发现Context还是有很多内容的.结果也花了不少时间才写完,所以这篇需要各位慢慢消化,并且最好多写几个例子加深理解. 如果有不了解Esp ...

  7. operator= 复制操作符的意外

    首先,看以下的代码的输出时什么: 上述代码做了最理所当然的事.就是将Derived的两个对象进行了交换.可是通过指针进行的赋值输出却不是预期的: 居然调用的是Base的operator=,也就意味着我 ...

  8. Hadoop之MapReduce程序应用三

    摘要:MapReduce程序进行数据去重. 关键词:MapReduce   数据去重 数据源:人工构造日志数据集log-file1.txt和log-file2.txt. log-file1.txt内容 ...

  9. [Windows Phone]模仿魔兽3技能按钮SkillButton

    简介: 模仿魔兽3技能按钮,带CD效果.使用的时候可以当做普通按钮使用,同时也支持Binding. 音效紧耦合在控件内部,因为控件本身目的就是模拟魔兽3的技能按钮,所以不考虑音效的扩展. Demo结构 ...

  10. 那些年我们装过的数据库---盘点sqlserver2008安装时遇到的各种的问题(持续更新中)

    给自己安过sqlServer2008,也给好多同学安过sqlServer2008,期间遇到了好多不同的另人心烦的问题,在这里整理一下,(涉及到的部分方法是在网上找的,有些也没试过,仅仅是在这里整理一下 ...