how2j.cn

步骤 1 : 表关系图   
步骤 2 : 表   
步骤 3 : 正确的分析表与表之间的关系的方法   
步骤 4 : 表关系   

步骤 1 :

表关系图

在这张表关系图上,列出了模仿天猫整站一共需要用到的9张表,以及表之间的关系。接下来,对每张表做介绍,并讲解表与表之间的关系
表关系图
步骤 2 :

"); window.frames["iframe_show3611"].document.write(decodeHtml($("textarea#stepcodeTextarea3611").val())); window.frames["iframe_show3611"].document.close(); $(window.frames["iframe_show3611"]).load(function(){ $("#iframe_show3611").height($("#iframe_show3611").contents().find("body").height()+showittryitheight); }); $("#iframe_show3611").height($("#iframe_show3611").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
<style> *{ font-size:15px; } table.t2{ border-collapse:collapse; width:100%; } td{ text-align:left; padding-left:10px; background-color:#F5F5DC; } tr.firstline td{ background-color:#F0F8FF; } </style> <table class="t2" border="1" width="99%"> <tr class="firstline"> <td >表名</td> <td >中文含义</td> <td >介绍</td> </tr> <tr> <td >Category</td> <td >分类表 </td> <td >存放分类信息,如女装,平板电视,沙发等 </td> </tr> <tr> <td >Property</td> <td >属性表 </td> <td >存放属性信息,如颜色,重量,品牌,厂商,型号等</td> </tr> <tr> <td >Product</td> <td >产品表 </td> <td >存放产品信息,如LED40EC平板电视机,海尔EC6005热水器</td> </tr> <tr> <td >PropertyValue</td> <td >属性值表 </td> <td >存放属性值信息,如重量是900g,颜色是粉红色</td> </tr> <tr> <td >ProductImage</td> <td >产品图片表 </td> <td >存放产品图片信息,如产品页显示的5个图片</td> </tr> <tr> <td >Review</td> <td >评论表 </td> <td >存放评论信息,如买回来的蜡烛很好用,么么哒 </td> </tr> <tr> <td >User</td> <td >用户表 </td> <td >存放用户信息,如斩手狗,千手小粉红</td> </tr> <tr> <td >Order</td> <td >订单表 </td> <td >存放订单信息,包括邮寄地址,电话号码等信息</td> </tr> <tr> <td >OrderItem</td> <td >订单项表 </td> <td >存放订单项信息,包括购买产品种类,数量等 </td> </tr> </table>
"); window.frames["iframe3611"].document.write(decodeHtml(code3611)); window.frames["iframe3611"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3611"]).load(function(){ $("#iframe3611").height($("#iframe3611").contents().find("body").height()+showittryitheight); }); $("#iframe3611").height($("#iframe3611").contents().find("body").height()+showittryitheight); alreadyWriteCode3611 = code3611; $("#rendering3611").hide(); $("#rendered3611").show(); } var tRereshRetry2DemoPanel3611 = setInterval(rereshRetry2DemoPanel3611,1000); var binded3611 = false; $("textarea#stepcodeTextarea3611").keyup(function(){ if(!binded3611){ $(window).bind('beforeunload',function(){ binded3611 = true; return "xxxx"; }); } var newCode = $(this).val() code3611 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3611!=newCode){ // window.frames["iframe3611"].document.write("
"); // window.frames["iframe3611"].document.write(decodeHtml($("textarea#stepcodeTextarea3611").val())); // window.frames["iframe3611"].document.close(); // $(window.frames["iframe3611"]).load(function(){ // $("#iframe3611").height($("#iframe3611").contents().find("body").height()+showittryitheight); // }); // code3611 = newCode; // } }); $(".tryButton3611").click(function(){ $("#tryDiv3611").show(); $("#stepcodeTextarea3611").focus(); $("#stepcodeTextarea3611").height(200); $("#iframe3611").height(0); window.frames["iframe3611"].document.write("
"); window.frames["iframe3611"].document.write(decodeHtml($("textarea#stepcodeTextarea3611").val())); window.frames["iframe3611"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3611"]).load(function(){ $("#iframe3611").height($("#iframe3611").contents().find("body").height()+showittryitheight); }); $("#iframe3611").height($("#iframe3611").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3611.focus(); editor3611.setSize(null, "250"); $("#rendering3611").hide(); $("#rendered3611").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor3611 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3611"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor3611.on("change",function(doc){ if(!binded3611){ $(window).bind('beforeunload',function(){ binded3611 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3611 = newCode; $("textarea#stepcodeTextarea3611").val(newCode); if(alreadyWriteCode3611!=code3611){ lastModifedTime3611 = new Date().getTime(); $("#rendering3611").show(); $("#rendered3611").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3611 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3611.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3611").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
步骤 3 :

正确的分析表与表之间的关系的方法

表与表之间的关系,基本上是3种
一对一
一对多
多对一
那么怎么判断关系到底是什么呢?
以分类和产品为例子,分类表里有多条数据,产品表里也有多条数据,那么他们的关系是多对多吗? 从经验上讲,我们知道这个结果是不正确的。

正确的分析表与表之间的关系的方法是这样:
一个分类对应 多个 产品
一个产品对应 一个 分类

所以分类和产品之间的关系是一对多
正确的分析表与表之间的关系的方法
步骤 4 :

表关系

从最上面的表关系图中可以看到,有关系的表之间,都是一对多关系(反过来就是多对一关系),并没有一对一关系,和多对多关系。

所以本表列出了所有的一对多关系

注:产品和用户之间其实是多对多关系,即一个用户可以购买多种产品,一种产品可以被多个用户购买。 但是他们的多对多关系是间接的建立在订单项表(OrderItem)上的。
"); window.frames["iframe_show3613"].document.write(decodeHtml($("textarea#stepcodeTextarea3613").val())); window.frames["iframe_show3613"].document.close(); $(window.frames["iframe_show3613"]).load(function(){ $("#iframe_show3613").height($("#iframe_show3613").contents().find("body").height()+showittryitheight); }); $("#iframe_show3613").height($("#iframe_show3613").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
<style> *{ font-size:15px; } table.t2{ border-collapse:collapse; width:350px; } td{ text-align:left; padding-left:10px; background-color:#F5F5DC; } tr.firstline td{ background-color:#F0F8FF; } </style> <table class="t2" border="1" width="99%"> <tr class="firstline"> <td width="41%" >一</td> <td >多</td> </tr> <tr> <td >Category-分类</td> <td >Product-产品</td> </tr> <tr> <td >Category-分类</td> <td >Property-属性</td> </tr> <tr> <td >Property-属性</td> <td >PropertyValue-属性值</td> </tr> <tr> <td >Product-产品</td> <td >PropertyValue-属性值</td> </tr> <tr> <td >Product-产品</td> <td >ProductImage-产品图片</td> </tr> <tr> <td >Product-产品</td> <td >Review-评价</td> </tr> <tr> <td >User-用户</td> <td >Order-订单</td> </tr> <tr> <td >Product-产品</td> <td >OrderItem-订单项 </td> </tr> <tr> <td >User-用户</td> <td >OrderItem-订单项</td> </tr> <tr> <td >Order-订单</td> <td >OrderItem-订单项</td> </tr> <tr> <td >User-用户</td> <td >User-评价</td> </tr> </table>
"); window.frames["iframe3613"].document.write(decodeHtml(code3613)); window.frames["iframe3613"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3613"]).load(function(){ $("#iframe3613").height($("#iframe3613").contents().find("body").height()+showittryitheight); }); $("#iframe3613").height($("#iframe3613").contents().find("body").height()+showittryitheight); alreadyWriteCode3613 = code3613; $("#rendering3613").hide(); $("#rendered3613").show(); } var tRereshRetry2DemoPanel3613 = setInterval(rereshRetry2DemoPanel3613,1000); var binded3613 = false; $("textarea#stepcodeTextarea3613").keyup(function(){ if(!binded3613){ $(window).bind('beforeunload',function(){ binded3613 = true; return "xxxx"; }); } var newCode = $(this).val() code3613 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3613!=newCode){ // window.frames["iframe3613"].document.write("
"); // window.frames["iframe3613"].document.write(decodeHtml($("textarea#stepcodeTextarea3613").val())); // window.frames["iframe3613"].document.close(); // $(window.frames["iframe3613"]).load(function(){ // $("#iframe3613").height($("#iframe3613").contents().find("body").height()+showittryitheight); // }); // code3613 = newCode; // } }); $(".tryButton3613").click(function(){ $("#tryDiv3613").show(); $("#stepcodeTextarea3613").focus(); $("#stepcodeTextarea3613").height(200); $("#iframe3613").height(0); window.frames["iframe3613"].document.write("
"); window.frames["iframe3613"].document.write(decodeHtml($("textarea#stepcodeTextarea3613").val())); window.frames["iframe3613"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3613"]).load(function(){ $("#iframe3613").height($("#iframe3613").contents().find("body").height()+showittryitheight); }); $("#iframe3613").height($("#iframe3613").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3613.focus(); editor3613.setSize(null, "250"); $("#rendering3613").hide(); $("#rendered3613").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor3613 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3613"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor3613.on("change",function(doc){ if(!binded3613){ $(window).bind('beforeunload',function(){ binded3613 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3613 = newCode; $("textarea#stepcodeTextarea3613").val(newCode); if(alreadyWriteCode3613!=code3613){ lastModifedTime3613 = new Date().getTime(); $("#rendering3613").show(); $("#rendered3613").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3613 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3613.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3613").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 实践项目-天猫整站J2EE-表与表关系 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图