<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>云河空间</title><link>https://yuyunhe.cn/</link><description>Good Luck To You!</description><item><title>Devops学习路线图</title><link>https://yuyunhe.cn/index.php/post/324.html</link><description>&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://yuyunhe.cn/zb_users/upload/2025/04/202504031743665948259058.png&quot; title=&quot;devops.png&quot; alt=&quot;devops.png&quot;/&gt;&lt;/p&gt;</description><pubDate>Fri, 28 Jul 2023 11:22:03 +0800</pubDate></item><item><title>vue配置iframe父级窗口通信</title><link>https://yuyunhe.cn/index.php/post/322.html</link><description>&lt;p&gt;在router/index.js中配置&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-markdown&quot;&gt;export&amp;nbsp;default&amp;nbsp;new&amp;nbsp;Router({
&amp;nbsp;&amp;nbsp;scrollBehavior:&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;({&amp;nbsp;y:&amp;nbsp;0&amp;nbsp;}),
&amp;nbsp;&amp;nbsp;routes:&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;path:&amp;nbsp;&amp;#39;/&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name:&amp;nbsp;&amp;#39;index&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;component:&amp;nbsp;resolve&amp;nbsp;=&amp;gt;&amp;nbsp;require([&amp;#39;@/views/index&amp;#39;],&amp;nbsp;resolve),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;meta:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;keepAlive:&amp;nbsp;true,&amp;nbsp;//&amp;nbsp;此组件需要被缓存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isIframe:&amp;nbsp;true&amp;nbsp;//&amp;nbsp;标记是否是iframe
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;]
})&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;在入口文件main.js中配置&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-markdown&quot;&gt;//&amp;nbsp;判断当前路由是否需要iframe
router.beforeEach((to,&amp;nbsp;from,&amp;nbsp;next)&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;if&amp;nbsp;(to.meta.isIframe)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;window.parent.postMessage({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type:&amp;nbsp;&amp;#39;setIframeHeight&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;height:&amp;nbsp;document.documentElement.scrollHeight
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&amp;nbsp;&amp;#39;*&amp;#39;)
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;next()
})&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;在父页面中添加&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-markdown&quot;&gt;&amp;lt;script&amp;gt;
&amp;nbsp;&amp;nbsp;window.addEventListener(&amp;#39;message&amp;#39;,&amp;nbsp;function&amp;nbsp;(e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(e.data.type&amp;nbsp;===&amp;nbsp;&amp;#39;setIframeHeight&amp;#39;)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;document.querySelector(&amp;#39;#iframe&amp;#39;).height&amp;nbsp;=&amp;nbsp;e.data.height
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;})
&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 07 Feb 2023 14:42:14 +0800</pubDate></item><item><title>一文读懂，DDD落地数据库设计实战</title><link>https://yuyunhe.cn/index.php/post/321.html</link><description>&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;作者范钢，曾任航天信息首席架构师，《大话重构》一书的作者。本文根据具体实例详细描述了DDD 落实到&lt;a data-text-link=&quot;107_1777654&quot; data-from=&quot;10680&quot; href=&quot;https://cloud.tencent.com/solution/database?from=10680&quot; target=&quot;_blank&quot; style=&quot;text-decoration-line: none; box-sizing: border-box; list-style: inherit; color: rgb(0, 164, 255);&quot;&gt;数据库&lt;/a&gt;设计的整个过程&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;阅读本文之前建议先阅读上一篇文章《&lt;a data-from=&quot;10680&quot; href=&quot;http://mp.weixin.qq.com/s?__biz=MzU5MTIyODk1Mg==&amp;mid=2247484368&amp;idx=1&amp;sn=30a1ec30d05a454f8451332d0b492ae3&amp;chksm=fe337aa7c944f3b148ba696f2014229f817edec9a2d854e88b6c218cad382da5805faf24ddbb&amp;scene=21#wechat_redirect&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot; style=&quot;text-decoration-line: none; box-sizing: border-box; list-style: inherit; color: rgb(0, 164, 255);&quot;&gt;万字长文，结合电商支付业务一文搞懂DDD&lt;/a&gt;》&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;过去，系统的软件设计是以数据库设计为核心，当需求确定下来以后，团队首先开始进行数据库设计。因为数据库是各个模块唯一的接口，当整个团队将数据库设计确定下来以后，就可以按照模块各自独立地进行开发了，如下图所示。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/xasftiuxuy.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;在上面的过程中，为了提高团队开发速度，尽量让各个模块不要交互，从而达到各自独立开发的效果。但是，随着系统规模越来越大，业务逻辑越来越复杂，我们越来越难于保证各个模块独立不交互了。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;随着软件业的不断发展，软件系统变得越来越复杂，各个模块间的交互也越来越频繁，这时，原有的设计过程已经不能满足我们的需要了。因为如果要先进行数据库设计，但数据库设计只能描述数据结构，而不能描述系统对这些数据结构的处理。因此，在第一次对整个系统的梳理过程中，只能梳理系统的所有数据结构，形成数据库设计；接着，又要再次梳理整个系统，分析系统对这些数据结构的处理过程，形成程序设计。为什么不能一次性地把整个系统的设计梳理到位呢？&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/ew2q3qv05m.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;现如今，我们已经按照面向对象的软件设计过程来分析设计系统了。当开始需求分析时，首先进行用例模型的设计，分析整个系统要实现哪些功能；接着进行领域模型的设计，分析系统的业务实体。在领域模型分析中，采用类图的形式，每个类可以通过它的属性来表述数据结构，又可以通过添加方法来描述对这个数据结构的处理。因此，在领域模型的设计过程中，既完成了对数据结构的梳理，又确定了系统对这些数据结构的处理，这样就把两项工作一次性地完成了。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;在这个设计过程中，其核心是领域模型的设计。以领域模型作为核心，可以指导系统的数据库设计与程序设计，此时，数据库设计就弱化为了领域对象持久化设计的一种实现方式。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;领域对象持久化的思想&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;什么叫领域对象的持久化呢？在当今软件架构设计的主流思想中，面向对象设计成了主流思想，在整个系统运行的过程中，所有的数据都是以领域对象的形式存在的。譬如：&lt;/p&gt;&lt;ul class=&quot;ul-level-0 list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;要插入一条记录就是创建一个领域对象；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;要更新一条记录就是根据 key 值去修改相应的领域对象；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;删除数据则是摧毁这个领域对象。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;假如我们的服务器是一台超级强大的服务器，那实际上不需要任何数据库，直接操作这些领域对象就可以了，但在现实世界中没有那么强大的服务器。因此，必须将暂时不用的领域对象持久化存储到磁盘中，而数据库只是这种持久化存储的一种实现方式。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;按照这种设计思想，我们将暂时不使用的领域对象从内存中持久化存储到磁盘中。当日后需要再次使用这个领域对象时，根据 key 值到数据库查找到这条记录，然后将其恢复成领域对象，应用程序就可以继续使用它了，这就是领域对象持久化存储的设计思想。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;所以，今天的数据库设计，实际上就是将领域对象的设计按照某种对应关系，转换成数据库的设计。同时，随着整个产业的大数据转型，今后的数据库设计思想也将发生巨大的转变，有可能数据库就不一定是关系型数据库了，也许是 NoSQL 数据库或者大数据平台。数据库的设计也不一定遵循 3NF（第三范式）了，可能会增加更多的冗余，甚至是宽表。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;数据库设计在发生剧烈的变化，但唯一不变的是领域对象。这样，当系统在大数据转型时，可以保证业务代码不变，变化的是数据访问层（DAO）。这将使得日后大数据转型的成本更低，让我们更快地跟上技术快速发展的脚步。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;领域模型的设计&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;此外，这里有个有趣的问题值得探讨：领域模型的设计到底是谁的职责，是需求分析人员还是设计开发人员？我认为，它是两个角色相互协作的产物。而未来&lt;a data-text-link=&quot;2063_1777654&quot; data-from=&quot;10680&quot; href=&quot;https://cloud.tencent.com/product/coding-pm?from=10680&quot; target=&quot;_blank&quot; style=&quot;text-decoration-line: none; box-sizing: border-box; list-style: inherit; color: rgb(0, 164, 255);&quot;&gt;敏捷开发&lt;/a&gt;的组织形成，团队将更加扁平化。过去是需求分析人员做需求分析，然后交给设计人员设计开发，这种方式就使得软件设计质量低下而结构臃肿。未来“大前端”的思想将支持更多设计开发人员直接参与需求分析，实现从需求分析到设计开发的一体化组织形式。这样，领域模型就成为了设计开发人员快速理解需求的利器。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;总之，**DDD 的数据库设计实际上已经变成了：以领域模型为核心，如何将领域模型转换成数据库设计的过程。**那么怎样进行转换呢？在领域模型中是一个一个的类，而在数据库设计中是一个一个的表，因此就是将类转换成表的过程。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/rpx2m6doot.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;上图是一个绩效考核系统的领域模型图，该绩效考核系统首先进行自动考核，发现一批过错，然后再给一个机会，让过错责任人对自己的过错进行申辩。这时，过错责任人可以填写一张申辩申请单，在申辩申请单中有多个明细，每个明细对应一个过错行为，每个过错行为都对应了一个过错类型，这样就形成了一个领域模型。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;接着，要将这个领域模型转换成数据库设计，怎么做呢？很显然，领域模型中的一个类可以转换成数据库中的一个表，类中的属性可以转换成表中的字段。但这里的关键是如何处理类与类之间的关系，如何转换成表与表之间的关系。这时候，就有 5 种类型的关系需要转换，即传统的 4 种关系 + 继承关系。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;传统的 4 种关系&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;传统的关系包含一对一、多对一、一对多、多对多这 4 种，它们既存在于类与类之间，又存在于表与表之间，所以可以直接进行转换。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;1. 一对一关系&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;在以上案例中，“申辩申请单明细”与“过错行为”就是一对“一对一”关系。在该关系中，一个“申辩申请单明细”必须要对应一个“过错行为”，没有一个“过错行为”的对应就不能成为一个“申辩申请单明细”。这种约束在数据库设计时，可以通过外键来实现。但是，一对一关系还有另外一个约束，那就是一个“过错行为”最多只能有一个“申辩申请单明细”与之对应。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;也就是说，一个“过错行为”可以没有“申辩申请单明细”与之对应，但如果有，最多只能有一个“申辩申请单明细”与之对应，这个约束暗含的是一种唯一性的约束。因此，将过错行为表中的主键，作为申辩申请单明细表的外键，并将该字段升级为申辩申请单明细表的主键。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/n5t12te6od.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;2. 多对一关系&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;是日常的分析设计中最常见的一种关系。在以上案例中，一个过错行为对应一个税务人员、一个纳税人与一个过错类型；同时，一个税务人员，或纳税人，或过错类型，都可以对应多个过错行为。它们就形成了“多对一”关系。在数据库设计时，通过外键就可以建立这种“多对一”关系。因此，我们进行了如下数据库的设计：&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/x1tkpw996o.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;多对一关系在数据库设计上比较简单，然而落实到程序设计时，需要好好探讨一下。比如，以上案例，在按照这样的方式设计以后，在查询时往往需要在查询过错行为的同时，显示它们对应的税务人员、纳税人与过错类型。这时，以往的设计是增加一个 join 语句。然而，这样的设计在随着数据量不断增大时，查询性能将受到极大的影响。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;也就是说，join 操作往往是关系型数据库在面对大数据时最大的瓶颈之一。因此，一个更好的方案就是先查询过错行为表，分页，然后再补填当前页的其他关联信息。这时，就需要在“过错行为”这个值对象中通过属性变量，增加对税务人员、纳税人与过错类型等信息的引用。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;3. 一对多关系&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;该关系往往表达的是一种主-子表的关系。譬如，以上案例中的“申辩申请单”与“申辩申请单明细”就是一对“一对多”关系。除此之外，订单与订单明细、表单与表单明细，都是一对多关系。一对多关系在数据库设计上比较简单，就是在子表中增加一个外键去引用主表中的主键。比如本案例中，申辩申请单明细表通过一个外键去引用申辩申请单表中的主键，如下图所示。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/06d1nowc58.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;除此之外，在程序的值对象设计时，主对象中也应当有一个集合的属性变量去引用子对象。如本例中，在“申辩申请单”值对象中有一个集合属性去引用“申辩申请单明细”。这样，当通过申辩申请单号查找到某个申辩申请单时，同时就可以获得它的所有申辩申请单明细，如下代码所示：&lt;/p&gt;&lt;div class=&quot;developer-code-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit; position: relative; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre class=&quot;prism-token token line-numbers language-javascript&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: border-box; list-style: inherit; padding: 1em 1em 1em 3.8em; color: rgb(204, 204, 204); background-color: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; overflow-wrap: normal; word-spacing: normal; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; position: relative; counter-reset: linenumber 0;&quot;&gt;public&amp;nbsp;class&amp;nbsp;Sbsqd&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Set&amp;lt;SbsqdMx&amp;gt;&amp;nbsp;sbsqdMxes;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;setSbsqdMxes(Set&amp;lt;SbsqdMx&amp;gt;&amp;nbsp;sbsqdMxes){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.sbsqdMxes&amp;nbsp;=&amp;nbsp;sbsqdMxes;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Set&amp;lt;SbsqdMx&amp;gt;&amp;nbsp;getSbsqdMxes(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;this.sbsqdMxes;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;……}&lt;/pre&gt;&lt;button class=&quot;copy&quot; style=&quot;margin: 0px; padding: 0px 0.5em; font-family: inherit; border-width: initial; border-style: none; border-color: initial; cursor: pointer; list-style: inherit; color: rgb(255, 255, 255); background-color: rgb(105, 113, 145); font-size: 0.8em; border-radius: 0.5em; z-index: 10; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0; position: absolute;&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;4. 多对多关系&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;比较典型的例子就是“用户角色”与“功能权限”。一个“用户角色”可以申请多个“功能权限”；而一个“功能权限”又可以分配给多个“用户角色”使用，这样就形成了一个“多对多”关系。这种多对多关系在对象设计时，可以通过一个“功能-角色关联类”来详细描述。因此，在数据库设计时就可以添加一个“角色功能关联表”，而该表的主键就是关系双方的主键进行的组合，形成的联合主键，如下图所示：&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/9j3cmlfyri.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;以上是领域模型和数据库都有的 4 种关系。因此，在数据库设计时，直接将相应的关系转换成数据库设计就可以了。同时，在数据库设计时还要将它们进一步细化。如在领域模型中，不论对象还是属性，在命名时都采用中文，这样有利于沟通与理解。但到了数据库设计时，就要将它们细化为英文命名，或者汉语拼音首字母，同时还要确定它们的字段类型与是否为空等其他属性。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;继承关系的 3 种设计&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;第 5 种关系就不太一样了：继承关系是在领域模型设计中有，但在数据库设计中却没有。如何将领域模型中的继承关系转换成数据库设计呢？有 3 种方案可以选择。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;1. 继承关系的第一种方案&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;首先，看看以上案例。“执法行为”通过继承分为“正确行为”和“过错行为”。如果这种继承关系的子类不多（一般就 2 ~ 3 个），并且每个子类的个性化字段也不多（3 个以内）的话，则可以使用一个表来记录整个继承关系。在这个表的中间有一个标识字段，标识表中的每条记录到底是哪个子类，这个字段的前面部分罗列的是父类的字段，后面依次罗列各个子类的个性化字段。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/tkovg40kgd.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;采用这个方案的优点是简单，整个继承关系的数据全部都保存在这个表里。但是，它会造成“表稀疏”。在该案例中，如果是一条“正确行为”的记录，则字段“过错类型”与“扣分”永远为空；如果是一条“过错行为”的记录，则字段“加分”永远为空。假如这个继承关系中各子类的个性化字段很多，就会造成该表中出现大量字段为空，称为“表稀疏”。在关系型数据库中，为空的字段是要占用空间的。因此，这种“表稀疏”既会浪费大量存储空间，又会影响查询速度，是需要极力避免的。所以，当子类比较多，或者子类个性化字段多的情况是不适合该方案（第一种方案）的。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;2. 继承关系的第二种方案&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果执法行为按照考核指标的类型进行继承，分为“考核指标1”“考核指标2”“考核指标3”……如下图所示：&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/p0e7lw1iio.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;并且每个子类都有很多的个性化字段，则采用前面那个方案就不合适了。这时，用另外两个方案进行数据库设计。其中一个方案是将每个子类都对应到一个表，有几个子类就有几个表，这些表共用一个主键，即这几个表的主键生成器是一个，某个主键值只能存在于某一个表中，不能存在于多个表中。每个表的前面是父类的字段，后面罗列各个子类的字段，如下图所示：&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/7fwi0t4xtc.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果业务需求是在前端查询时，每次只能查询某一个指标，那么采用这种方案就能将每次查询落到某一个表中，方案就最合适。但如果业务需求是要查询某个过错责任人涉及的所有指标，则采用这种方案就必须要在所有的表中进行扫描，那么查询效率就比较低，并不适用。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;3. 继承关系的第三种方案&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果业务需求是要查询某个过错责任人涉及的所有指标，则更适合采用以下方案，将父类做成一个表，各个子类分别对应各自的表（如图所示）。这样，当需要查询某个过错责任人涉及的所有指标时，只需要查询父类的表就可以了。如果要查看某条记录的详细信息，再根据主键与类型字段，查询相应子类的个性化字段。这样，这种方案就可以完美实现该业务需求。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/uymcqen1vc.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;综上所述，将领域模型中的继承关系转换成数据库设计有 3 种方案，并且每个方案都有各自的优缺点。因此，需要根据业务场景的特点与需求去评估，选择哪个方案更适用。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;NoSQL 数据库的设计&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;前面我们讲的数据库设计，还是基于传统的关系型数据库、基于第三范式的数据库设计。但是，随着互联网高并发与分布式技术的发展，另一种全新的数据库类型孕育而生，那就是NoSQL 数据库。正是由于互联网应用带来的高并发压力，采用关系型数据库进行集中式部署不能满足这种高并发的压力，才使得分布式 NoSQL 数据库得到快速发展。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;也正因为如此，NoSQL 数据库与关系型数据库的设计套路是完全不同的。关系型数据库的设计是遵循第三范式进行的，它使得数据库能够大幅度降低冗余，但又从另一个角度使得数据库查询需要频繁使用 join 操作，在高并发场景下性能低下。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;所以，NoSQL 数据库的设计思想就是尽量干掉 join 操作，即将需要 join 的查询在写入数据库表前先进行 join 操作，然后直接写到一张单表中进行&lt;a data-text-link=&quot;588_1777654&quot; data-from=&quot;10680&quot; href=&quot;https://cloud.tencent.com/product/cos?from=10680&quot; target=&quot;_blank&quot; style=&quot;text-decoration-line: none; box-sizing: border-box; list-style: inherit; color: rgb(0, 164, 255);&quot;&gt;分布式存储&lt;/a&gt;，这张表称为“宽表”。这样，在面对海量数据进行查询时，就不需要再进行 join 操作，直接在这个单表中查询。同时，因为 NoSQL 数据库自身的特点，使得它在存储为空的字段时不占用空间，不担心“表稀疏”，不影响查询性能。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;因此，NoSQL 数据库在设计时的套路就是，尽量在单表中存储更多的字段，只要避免数据查询中的 join 操作，即使出现大量为空的字段也无所谓了。&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;image-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;&lt;img src=&quot;https://ask.qcloudimg.com/http-save/7774611/vbrhxztwgk.png?imageView2/2/w/1620&quot; class=&quot;&quot; style=&quot;border: 0px; box-sizing: border-box; list-style: inherit; display: block; margin: 0px auto; max-width: 100%; max-height: 100%; box-shadow: rgba(3, 27, 78, 0.12) 0px 4px 8px; border-radius: 3px; cursor: zoom-in;&quot;/&gt;&lt;/span&gt;&lt;figcaption style=&quot;box-sizing: border-box; list-style: inherit; margin: 10px auto 16px; text-align: center; color: rgb(102, 102, 102); max-width: 61.8%;&quot;&gt;增值税发票票样图&lt;/figcaption&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;正因为 NoSQL 数据库在设计上有以上特点，因此将领域模型转换成 NoSQL 数据库时，设计就完全不一样了。比如，这样一张增值税发票，如上图所示，在数据库设计时就需要分为发票信息表、发票明细表与纳税人表，而在查询时需要进行 4 次 join 才能完成查询。但在 NoSQL 数据库设计时，将其设计成这样一张表：&lt;/p&gt;&lt;div class=&quot;developer-code-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit; position: relative; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre class=&quot;prism-token token line-numbers language-javascript&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: border-box; list-style: inherit; padding: 1em 1em 1em 3.8em; color: rgb(204, 204, 204); background-color: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; overflow-wrap: normal; word-spacing: normal; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; position: relative; counter-reset: linenumber 0;&quot;&gt;{&amp;nbsp;_id:&amp;nbsp;ObjectId(7df78ad8902c)
&amp;nbsp;&amp;nbsp;fpdm:&amp;nbsp;&amp;#39;3700134140&amp;#39;,&amp;nbsp;fphm:&amp;nbsp;&amp;#39;02309723‘,&amp;nbsp;
&amp;nbsp;&amp;nbsp;kprq:&amp;nbsp;&amp;#39;2016-1-25&amp;nbsp;9:22:45&amp;#39;,
&amp;nbsp;&amp;nbsp;je:&amp;nbsp;70451.28,&amp;nbsp;se:&amp;nbsp;11976.72,&amp;nbsp;
&amp;nbsp;&amp;nbsp;gfnsr:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nsrsbh:&amp;nbsp;&amp;#39;370112582247803&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nsrmc:&amp;#39;联通华盛通信有限公司济南分公司&amp;#39;,…&amp;nbsp;&amp;nbsp;},
&amp;nbsp;&amp;nbsp;xfnsr:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nsrsbh:&amp;nbsp;&amp;#39;370112575587500&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nsrmc:&amp;#39;联通华盛通信有限公司济南分公司&amp;#39;,…&amp;nbsp;&amp;nbsp;},
&amp;nbsp;&amp;nbsp;spmx:&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;qdbz:&amp;#39;00&amp;#39;,&amp;nbsp;wp_mc:&amp;#39;蓝牙耳机&amp;nbsp;车语者S1&amp;nbsp;蓝牙耳机&amp;#39;,&amp;nbsp;sl:2,&amp;nbsp;dj:68.37,…&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;qdbz:&amp;#39;00&amp;#39;,&amp;nbsp;wp_mc:&amp;#39;车载充电器&amp;nbsp;新在线&amp;#39;,&amp;nbsp;sl:1,&amp;nbsp;dj:11.11,…&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;qdbz:&amp;#39;00&amp;#39;,&amp;nbsp;wp_mc:&amp;#39;保护壳&amp;nbsp;非尼膜属&amp;nbsp;iPhone6&amp;nbsp;电镀壳&amp;#39;,&amp;nbsp;sl:1,&amp;nbsp;dj:24,…&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;]}&lt;/pre&gt;&lt;button class=&quot;copy&quot; style=&quot;margin: 0px; padding: 0px 0.5em; font-family: inherit; border-width: initial; border-style: none; border-color: initial; cursor: pointer; list-style: inherit; color: rgb(255, 255, 255); background-color: rgb(105, 113, 145); font-size: 0.8em; border-radius: 0.5em; z-index: 10; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0; position: absolute;&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;在该案例中，对于“一对一”和“多对一”关系，在发票信息表中通过一个类型为“对象”的字段来存储，比如“购方纳税人（gfnsr）”与“销方纳税人（xfnsr）”字段。对于“一对多”和“多对多”关系，通过一个类型为“对象数组”的字段来存储，如“商品明细（spmx）”字段。在这样一个发票信息表中就可以完成对所有发票的查询，无须再进行任何 join 操作。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;同样，采用 NoSQL 数据库怎样实现继承关系的设计呢？由于 NoSQL 数据库自身的特点决定了不用担心“表稀疏”，同时要避免 join 操作，所以比较适合采用第一个方案，即将整个继承关系放到同一张表中进行设计。这时，NoSQL 数据库的每一条记录可以有不一定完全相同的字段，可以设计成这样：&lt;/p&gt;&lt;div class=&quot;developer-code-block&quot; style=&quot;margin: 0px; padding: 0px; box-sizing: border-box; list-style: inherit; position: relative; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;pre class=&quot;prism-token token line-numbers language-javascript&quot; tabindex=&quot;0&quot; style=&quot;box-sizing: border-box; list-style: inherit; padding: 1em 1em 1em 3.8em; color: rgb(204, 204, 204); background-color: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; overflow-wrap: normal; word-spacing: normal; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; position: relative; counter-reset: linenumber 0;&quot;&gt;{&amp;nbsp;_id:&amp;nbsp;ObjectId(79878ad8902c),
&amp;nbsp;&amp;nbsp;name:&amp;nbsp;‘Jack’,
&amp;nbsp;&amp;nbsp;type:&amp;nbsp;‘parent’,
&amp;nbsp;&amp;nbsp;partner:&amp;nbsp;‘Elizabeth’,
&amp;nbsp;&amp;nbsp;children:&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;name:&amp;nbsp;‘Tom’,&amp;nbsp;gender:&amp;nbsp;‘male’&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;name:&amp;nbsp;‘Mary’,&amp;nbsp;gender:&amp;nbsp;‘female’}
&amp;nbsp;&amp;nbsp;]},{&amp;nbsp;_id:&amp;nbsp;ObjectId(79878ad8903d),
&amp;nbsp;&amp;nbsp;name:&amp;nbsp;‘Bob’,
&amp;nbsp;&amp;nbsp;type:&amp;nbsp;‘kid’,
&amp;nbsp;&amp;nbsp;mother:&amp;nbsp;‘Anna’,
&amp;nbsp;&amp;nbsp;father:&amp;nbsp;‘David’}&lt;/pre&gt;&lt;button class=&quot;copy&quot; style=&quot;margin: 0px; padding: 0px 0.5em; font-family: inherit; border-width: initial; border-style: none; border-color: initial; cursor: pointer; list-style: inherit; color: rgb(255, 255, 255); background-color: rgb(105, 113, 145); font-size: 0.8em; border-radius: 0.5em; z-index: 10; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0; position: absolute;&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;以上案例是一个用户档案表，有两条记录：Jack 与 Bob。但是，Jack 的类型是“家长”，因此其个性化字段是“伴侣”与“孩子”；而 Bob 的类型是“孩子”，因此他的个性化字段是“父亲”与“母亲”。显然，在 NoSQL 数据库设计时就会变得更加灵活。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; list-style: inherit;&quot;&gt;总结&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;figure class=&quot;&quot; style=&quot;box-sizing: border-box; list-style: inherit; margin: 16px 0px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;hr style=&quot;margin: 20px 0px; padding: 0px; box-sizing: border-box; list-style: inherit; width: 734px; height: 1px; background-color: rgb(153, 153, 153); opacity: 0.24; border: 0px none;&quot;/&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;将领域模型落地到系统设计包含 2 部分内容，本文演练了第一部分内容——从 DDD 落实到数据库设计的整个过程：传统的 4 种关系可以直接转换；继承关系有 3 种设计方案；转换成 NoSQL 数据库则是完全不同的思路。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;有了 DDD 的指导，可以帮助我们理清数据间的关系，以及对数据的操作。不仅如此，在未来面对大数据转型时更加从容。&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 8px; padding: 0px; box-sizing: border-box; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &amp;quot;pingfang SC&amp;quot;, &amp;quot;helvetica neue&amp;quot;, arial, &amp;quot;hiragino sans gb&amp;quot;, &amp;quot;microsoft yahei ui&amp;quot;, &amp;quot;microsoft yahei&amp;quot;, simsun, sans-serif; white-space: pre-wrap; background-color: rgb(255, 255, 255);&quot;&gt;号主简介：冯涛，曾任职于阿里巴巴，每日优鲜等互联网公司，任技术总监，15年电商互联网经历。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 21 Aug 2022 21:34:29 +0800</pubDate></item><item><title>devops三十六计</title><link>https://yuyunhe.cn/index.php/post/320.html</link><description>&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://yuyunhe.cn/zb_users/upload/2022/04/202204091649499111905904.jpeg&quot; title=&quot;devops三十六计.jpeg&quot; alt=&quot;devops三十六计.jpeg&quot;/&gt;&lt;/p&gt;</description><pubDate>Sat, 09 Apr 2022 18:11:38 +0800</pubDate></item><item><title>Linux Kernel map</title><link>https://yuyunhe.cn/index.php/post/319.html</link><description>&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://yuyunhe.cn/zb_users/upload/2022/04/202204091649498779453246.png&quot; title=&quot;linux kernel map.png&quot; alt=&quot;linux kernel map.png&quot;/&gt;&lt;/p&gt;</description><pubDate>Sat, 09 Apr 2022 18:05:58 +0800</pubDate></item><item><title>运维工具体系</title><link>https://yuyunhe.cn/index.php/post/318.html</link><description>&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://yuyunhe.cn/zb_users/upload/2022/04/202204091649499561204489.png&quot; title=&quot;运维工具体系.png&quot; alt=&quot;运维工具体系.png&quot;/&gt;&lt;/p&gt;</description><pubDate>Sat, 09 Apr 2022 18:03:09 +0800</pubDate></item><item><title>公共DNS</title><link>https://yuyunhe.cn/index.php/post/317.html</link><description>&lt;pre class=&quot;prism-highlight prism-language-bash&quot;&gt;阿里云：
223.6.6.6
223.5.5.5

