how2j.cn

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

步骤 1 :

表关系图

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

"); window.frames["iframe_show6042"].document.write(decodeHtml($("textarea#stepcodeTextarea6042").val())); window.frames["iframe_show6042"].document.close(); $(window.frames["iframe_show6042"]).load(function(){ $("#iframe_show6042").height($("#iframe_show6042").contents().find("body").height()+showittryitheight); }); $("#iframe_show6042").height($("#iframe_show6042").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["iframe6042"].document.write(decodeHtml(code6042)); window.frames["iframe6042"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe6042"]).load(function(){ $("#iframe6042").height($("#iframe6042").contents().find("body").height()+showittryitheight); }); $("#iframe6042").height($("#iframe6042").contents().find("body").height()+showittryitheight); alreadyWriteCode6042 = code6042; $("#rendering6042").hide(); $("#rendered6042").show(); } var tRereshRetry2DemoPanel6042 = setInterval(rereshRetry2DemoPanel6042,1000); var binded6042 = false; $("textarea#stepcodeTextarea6042").keyup(function(){ if(!binded6042){ $(window).bind('beforeunload',function(){ binded6042 = true; return "xxxx"; }); } var newCode = $(this).val() code6042 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code6042!=newCode){ // window.frames["iframe6042"].document.write("
"); // window.frames["iframe6042"].document.write(decodeHtml($("textarea#stepcodeTextarea6042").val())); // window.frames["iframe6042"].document.close(); // $(window.frames["iframe6042"]).load(function(){ // $("#iframe6042").height($("#iframe6042").contents().find("body").height()+showittryitheight); // }); // code6042 = newCode; // } }); $(".tryButton6042").click(function(){ $("#tryDiv6042").show(); $("#stepcodeTextarea6042").focus(); $("#stepcodeTextarea6042").height(200); $("#iframe6042").height(0); window.frames["iframe6042"].document.write("
"); window.frames["iframe6042"].document.write(decodeHtml($("textarea#stepcodeTextarea6042").val())); window.frames["iframe6042"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe6042"]).load(function(){ $("#iframe6042").height($("#iframe6042").contents().find("body").height()+showittryitheight); }); $("#iframe6042").height($("#iframe6042").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor6042.focus(); editor6042.setSize(null, "250"); $("#rendering6042").hide(); $("#rendered6042").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 editor6042 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea6042"), { 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); } } }); editor6042.on("change",function(doc){ if(!binded6042){ $(window).bind('beforeunload',function(){ binded6042 = true; return "xxxx"; }); } var newCode = doc.getValue(); code6042 = newCode; $("textarea#stepcodeTextarea6042").val(newCode); if(alreadyWriteCode6042!=code6042){ lastModifedTime6042 = new Date().getTime(); $("#rendering6042").show(); $("#rendered6042").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor6042 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor6042.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv6042").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

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

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

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

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

表关系

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

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

注:产品和用户之间其实是多对多关系,即一个用户可以购买多种产品,一种产品可以被多个用户购买。 但是他们的多对多关系是间接的建立在订单项表(OrderItem)上的。
"); window.frames["iframe_show6044"].document.write(decodeHtml($("textarea#stepcodeTextarea6044").val())); window.frames["iframe_show6044"].document.close(); $(window.frames["iframe_show6044"]).load(function(){ $("#iframe_show6044").height($("#iframe_show6044").contents().find("body").height()+showittryitheight); }); $("#iframe_show6044").height($("#iframe_show6044").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 >Review-评价</td> </tr> </table>
"); window.frames["iframe6044"].document.write(decodeHtml(code6044)); window.frames["iframe6044"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe6044"]).load(function(){ $("#iframe6044").height($("#iframe6044").contents().find("body").height()+showittryitheight); }); $("#iframe6044").height($("#iframe6044").contents().find("body").height()+showittryitheight); alreadyWriteCode6044 = code6044; $("#rendering6044").hide(); $("#rendered6044").show(); } var tRereshRetry2DemoPanel6044 = setInterval(rereshRetry2DemoPanel6044,1000); var binded6044 = false; $("textarea#stepcodeTextarea6044").keyup(function(){ if(!binded6044){ $(window).bind('beforeunload',function(){ binded6044 = true; return "xxxx"; }); } var newCode = $(this).val() code6044 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code6044!=newCode){ // window.frames["iframe6044"].document.write("
"); // window.frames["iframe6044"].document.write(decodeHtml($("textarea#stepcodeTextarea6044").val())); // window.frames["iframe6044"].document.close(); // $(window.frames["iframe6044"]).load(function(){ // $("#iframe6044").height($("#iframe6044").contents().find("body").height()+showittryitheight); // }); // code6044 = newCode; // } }); $(".tryButton6044").click(function(){ $("#tryDiv6044").show(); $("#stepcodeTextarea6044").focus(); $("#stepcodeTextarea6044").height(200); $("#iframe6044").height(0); window.frames["iframe6044"].document.write("
"); window.frames["iframe6044"].document.write(decodeHtml($("textarea#stepcodeTextarea6044").val())); window.frames["iframe6044"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe6044"]).load(function(){ $("#iframe6044").height($("#iframe6044").contents().find("body").height()+showittryitheight); }); $("#iframe6044").height($("#iframe6044").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor6044.focus(); editor6044.setSize(null, "250"); $("#rendering6044").hide(); $("#rendered6044").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 editor6044 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea6044"), { 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); } } }); editor6044.on("change",function(doc){ if(!binded6044){ $(window).bind('beforeunload',function(){ binded6044 = true; return "xxxx"; }); } var newCode = doc.getValue(); code6044 = newCode; $("textarea#stepcodeTextarea6044").val(newCode); if(alreadyWriteCode6044!=code6044){ lastModifedTime6044 = new Date().getTime(); $("#rendering6044").show(); $("#rendered6044").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor6044 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor6044.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv6044").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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


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


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

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

上传截图