百度：
180.76.76.76

联通：
123.125.81.6
218.30.118.6

114：
114.114.114.114&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;附：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-bash&quot;&gt;地区&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;主服务器&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;备服务器&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
北京联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.106.196.115&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.106.46.151&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
202.106.0.20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.106.195.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
重庆联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.5.203.98&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.7.92.98&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
广东联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;210.21.196.6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.5.88.88&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
河北联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.160.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.166.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
河南联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.102.224.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.102.227.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
黑龙江联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.97.224.69&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.97.224.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
吉林联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.98.0.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.98.5.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
江苏联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.6.4.66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.6.4.67&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
内蒙古联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.224.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.224.8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
山东联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.102.128.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.102.152.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
202.102.134.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.102.154.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
山西联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.192.66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.192.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
陕西联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.11.1.67&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.11.1.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
上海联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;210.22.70.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;210.22.84.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
四川联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;119.6.6.6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;124.161.87.155&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
天津联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.104.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;202.99.96.68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
浙江联通DNS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.12.1.227&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;221.12.33.227


中国公共dns
百科&amp;nbsp;&amp;gt;中国公共dns
说明：
阿里、腾讯dns不错；谷歌的8.8.8.8虽然不错，但国内访问确实不稳定，还会碰到解析记录更新不及时问题；114之前试了，正常用挺好的，但如果公司访问非常多的情况下，怀疑限频阈值较低，有时会解析不了。

为什么要用公共dns呢？那是因为使用了多家运营商商务宽带，但各运营商dns要嘛限制只对自家网络开放，要嘛限频限得非常低。这时候就需要用公共dns了，当然自己在公网内网搭建dns更好。

具体：
阿里公共DNS&amp;nbsp;
阿里公共DNS是阿里巴巴集团推出的DNS递归解析系统，目标是成为国内互联网基础设施的组成部分，面向互联网用户提供“快速”、“稳定”、“智能”的免费DNS递归解析服务.
官网：https://www.alidns.com/
IPv4首选：223.5.5.5
IPv4备用：223.6.6.6
IPv6首选：2400:3200::1
IPv6备用：2400:3200:baba::1

腾讯公共DNS（同DNSPod）
腾讯公共DNS是腾讯DNSPod&amp;nbsp;提供的公共&amp;nbsp;DNS&amp;nbsp;服务，基于&amp;nbsp;BGP&amp;nbsp;AnyCast，支持&amp;nbsp;edns-client-subnet&amp;nbsp;技术，精准调度，多地集群容灾，面向所有互联网用户免费使用。
官网：https://www.dnspod.cn/Products/Public.DNS
IPv4首选：119.29.29.29
IPv4备用：
IPv6首选：
IPv6备用：


百度公共DNS
百度公共DNS是百度系统部推出的递归DNS解析服务。拥有云防护、无劫持、更精准等特性,让您上网更快更安全。
官网：https://dudns.baidu.com/intro/publicdns/
IPv4首选：180.76.76.76
IPv4备用：
IPv6首选：2400:da00::6666
IPv6备用：

谷歌公共DNS（Google&amp;nbsp;Public&amp;nbsp;DNS）
Google&amp;nbsp;Public&amp;nbsp;DNS&amp;nbsp;是Google面对大众推出的一个公共免费域名解析服务。
官网：https://developers.google.com/speed/public-dns
IPv4首选：8.8.8.8
IPv4备用：8.8.4.4
IPv6首选：2001:4860:4860::8888
IPv6备用：2001:4860:4860::8844

114DNS：
114DNS是由多个基础电信运营商与南京信风共建共享，但由南京信风提供技术支持的公共DNS。
官网：https://www.114dns.com/about.html
IPv4首选：114.114.114.114
IPv4备用：114.114.115.115
IPv6首选：
IPv6备用：

附录：
中国电信各地DNS服务器，https://www.66office.com/article.php?id=267
中国联通各地DNS服务器，https://www.66office.com/article.php?id=266&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sat, 26 Mar 2022 09:53:12 +0800</pubDate></item><item><title>最常用的架构模式</title><link>https://yuyunhe.cn/index.php/post/316.html</link><description>&lt;blockquote style=&quot;font-variant-ligatures: none; margin: 1.6em 0px; padding: 0px 0.8em; border-width: 0px 0px 0px 4px; border-top-style: initial; border-right-style: initial; border-bottom-style: initial; border-left-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(221, 221, 221); border-image: initial; outline: 0px; font-family: Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Verdana, Tahoma, BiauKai, Kai, KaiTi, sans-serif; font-size: 16px; vertical-align: baseline; color: rgb(119, 119, 119); white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px;&quot;&gt;观其设计知其人&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px;&quot;&gt;A MAN is KNOWN by the DESIGN he keeps&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;原文:&lt;a href=&quot;https://shadman-jamil.medium.com/most-useful-software-architecture-patterns-68e171405292&quot; target=&quot;_blank&quot; rel=&quot;external&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;Most Useful Software Architecture Patterns&lt;/a&gt;&amp;nbsp;by Shadman Jamil&lt;/p&gt;&lt;p&gt;&lt;a id=&quot;more&quot; style=&quot;font-variant-ligatures: none; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; color: rgb(227, 45, 64); white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-variant-ligatures: none; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/Software-Architecture.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/Software-Architecture.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2 id=&quot;分层模式_(Layered_Pattern_(n-tier))&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;分层模式 (Layered Pattern (n-tier))&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;分层架构模式是最常见的模式之一。分层模式背后的理念是，具有相同功能的组件将被组织成水平层。因此，每一层在应用程序中都扮演着特定的角色。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在这种模式中，我们对应用程序可以拥有的层数没有限制。在这方面，我们还提倡关注点分离的概念。分层模式风格抽象了整个软件的视图；同时提供足够的细节，以了解各个层的角色和职责以及它们之间的关系。分层模式的典型实现如下：&lt;/p&gt;&lt;ul style=&quot;list-style-type: none;&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;UI展示层(&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;UI / Presentation Layer&lt;/strong&gt;): 渲染并运行用户界面，向服务器应用程序发送请求。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;应用层(&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;Application Layer&lt;/strong&gt;): 包含表示层、应用程序层、域对象层和持久化层。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;域对象层/业务层(&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;Domain / Business Layer&lt;/strong&gt;): 该层包含所有业务逻辑、实体、事件和其他包含业务逻辑的对象类型。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;数据库层(&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;Database Layer&lt;/strong&gt;): 这是数据层，用于持久化数据，应用服务器将使用这些数据。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/layers.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/layers.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 桌面应用程序、电子商务、web应用程序等。&lt;/p&gt;&lt;blockquote style=&quot;font-variant-ligatures: none; margin: 1.6em 0px; padding: 0px 0.8em; border-width: 0px 0px 0px 4px; border-top-style: initial; border-right-style: initial; border-bottom-style: initial; border-left-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(221, 221, 221); border-image: initial; outline: 0px; font-family: Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Verdana, Tahoma, BiauKai, Kai, KaiTi, sans-serif; font-size: 16px; vertical-align: baseline; color: rgb(119, 119, 119); white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px;&quot;&gt;参考例子：&amp;nbsp;&lt;a href=&quot;https://github.com/bxcodec/go-clean-arch&quot; target=&quot;_blank&quot; rel=&quot;external&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;go-clean-arch&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2 id=&quot;客户端-服务器模式_(Client-Server_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;客户端-服务器模式 (Client-Server Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;这是最简单的架构模式，由一台服务器和多个客户端组成。这种模式是一种分布式架构，在资源/服务的提供者（称为服务器）和服务请求者（称为客户端）之间划分任务/工作负载。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在客户端-服务器模式中，当客户端向服务器发送数据请求时，服务器接受请求的进程，并向客户机发送所需的数据。客户不共享他们的任何资源。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/client-server.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/client-server.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: Email、文档共享、银行等&lt;/p&gt;&lt;h2 id=&quot;事件总线模式_(Event-Bus_Pattern_(Event-Driven_Architecture))&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;事件总线模式 (Event-Bus Pattern (Event-Driven Architecture))&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;该模式是一种分布式异步体系架构模式，用于创建高度可扩展的响应式应用程序。适用于从小型到复杂的各级应用程序技术栈。此模式的主要思想是异步传递和处理事件。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;这个模式包含四个组件:&lt;/p&gt;&lt;ol style=&quot;font-variant-ligatures: none; margin: 0.8em 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; list-style-position: initial; list-style-image: initial; line-height: 2em; counter-reset: item 0; white-space: normal; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;事件源(Event Source)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;事件监听器(Event Listener)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;通道(Channel)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;事件总线(Event Bus)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;源将消息发布到事件总线上的特定通道。监听器订阅特定的频道，监听器可以获取发布到其订阅的频道的消息。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/event-source.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/event-source.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 电子商务、手机应用程序、通知服务等&lt;/p&gt;&lt;h2 id=&quot;代理人模式(Broker_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;代理人模式(Broker Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;此模式可用于构造具有通过远程服务调用进行交互的解耦组件的分布式系统。代理组件负责协调组件之间的通信；例如转发请求，以及传输结果和异常。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;服务器&lt;/strong&gt;将其能力（服务和特性）发布给&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;代理&lt;/strong&gt;(Broker)。&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;客户端&lt;/strong&gt;向&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;代理&lt;/strong&gt;请求服务，然后&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;代理&lt;/strong&gt;将&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;客户端&lt;/strong&gt;的请求重定向到合适的服务。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/broker.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/broker.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 消息Broker程序，如Apache ActiveMQ、Apache Kafka、RabbitMQ、JBOSS Messaging等&lt;/p&gt;&lt;h2 id=&quot;微服务模式_(Microservices_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;微服务模式 (Microservices Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在这种模式中，服务通过使用HTTP/REST等同步协议或AMQP（高级消息队列协议）等异步协议进行通信。服务可以独立开发和部署，每个服务都有自己的数据库。服务之间的数据一致性是通过使用Saga模式（一系列本地事务）来维护的。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/microservices.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/microservices.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 可以在许多用例上实现，尤其是广泛的数据管道处理上&lt;/p&gt;&lt;h2 id=&quot;点对点模式_(Peer-to-Peer_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;点对点模式 (Peer-to-Peer Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在通用客户端-服务器体系架构中，多个客户端与中央服务器通信。但P2P模式由分散的对等网络组成。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在这种模式中，节点的行为类似于客户端和服务器。对等点既可以作为客户端向其他对等点请求服务，也可以作为服务器向其他对等点提供服务。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;P2P网络在节点之间分配工作负载，所有节点贡献并消耗网络中的资源，而不需要集中的服务器。对等方可能会随着时间动态地改变其角色。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/peer-2-peer.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/peer-2-peer.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 文件分享网络、多媒体协议PDTP,P2PTV、比特币、区块链等&lt;/p&gt;&lt;h2 id=&quot;黑板模式(Blackboard_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;黑板模式(Blackboard Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;这种模式对于不知道确定性解决方案策略的问题很有用。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;所有部件都可以接触到黑板。组件可能会产生新的数据对象，这些对象将被添加到黑板上。组件在黑板上寻找特定类型的数据，并通过与现有知识源的模式匹配找到这些数据。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;这个模式包含三个组件：&lt;/p&gt;&lt;ul style=&quot;list-style-type: none;&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;黑板(blackboard): 含解决方案空间中的对象的结构化全局内存&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;知识源(knowledge source:):具有自己表示形式的专用模块&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;控制组件(control component):选择、配置和执行模块。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/blackboard.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/blackboard.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 速度识别、蛋白质结构识别、声纳信号解释、机器学习程序等。&lt;/p&gt;&lt;h2 id=&quot;组件模式_(Component-based_Pattern)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;组件模式 (Component-based Pattern)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;基于组件的软件工程（Component-based software engineering，简称CBSE）或基于组件的开发（Component-Based Development，简称CBD）是针对系统的广泛功能，进行关注点分离的软件工程方式。此方式是以复用为基础的作法，定义、实现许多松耦合的独立组件（Component），再将组件组合成为系统。此作法的目的是希望在软件本身的短期益处以及开发软件组织的长期益处之间获取平衡。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;一旦组件进行了划分，可以将组件分布式的开发部署，就会演化成面向服务或者微服务的架构。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/component-based.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/component-based.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 常见大型项目中或者单个服务中。&lt;/p&gt;&lt;h2 id=&quot;管道模式_(Pipes_和_filters)&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;管道模式 (Pipes 和 filters)&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;管道(pipeline)由一系列处理元素（进程、线程、协同程序、函数等）组成，每个元素的输出都是下一个元素的输入；这个名字类似于一个物理管道。通常在连续元素之间提供一定量的缓冲。在这些管道中流动的信息通常是记录流、字节流或比特流，管道中的元素可以称为过滤器(filter)；这也称为管道和过滤器设计模式。将元素连接到管道中类似于函数合成。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;管道模式可以将数据的处理解耦，并且可以动态的增加或者删除特定的处理流程。每个处理单元可以结合下面插件模式，实现定制化。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/pipeline.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/pipeline.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: 多任务操作系统、数据处理程序等。&lt;/p&gt;&lt;h2 id=&quot;插件模式&quot; style=&quot;font-variant-ligatures: none; margin: 2.2em 0px 1.1em; padding: 0px 0px 5px; border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: solid; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(204, 204, 204); border-left-color: initial; border-image: initial; outline: 0px; font-family: &amp;quot;Droid Serif&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Georgia, serif; font-size: 1.6em; vertical-align: baseline; line-height: 1.1em; counter-reset: section 0; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;插件模式&lt;/h2&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;在计算技术中，插件（或插件、外接程序、外接程序、外接程序或外接程序）是一种软件组件，用于向现有计算机程序添加特定功能。当程序支持插件时，它会启用自定义功能。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;插件模式可以方便对程序进行扩展，以及动态实现功能的开启和禁用等功能，方便进行定制化。&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/plugin.png&quot; title=&quot;&quot; class=&quot;fancybox&quot; rel=&quot;article0&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(227, 45, 64); text-decoration-line: none;&quot;&gt;&lt;img src=&quot;https://colobu.com/2022/03/06/most-useful-software-architecture-patterns/plugin.png&quot; alt=&quot;&quot; style=&quot;margin: auto; padding: 0px; border: none; outline: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; max-width: 100%; height: auto; display: block;&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-variant-ligatures: none; margin-top: 0px; margin-bottom: 20px; padding: 0px; border: 0px; outline: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; vertical-align: baseline; letter-spacing: 0.01rem; line-height: 2em; text-shadow: rgba(0, 0, 0, 0.22) 0px 0px 1px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 2px 4px; border-width: 0.25em 0px; border-style: initial; border-color: initial; border-image: initial; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 255); background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));&quot;&gt;例子&lt;/strong&gt;: IDE程序如Eclipse，IDEA Intellj、网络应用程序入netty等。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 08 Mar 2022 19:00:56 +0800</pubDate></item><item><title>什么是“堆”,&amp;quot;栈&amp;quot;,&amp;quot;堆栈&amp;quot;,&amp;quot;队列&amp;quot;,它们的区别</title><link>https://yuyunhe.cn/index.php/post/315.html</link><description>&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;如果你学过数据结构，就一定会遇到“堆”,&amp;quot;栈&amp;quot;,&amp;quot;堆栈&amp;quot;,&amp;quot;队列&amp;quot;，而最关键的是这些到底是什么意思？最关键的是即使你去面试，这些都还会问到，所以如果你不懂对你是损失很大的。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;堆栈都是一种&lt;a class=&quot;ed_inner_link&quot; href=&quot;http://baike.sogou.com/v452927.htm&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; style=&quot;margin: 0px; padding: 0px; outline: none; color: rgb(0, 0, 0);&quot;&gt;数据项&lt;/a&gt;按序排列的数据结构，只能在一端(称为栈顶(top))对数据项进行插入和删除。&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;要点：堆：顺序随意 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/strong&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;栈：后进先出(Last-In/First-Out)&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328152800878-1759144630.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;&amp;nbsp;堆 &amp;nbsp;&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;堆：什么是堆？又该怎么理解呢？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①堆通常是一个可以被看做一棵树的数组对象。堆总是满足下列性质：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp; &amp;nbsp;·堆中某个节点的值总是不大于或不小于其父节点的值；&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp; &amp;nbsp;·堆总是一棵完全二叉树。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;将根节点最大的堆叫做最大堆或大根堆，根节点最小的堆叫做最小堆或小根堆。常见的堆有二叉堆、斐波那契堆等。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②堆是在程序运行时，而不是在程序编译时，申请某个大小的内存空间。即动态分配内存，对其访问和对一般内存的访问没有区别。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;③堆是应用程序在运行的时候请求操作系统分配给自己内存，一般是申请/给予的过程。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;④堆是指程序运行时申请的动态内存，而栈只是指一种使用堆的方法(即先进后出)。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328152928283-1458291999.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;栈&amp;nbsp;&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;栈：什么是栈？又该怎么理解呢？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①栈（stack）又名堆栈，它是一种运算受限的线性表。其限制是仅允许在表的一端进行插入和删除运算。这一端被称为栈顶，相对地，把另一端称为栈底。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②栈就是一个桶，后放进去的先拿出来，它下面本来有的东西要等它出来之后才能出来（先进后出）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;③栈(Stack)是操作系统在建立某个进程时或者线程（在支持多线程的操作系统中是线程）为这个线程建立的存储区域，该区域具有FIFO的特性，在编译的时候可以指定需要的Stack的大小。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153013201-1156246616.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;堆栈 &amp;nbsp;&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;堆栈：什么是堆栈？又该怎么理解呢？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;注意：其实堆栈本身就是栈，只是换了个抽象的名字。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;堆栈的特性： 最后一个放入堆栈中的物体总是被最先拿出来， 这个特性通常称为后进先出(LIFO)队列。 堆栈中定义了一些操作。 两个最重要的是PUSH和POP。 PUSH操作在堆栈的顶部加入一 个元素。POP操作相反， 在堆栈顶部移去一个元素， 并将堆栈的大小减一。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153049383-817765669.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;总结：&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;堆、栈区别总结：&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;1.堆栈空间分配&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;①栈（操作系统）：由操作系统自动分配释放 ，存放函数的参数值，局部变量的值等。其操作方式类似于数据结构中的栈。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;②堆（操作系统）： 一般由程序员分配释放， 若程序员不释放，程序结束时可能由OS回收，分配方式倒是类似于链表。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;2.堆栈缓存方式&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①栈使用的是一级缓存， 他们通常都是被调用时处于存储空间中，调用完毕立即释放。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②堆则是存放在二级缓存中，生命周期由虚拟机的垃圾回收算法来决定（并不是一旦成为孤儿对象就能被回收）。所以调用这些对象的速度要相对来得低一些。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;3.堆栈数据结构区别&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①堆（数据结构）：堆可以被看成是一棵树，如：堆排序。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②栈（数据结构）：一种先进后出的数据结构。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153151707-229802975.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;队列：&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;队列：什么是队列？又该怎么理解呢？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①队列是一种特殊的线性表，特殊之处在于它只允许在表的前端（front）进行删除操作，而在表的后端（rear）进行插入操作，和栈一样，队列是一种操作受限制的线性表。进行插入操作的端称为队尾，进行删除操作的端称为队头。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②队列中没有元素时，称为空队列。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;③建立顺序队列结构必须为其静态分配或动态申请一片连续的存储空间，并设置两个指针进行管理。一个是队头指针front，它指向队头元素；另一个是队尾指针rear，它指向下一个入队元素的存储位置。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;④队列采用的FIFO(first in first out)，新元素（等待进入队列的元素）总是被插入到链表的尾部，而读取的时候总是从链表的头部开始读取。每次读取一个元素，释放一个元素。所谓的动态创建，动态释放。因而也不存在溢出等问题。由于链表由结构体间接而成，遍历也方便。（先进先出）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153408473-245621412.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;margin: 10px 0px 12px; padding: 0px 0px 0px 15px; font-size: 21px; line-height: 1.5; background-color: rgb(0, 143, 198); border-radius: 3px; text-align: center; color: white; text-shadow: rgb(34, 34, 34) 1px 1px 2px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal;&quot;&gt;区别:&amp;nbsp;&lt;/h2&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;堆、栈、队列之间的区别是？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;①堆是在程序运行时，而不是在程序编译时，申请某个大小的内存空间。即动态分配内存，对其访问和对一般内存的访问没有区别。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;②栈就是一个桶，后放进去的先拿出来，它下面本来有的东西要等它出来之后才能出来。（后进先出）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;③队列只能在队头做删除操作,在队尾做插入操作.而栈只能在栈顶做插入和删除操作。（先进先出）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: 16px;&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153434044-982202731.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: none; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 10px auto; padding: 0px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Verdana, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://images2018.cnblogs.com/blog/1308093/201803/1308093-20180328153508171-543933965.png&quot; alt=&quot;&quot; class=&quot;medium-zoom-image&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; max-width: 700px; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 11 Feb 2022 19:04:32 +0800</pubDate></item><item><title>Vue 加载本地Excel实时预览</title><link>https://yuyunhe.cn/index.php/post/314.html</link><description>&lt;pre class=&quot;prism-highlight prism-language-markup&quot;&gt;#template

&amp;lt;template&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;type=&amp;quot;file&amp;quot;&amp;nbsp;id=&amp;quot;files&amp;quot;&amp;nbsp;ref=&amp;quot;upload&amp;quot;&amp;nbsp;accept=&amp;quot;.xls,.xlsx&amp;quot;&amp;nbsp;style=&amp;quot;display:&amp;nbsp;none&amp;quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;el-button&amp;nbsp;slot=&amp;quot;trigger&amp;quot;&amp;nbsp;type=&amp;quot;warning&amp;quot;&amp;nbsp;@click=&amp;quot;clickLoad&amp;quot;&amp;nbsp;style=&amp;quot;margin-right:&amp;nbsp;20px&amp;quot;&amp;gt;从Excel加载&amp;lt;/el-button&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;


methods(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;clickLoad()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$refs.upload.dispatchEvent(new&amp;nbsp;MouseEvent(&amp;#39;click&amp;#39;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;readExcel(e)&amp;nbsp;{//表格导入
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;that&amp;nbsp;=&amp;nbsp;this;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;files&amp;nbsp;=&amp;nbsp;e.target.files;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;validRule&amp;nbsp;=&amp;nbsp;/\.(xls|xlsx)$/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(files.length&amp;nbsp;&amp;lt;=&amp;nbsp;0)&amp;nbsp;{//如果没有文件名
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(!validRule.test(files[0].name.toLowerCase()))&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$Message.error(&amp;#39;上传格式不正确，请上传xls或者xlsx格式&amp;#39;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;fileReader&amp;nbsp;=&amp;nbsp;new&amp;nbsp;FileReader();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fileReader.onload&amp;nbsp;=&amp;nbsp;(e)&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;data&amp;nbsp;=&amp;nbsp;e.target.result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;workData&amp;nbsp;=&amp;nbsp;XLSX.read(data,&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type:&amp;nbsp;&amp;#39;binary&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;console.log(workData)//&amp;nbsp;文件的内容
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;wsName&amp;nbsp;=&amp;nbsp;workData.SheetNames[0];//取第一张表
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;ws&amp;nbsp;=&amp;nbsp;XLSX.utils.sheet_to_json(workData.Sheets[wsName]);//生成json表格内容
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;console.log(ws);&amp;nbsp;&amp;nbsp;//自第二行开始的内容
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//{&amp;nbsp;&amp;nbsp;这里可以做相应的处理&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//{&amp;nbsp;&amp;nbsp;这里可以做相应的处理&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;console.log(&amp;quot;table:&amp;quot;,&amp;nbsp;this.tablesData)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(let&amp;nbsp;i&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;this.tablesData.length;&amp;nbsp;i++)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;item&amp;nbsp;=&amp;nbsp;this.tablesData[i]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;allKey&amp;nbsp;=&amp;nbsp;Object.keys(item)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(let&amp;nbsp;j&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;j&amp;nbsp;&amp;lt;&amp;nbsp;ws.length;&amp;nbsp;j++)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;item2&amp;nbsp;=&amp;nbsp;ws[j]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;key1&amp;nbsp;=&amp;nbsp;item[&amp;#39;a&amp;#39;]&amp;nbsp;+&amp;nbsp;&amp;quot;_&amp;quot;&amp;nbsp;+&amp;nbsp;item[&amp;#39;b&amp;#39;]&amp;nbsp;+&amp;nbsp;&amp;quot;_&amp;quot;&amp;nbsp;+&amp;nbsp;item[&amp;#39;c&amp;#39;]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;let&amp;nbsp;key2&amp;nbsp;=&amp;nbsp;item2[&amp;#39;a&amp;#39;]&amp;nbsp;+&amp;nbsp;&amp;quot;_&amp;quot;&amp;nbsp;+&amp;nbsp;item2[&amp;#39;b&amp;#39;]&amp;nbsp;+&amp;nbsp;&amp;quot;_&amp;quot;&amp;nbsp;+&amp;nbsp;item2[&amp;#39;c&amp;#39;]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(key1&amp;nbsp;===&amp;nbsp;key2)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(let&amp;nbsp;key&amp;nbsp;of&amp;nbsp;allKey)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//只对20开头的key做值更新
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(key.indexOf(&amp;quot;20&amp;quot;)&amp;nbsp;===&amp;nbsp;0)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(&amp;quot;key1:&amp;quot;,&amp;nbsp;key1,&amp;nbsp;&amp;quot;key2:&amp;quot;,&amp;nbsp;key2,&amp;nbsp;&amp;quot;key:&amp;quot;,&amp;nbsp;key,&amp;nbsp;&amp;quot;value:&amp;quot;,&amp;nbsp;item2[key])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$set(this.tablesData[i],&amp;nbsp;key,&amp;nbsp;item2[key])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$refs.upload.value&amp;nbsp;=&amp;nbsp;&amp;#39;&amp;#39;;&amp;nbsp;//&amp;nbsp;处理完成&amp;nbsp;清空表单值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$message.error(&amp;quot;解析表格失败&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fileReader.readAsBinaryString(files[0]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

},

mounted(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//注册事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.$refs.upload.addEventListener(&amp;#39;change&amp;#39;,&amp;nbsp;e&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.readExcel(e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;})
}&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Mon, 24 Jan 2022 19:40:49 +0800</pubDate></item></channel></rss>