fastApiProject/content.json

1 line
1.0 MiB
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{"meta":{"title":"龙儿之家","subtitle":"hexo.huangge1199.cn","description":"千里之行,始于足下","author":"轩辕龙儿","url":"https://hexo.huangge1199.cn","root":"/"},"pages":[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}],"posts":[{"title":"element-plus选择器自定义筛选方法拼音首字母搜索","slug":"element-plusxuan-ze-qi-zi-ding-yi-shai-xuan-fang-fa-pin-yin-shou-zi-mu-sou-suo","date":"2024-07-05T06:05:35.000Z","updated":"2024-07-05T06:54:48.906Z","comments":true,"path":"/post/element-plusxuan-ze-qi-zi-ding-yi-shai-xuan-fang-fa-pin-yin-shou-zi-mu-sou-suo/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>最近,来了个需求,需要在下拉列表中做筛选。下拉列表显示的是中文,但筛选时可能会输入中文的拼音首字母。因此,需要实现一个筛选功能,能够根据拼音首字母筛选出匹配的选项。</p>\n<h1 id=\"自定义筛选方法\"><a href=\"#自定义筛选方法\" class=\"headerlink\" title=\"自定义筛选方法\"></a>自定义筛选方法</h1><p>前端使用的是 <a href=\"https://cn.vuejs.org/guide/introduction.html\">vue3</a> 和 <a href=\"https://element-plus.org/zh-CN/component/overview.html\">element-plus</a>。我使用的组件是 <a href=\"https://element-plus.org/zh-CN/component/select.html\">Select 选择器 | Element Plus</a> 。为 <code>el-select</code> 添加 <code>filterable</code> 属性即可启用搜索功能。默认情况下Select 会找出所有 <code>label</code> 属性包含输入值的选项。但这里需要匹配拼音首字母进行搜索,因此要通过传入一个 <code>filter-method</code> 来实现。<code>filter-method</code> 是一个函数,它会在输入值发生变化时调用,参数为当前输入值。</p>\n<p>下面是这部分的简短代码:</p>\n<p>vue部分</p>\n<pre class=\"line-numbers language-vue\" data-language=\"vue\"><code class=\"language-vue\">&lt;el-select\n v-model&#x3D;&quot;queryParams.word&quot;\n filterable\n placeholder&#x3D;&quot;请输入&quot;\n clearable\n :filter-method&#x3D;&quot;filterMethod&quot;\n &gt;\n &lt;el-option\n v-for&#x3D;&quot;word in words&quot;\n :key&#x3D;&quot;word&quot;\n :label&#x3D;&quot;word&quot;\n :value&#x3D;&quot;word&quot;\n &#x2F;&gt;\n&lt;&#x2F;el-select&gt;&#x2F;el-form-item&gt;</code></pre>\n<p>JS部分</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">const showSearch &#x3D; ref(true);\n&#x2F;&#x2F; option选项\nconst words &#x3D; ref([&#39;你好&#39;, &#39;世界&#39;, &#39;中国&#39;, &#39;中国最棒&#39;])\n&#x2F;&#x2F; 保留原始的option选项\nconst wordsOld &#x3D; ref([&#39;你好&#39;, &#39;世界&#39;, &#39;中国&#39;, &#39;中国最棒&#39;])\n\nconst data &#x3D; reactive(&#123;\n queryParams: &#123;\n word: null,\n &#125;,\n&#125;);\n\nconst &#123; queryParams &#125; &#x3D; toRefs(data);\n\n&#x2F;&#x2F; 多选框选中数据\nfunction filterMethod(val)&#123;\n &#x2F;&#x2F; 如果有输入值,根据输入内容进行筛选\n if(val)&#123;\n &#x2F;&#x2F; 先将option中的选项words清空\n words.value &#x3D; []\n &#x2F;&#x2F; 从原始的option选项中遍历筛选\n wordsOld.value.forEach(word &#x3D;&gt; &#123;\n &#x2F;&#x2F; 添加筛选逻辑满足的word添加到words中显示\n words.value.push(word)\n &#125;)\n &#125; else &#123;\n &#x2F;&#x2F; 如果没有输入值恢复成原始的option选项\n words.value &#x3D; wordsOld.value\n &#125;\n&#125;</code></pre>\n<h1 id=\"拼音首字母匹配\"><a href=\"#拼音首字母匹配\" class=\"headerlink\" title=\"拼音首字母匹配\"></a>拼音首字母匹配</h1><p>可以使用 <code>pinyin-pro</code> 来实现拼音匹配,例子如下:</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">import &#123; pinyin &#125; from &#39;pinyin-pro&#39;;\n\nconst word &#x3D; ref(&#39;中国最棒&#39;)\n\nconst firstLetterPinyin &#x3D; pinyin(word, &#123; pattern: &#39;first&#39; &#125;).replace(&#x2F;\\s+&#x2F;g, &#39;&#39;);\nif(firstLetterPinyin.includes(queryLower))&#123;\n words.value.push(word)\n&#125;</code></pre>\n<p><code>pinyin</code> 方法使用 <code>pinyin-pro</code> 库将汉字转换为指定样式的拼音字符串。这里面first样式为获取每一个字的小写拼音首字母中间用空格分割而我匹配时不需要空格因此在<code>firstLetterPinyin</code>设值时添加了<code>replace(/\\s+/g, &#39;&#39;)</code>将转换的字符串去除空格。</p>\n<h1 id=\"完整的vue代码\"><a href=\"#完整的vue代码\" class=\"headerlink\" title=\"完整的vue代码\"></a>完整的vue代码</h1><pre class=\"line-numbers language-vue\" data-language=\"vue\"><code class=\"language-vue\">&lt;template&gt;\n &lt;div class&#x3D;&quot;app-container&quot;&gt;\n &lt;el-form :model&#x3D;&quot;queryParams&quot; ref&#x3D;&quot;queryRef&quot; :inline&#x3D;&quot;true&quot; v-show&#x3D;&quot;showSearch&quot;&gt;\n &lt;el-form-item label&#x3D;&quot;中文拼音匹配选择器&quot;&gt;\n &lt;el-select\n v-model&#x3D;&quot;queryParams.word&quot;\n filterable\n placeholder&#x3D;&quot;请输入&quot;\n clearable\n :filter-method&#x3D;&quot;filterMethod&quot;\n &gt;\n &lt;el-option\n v-for&#x3D;&quot;word in words&quot;\n :key&#x3D;&quot;word&quot;\n :label&#x3D;&quot;word&quot;\n :value&#x3D;&quot;word&quot;\n &#x2F;&gt;\n &lt;&#x2F;el-select&gt;\n &lt;&#x2F;el-form-item&gt;\n &lt;&#x2F;el-form&gt;\n &lt;&#x2F;div&gt;\n&lt;&#x2F;template&gt;\n\n&lt;script setup name&#x3D;&quot;word&quot;&gt;\nimport &#123; pinyin &#125; from &#39;pinyin-pro&#39;;\n\nconst showSearch &#x3D; ref(true);\nconst words &#x3D; ref([&#39;你好&#39;, &#39;世界&#39;, &#39;中国&#39;, &#39;中国最棒&#39;])\nconst wordsOld &#x3D; ref([&#39;你好&#39;, &#39;世界&#39;, &#39;中国&#39;, &#39;中国最棒&#39;])\n\nconst data &#x3D; reactive(&#123;\n queryParams: &#123;\n word: null,\n &#125;,\n&#125;);\n\nconst &#123; queryParams &#125; &#x3D; toRefs(data);\n\n&#x2F;&#x2F; 多选框选中数据\nfunction filterMethod(val)&#123;\n if(val)&#123;\n const queryLower &#x3D; val.toLowerCase();\n words.value &#x3D; []\n\n &#x2F;&#x2F; 筛选拼音首字母包含输入内容的选项\n wordsOld.value.forEach(word &#x3D;&gt; &#123;\n const firstLetterPinyin &#x3D; convertToPinyin(word, &#39;first&#39;).replace(&#x2F;\\s+&#x2F;g, &#39;&#39;);\n if(firstLetterPinyin.includes(queryLower))&#123;\n words.value.push(word)\n &#125;\n &#125;)\n &#x2F;&#x2F; 筛选选包含输入内容的选项\n wordsOld.value.forEach(word &#x3D;&gt; &#123;\n if(word.includes(val))&#123;\n words.value.push(word)\n &#125;\n &#125;)\n &#125; else &#123;\n words.value &#x3D; wordsOld.value\n &#125;\n&#125;\n\nfunction convertToPinyin(word, type) &#123;\n return pinyin(word, &#123; pattern: type &#125;);\n&#125;\n&lt;&#x2F;script&gt;</code></pre>\n<p>代码解析:</p>\n<ol>\n<li><p><strong>模板部分</strong></p>\n<ul>\n<li>使用 <code>el-select</code> 组件并启用 <code>filterable</code> 属性。</li>\n<li>通过 <code>v-for</code> 渲染选项列表。</li>\n</ul>\n</li>\n<li><p><strong>脚本部分</strong></p>\n<ul>\n<li>导入 <code>ref</code>, <code>reactive</code>, <code>toRefs</code> 从 Vue 中管理状态。</li>\n<li>导入 <code>pinyin-pro</code> 库进行拼音转换。</li>\n<li>定义原始选项列表 <code>wordsOld</code> 和当前选项列表 <code>words</code>。</li>\n<li>定义一个响应式对象 <code>data</code> 存储查询参数。</li>\n<li>实现 <code>filterMethod</code> 函数,根据输入值筛选匹配的选项,包括拼音首字母和汉字匹配。</li>\n</ul>\n</li>\n</ol>\n<p>以上代码实现了一个带拼音首字母匹配功能的下拉选择器,能有效地根据用户输入进行筛选。</p>\n","categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"前端/vue","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/vue/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/tags/vue/"}]},{"title":"Java实现RS485串口通信","slug":"javashi-xian-rs485chuan-kou-tong-xin","date":"2024-06-24T10:10:11.000Z","updated":"2024-06-24T05:42:44.020Z","comments":true,"path":"/post/javashi-xian-rs485chuan-kou-tong-xin/","link":"","excerpt":"","content":"<p>近期我接到了一个任务将报警器接入到Java项目中而接入的方式就是通过RS485接入本人之前可以说是对此毫无所知。不过要感谢现在的互联网通过网络我查到了我想要知道的一切这里记录下本次学习的情况供大家参考</p>\n<h1 id=\"一、RS485简单介绍\"><a href=\"#一、RS485简单介绍\" class=\"headerlink\" title=\"一、RS485简单介绍\"></a>一、RS485简单介绍</h1><p>RS485是一种常用的串行通信标准广泛应用于工业自动化和嵌入式系统。它采用差分信号传输具有抗干扰能力强、传输距离远等优点。以下是关于RS485串口的一些关键点</p>\n<h2 id=\"1、硬件连接\"><a href=\"#1、硬件连接\" class=\"headerlink\" title=\"1、硬件连接\"></a>1、硬件连接</h2><ul>\n<li><p>RS485使用差分信号传输通常需要使用收发器如MAX485芯片将串口的TTL信号转换为RS485信号</p>\n</li>\n<li><p>可以使用USB转RS485转换器实现与计算机的连接</p>\n</li>\n</ul>\n<h2 id=\"2、通信方式\"><a href=\"#2、通信方式\" class=\"headerlink\" title=\"2、通信方式\"></a>2、通信方式</h2><ul>\n<li><p>RS485支持半双工通信即发送和接收不能同时进行通常需要软件控制来实现发送和接收的切换</p>\n</li>\n<li><p>通过两个数据线进行通信数据线为A和BA为正B为负</p>\n</li>\n</ul>\n<h2 id=\"3、数据发送和接收\"><a href=\"#3、数据发送和接收\" class=\"headerlink\" title=\"3、数据发送和接收\"></a>3、数据发送和接收</h2><ul>\n<li><p>在数据发送时控制器的TX信号经过收发器转换成差分信号传输到总线上</p>\n</li>\n<li><p>接收时差分信号通过收发器转换为TTL信号再传输给控制器的RX端口</p>\n</li>\n<li><p>数据传输速率可以根据具体应用需求进行调整常见的波特率有9600、19200等</p>\n</li>\n</ul>\n<h1 id=\"二、电脑需要做的准备\"><a href=\"#二、电脑需要做的准备\" class=\"headerlink\" title=\"二、电脑需要做的准备\"></a>二、电脑需要做的准备</h1><p>Windows系统还好需要一个USB转RS485的转换器就可以了基本不需要额外安装什么其他的。Linux系统可能就麻烦些除了一个USB转RS485的转换器外可能还需要下载相应的驱动Linux这部分本人未实际操作全凭网上的资料。当然如果你的电脑或者是设备本身就带RS485串口那就方便了直接接上就好。</p>\n<p>接线方面A接T+B接T-</p>\n<h1 id=\"三、代码方面\"><a href=\"#三、代码方面\" class=\"headerlink\" title=\"三、代码方面\"></a>三、代码方面</h1><p>本人使用的是Springboot项目通过网上的查询可以使用 <code>jSerialComm</code> 或 <code>RXTX</code> 库来实现串口通信。</p>\n<h2 id=\"1、jSerialComm\"><a href=\"#1、jSerialComm\" class=\"headerlink\" title=\"1、jSerialComm\"></a>1、jSerialComm</h2><p>本人觉得使用这个库相对简单些直接在pom文件引入依赖就可以了依赖代码如下</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;dependency&gt;\n &lt;groupId&gt;com.fazecast&lt;&#x2F;groupId&gt;\n &lt;artifactId&gt;jSerialComm&lt;&#x2F;artifactId&gt;\n &lt;version&gt;2.9.2&lt;&#x2F;version&gt;\n&lt;&#x2F;dependency&gt;</code></pre>\n<h2 id=\"2、RXTX\"><a href=\"#2、RXTX\" class=\"headerlink\" title=\"2、RXTX\"></a>2、RXTX</h2><p>这个尼个人觉得相对复杂些首先要先去下载RXTX的jar包(<a href=\"http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip\">rxtx-2.1-7-bins-r2</a>)在使用时除了在pom文件中引入压缩包内的<code>RXTXcomm.jar</code>包外,还需要在系统<code>%JAVA_HOME%/jre/bin</code>目录下放入对应的文件比如说Windows的需要放入<code>rxtxParallel.dll</code>和<code>rxtxSerial.dll</code>两个文件</p>\n<p>压缩包内容:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/javashi-xian-rs485chuan-kou-tong-xin/2024-06-24-11-58-06-image.png\" alt=\"\"></p>\n<h2 id=\"3、代码例子\"><a href=\"#3、代码例子\" class=\"headerlink\" title=\"3、代码例子\"></a>3、代码例子</h2><p>我这边用的<code>jSerialComm</code>的方式引入jar包后Java的测试代码如下</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import com.fazecast.jSerialComm.SerialPort;\n\npublic class RS485Communication &#123;\n public static void main(String[] args) &#123;\n &#x2F;&#x2F;SerialPort[] commPorts &#x3D; SerialPort.getCommPorts();\n &#x2F;&#x2F;if (commPorts.length &#x3D;&#x3D; 0) &#123;\n &#x2F;&#x2F; log.error(&quot;设备未插入!&quot;);\n &#x2F;&#x2F;&#125;\n\t\t&#x2F;&#x2F;SerialPort serialPort &#x3D; null;\n &#x2F;&#x2F;if(SystemUtils.isLinux())&#123;\n &#x2F;&#x2F; for (SerialPort commPort : commPorts) &#123;\n &#x2F;&#x2F; log.info(JSON.toJSONString(commPort));\n &#x2F;&#x2F; if(commPort.getSystemPortName().equals(&quot;ttyS2&quot;))&#123;\n &#x2F;&#x2F; serialPort &#x3D; commPort;\n &#x2F;&#x2F; &#125;\n &#x2F;&#x2F; &#125;\n &#x2F;&#x2F;&#125; else &#123;\n &#x2F;&#x2F; for (SerialPort commPort : commPorts) &#123;\n &#x2F;&#x2F; log.info(JSON.toJSONString(commPort));\n &#x2F;&#x2F; if(commPort.getSystemPortName().contains(&quot;COM&quot;))&#123;\n &#x2F;&#x2F; serialPort &#x3D; commPort;\n &#x2F;&#x2F; &#125;\n &#x2F;&#x2F; &#125;\n &#x2F;&#x2F;&#125;\n\t &#x2F;&#x2F; 这里取的是第一个,如果你有多个,可以通过注释的代码来确定你使用的是哪一个\n SerialPort serialPort &#x3D; SerialPort.getCommPorts()[0];\n serialPort.setBaudRate(9600);\n serialPort.setNumDataBits(8);\n serialPort.setNumStopBits(SerialPort.ONE_STOP_BIT);\n serialPort.setParity(SerialPort.NO_PARITY);\n\n if (serialPort.openPort()) &#123;\n System.out.println(&quot;Port opened successfully.&quot;);\n &#125; else &#123;\n System.out.println(&quot;Failed to open port.&quot;);\n return;\n &#125;\n\n &#x2F;&#x2F; 发送数据\n byte[] dataToSend &#x3D; &#123;0x00, 0x10&#125;; &#x2F;&#x2F; 示例16位数据\n serialPort.writeBytes(dataToSend, dataToSend.length);\n\n &#x2F;&#x2F; 接收数据\n byte[] readBuffer &#x3D; new byte[2];\n serialPort.readBytes(readBuffer, readBuffer.length);\n System.out.println(&quot;Received: &quot; + bytesToHex(readBuffer));\n\n serialPort.closePort();\n &#125;\n\n private static String bytesToHex(byte[] bytes) &#123;\n StringBuilder sb &#x3D; new StringBuilder();\n for (byte b : bytes) &#123;\n sb.append(String.format(&quot;%02X &quot;, b));\n &#125;\n return sb.toString().trim();\n &#125;\n&#125;\n\n</code></pre>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"20240512盖章整理","slug":"20240512gai-zhang-zheng-li","date":"2024-05-13T11:01:02.000Z","updated":"2024-05-13T03:05:09.323Z","comments":true,"path":"/post/20240512gai-zhang-zheng-li/","link":"","excerpt":"","content":"<h1 id=\"盖章整理\"><a href=\"#盖章整理\" class=\"headerlink\" title=\"盖章整理\"></a>盖章整理</h1>","categories":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/categories/%E7%9B%96%E7%AB%A0/"}],"tags":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/tags/%E7%9B%96%E7%AB%A0/"}]},{"title":"tstypescript看这篇就够了","slug":"tstypescript-kan-zhe-pian-jiu-gou-le","date":"2024-04-23T07:50:10.000Z","updated":"2024-04-30T02:19:42.332Z","comments":true,"path":"/post/tstypescript-kan-zhe-pian-jiu-gou-le/","link":"","excerpt":"","content":"<h1 id=\"Typescript-简介\"><a href=\"#Typescript-简介\" class=\"headerlink\" title=\"Typescript 简介\"></a>Typescript 简介</h1><p>TypeScript是用于应用程序规模开发的JavaScript。</p>\n<p>TypeScript是强类型面向对象的编译语言。它是由微软的Anders HejlsbergC的设计者设计的。</p>\n<p>TypeScript既是一种语言又是一组工具。TypeScript是JavaScript的一个超集。换句话说TypeScript是JavaScript加上一些额外的功能。</p>\n<p>TypeScript 扩展了 JavaScript 的语法,所以任何现有的 JavaScript 程序可以不加改变的在 TypeScript 下工作。TypeScript 是为大型应用之开发而设计,而编译时它产生 JavaScript 以确保兼容性。</p>\n<p>TypeScript 可以编译出纯净、 简洁的 JavaScript 代码并且可以运行在任何浏览器上、Node.js 环境中和任何支持 ECMAScript 3或更高版本的 JavaScript 引擎中。</p>\n<h1 id=\"TypeScript-的优势\"><a href=\"#TypeScript-的优势\" class=\"headerlink\" title=\"TypeScript 的优势\"></a>TypeScript 的优势</h1><p>TypeScript相对于纯粹的JavaScript具有许多优势特别是在开发大型应用程序时。以下是一些TypeScript的优势</p>\n<h2 id=\"静态类型系统\"><a href=\"#静态类型系统\" class=\"headerlink\" title=\"静态类型系统\"></a>静态类型系统</h2><p>TypeScript引入了静态类型系统允许开发者在声明变量、函数参数、返回值等时指定类型。这种静态类型检查可以帮助捕获常见的编程错误例如类型不匹配、未定义的属性或方法等提供更好的代码质量和可靠性。</p>\n<h2 id=\"更好的代码智能感知\"><a href=\"#更好的代码智能感知\" class=\"headerlink\" title=\"更好的代码智能感知\"></a>更好的代码智能感知</h2><p>因为TypeScript了解代码中的类型信息因此编辑器可以提供更准确和强大的代码智能感知和自动补全功能。这可以显著提高开发效率并减少常见的编码错误。</p>\n<h2 id=\"更易于重构和维护\"><a href=\"#更易于重构和维护\" class=\"headerlink\" title=\"更易于重构和维护\"></a>更易于重构和维护</h2><p>静态类型和面向对象特性使得代码更模块化、更结构化从而更易于重构和维护。IDE可以更好地支持重构操作并能够更好地理解代码的结构和依赖关系。</p>\n<h2 id=\"更丰富的面向对象特性\"><a href=\"#更丰富的面向对象特性\" class=\"headerlink\" title=\"更丰富的面向对象特性\"></a>更丰富的面向对象特性</h2><p>TypeScript支持类、接口、继承、多态等面向对象编程的特性使得代码组织更清晰、更易于理解。这对于构建大型应用程序非常有用。</p>\n<h2 id=\"更好的工具支持:\"><a href=\"#更好的工具支持:\" class=\"headerlink\" title=\"更好的工具支持:\"></a>更好的工具支持:</h2><p>TypeScript配合现代的集成开发环境如VS Code、WebStorm等可以提供强大的代码导航、重构、调试和代码分析工具。此外TypeScript还能够与许多流行的前端框架如Angular、React等良好集成。</p>\n<h2 id=\"增强的语言功能:\"><a href=\"#增强的语言功能:\" class=\"headerlink\" title=\"增强的语言功能:\"></a>增强的语言功能:</h2><p>TypeScript不仅仅是JavaScript的超集它还引入了一些新的语言功能如箭头函数、可选参数、默认参数、模板字符串等使得代码更简洁和易读。</p>\n<h2 id=\"更好的生态系统:\"><a href=\"#更好的生态系统:\" class=\"headerlink\" title=\"更好的生态系统:\"></a>更好的生态系统:</h2><p>TypeScript拥有庞大的社区支持许多常用的JavaScript库和框架都提供了类型定义文件可以轻松地与TypeScript集成。这使得使用第三方库时具有更好的类型安全性和开发体验。</p>\n<h1 id=\"基础类型\"><a href=\"#基础类型\" class=\"headerlink\" title=\"基础类型\"></a>基础类型</h1><p>TypeScript支持与JavaScript几乎相同的数据类型 数字,字符串,结构体,布尔值等,此外还提供了实用的枚举类型方便我们使用。</p>\n<h2 id=\"布尔值\"><a href=\"#布尔值\" class=\"headerlink\" title=\"布尔值\"></a>布尔值</h2><p>最基本的数据类型就是简单的 true/false 值,在 JavaScript 和 TypeScript 里叫做 boolean其它语言中也一样。 我们来定义一个布尔类型的变量:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let isDone: boolean &#x3D; false;</code></pre>\n<p>在TypeScript中, 在参数名称后面使用冒号:来指定参数的类型</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let 变量名: 数据类型</code></pre>\n<h2 id=\"数字\"><a href=\"#数字\" class=\"headerlink\" title=\"数字\"></a>数字</h2><p>和 JavaScript 一样TypeScript 里的所有数字都是浮点数。 这些浮点数的类型是 number。 除了支持十进制和十六进制字面量TypeScript 还支持 ECMAScript 2015 中引入的二进制和八进制字面量。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let decLiteral: number &#x3D; 6;\nlet hexLiteral: number &#x3D; 0xf00d;\nlet binaryLiteral: number &#x3D; 0b1010;\nlet octalLiteral: number &#x3D; 0o744;</code></pre>\n<h2 id=\"字符串\"><a href=\"#字符串\" class=\"headerlink\" title=\"字符串\"></a>字符串</h2><h3 id=\"字符串新特性\"><a href=\"#字符串新特性\" class=\"headerlink\" title=\"字符串新特性\"></a>字符串新特性</h3><p>JavaScript 程序的另一项基本操作是处理网页或服务器端的文本数据。 像其它语言里一样,我们使用 string 表示文本数据类型。 和 JavaScript 一样,可以使用双引号 “或单引号’表示字符串。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let name: string &#x3D; &quot;bob&quot;;\nname &#x3D; &quot;loen&quot;;</code></pre>\n<p>以上字符串不支持换行.</p>\n<h3 id=\"多行字符串\"><a href=\"#多行字符串\" class=\"headerlink\" title=\"多行字符串\"></a>多行字符串</h3><p>在Typescript中你可以使用反引号 ` 表示多行字符串.</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let hello: string &#x3D; &#96;Welcome to \nW3cschool&#96;;</code></pre>\n<h3 id=\"内嵌表达式\"><a href=\"#内嵌表达式\" class=\"headerlink\" title=\"内嵌表达式\"></a>内嵌表达式</h3><p>你还可以使用模版字符串,也就是在反引号中使用 ${ expr }这种形式嵌入表达式</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let name: string &#x3D; &#96;Loen&#96;;\nlet age: number &#x3D; 37;\nlet sentence: string &#x3D; &#96;Hello, my name is $&#123; name &#125;.\n\n\nI&#39;ll be $&#123; age + 1 &#125; years old next month.&#96;;</code></pre>\n<p>这与下面定义sentence的方式效果相同</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let sentence: string &#x3D; &quot;Hello, my name is &quot; + name + &quot;.\\n\\n&quot; +\n &quot;I&#39;ll be &quot; + (age + 1) + &quot; years old next month.&quot;;</code></pre>\n<blockquote>\n<p>我们可以看到Typescript定义的字符串更加清晰简单.</p>\n</blockquote>\n<h3 id=\"自动拆分字符串\"><a href=\"#自动拆分字符串\" class=\"headerlink\" title=\"自动拆分字符串\"></a>自动拆分字符串</h3><p>我们可以用字符串模板去调用一个方法</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function userinfo(params,name,age)&#123;\n console.log(params);\n console.log(name);\n console.log(age);\n&#125;\n\n\nlet myname &#x3D; &quot;Loen Wang&quot;;\nlet getAge &#x3D; function()&#123;\n return 18;\n&#125;\n&#x2F;&#x2F; 调用\nuserinfo&#96;hello my name is $&#123;myname&#125;, i&#39;m $&#123;getAge()&#125;&#96;</code></pre>\n<p>结果:<br><img src=\"https://img.huangge1199.cn/blog/tstypescript-kan-zhe-pian-jiu-gou-le/2024-04-23-16-18-22-image.png\" alt=\"\"></p>\n<h2 id=\"数组\"><a href=\"#数组\" class=\"headerlink\" title=\"数组\"></a>数组</h2><p>TypeScript 有两种方式可以定义数组。</p>\n<p>第一种, 是在元素类型后面接上 <code>[]</code>,表示由此类型元素组成的一个数组:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let list: number[] &#x3D; [1, 2, 3];</code></pre>\n<p>第二种方式是使用数组泛型Array&lt;元素类型&gt;</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let list: Array&lt;number&gt; &#x3D; [1, 2, 3];</code></pre>\n<h2 id=\"元组-Tuple\"><a href=\"#元组-Tuple\" class=\"headerlink\" title=\"元组 Tuple\"></a>元组 Tuple</h2><p>元组类型允许表示一个已知元素数量和类型的数组,各元素的类型不必相同。 比如,你可以定义一对值分别为 <code>string</code> 和 <code>number</code> 类型的元组。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">&#x2F;&#x2F; 声明一个元组类型\nlet x: [string, number];\n&#x2F;&#x2F; 初始化元组\nx &#x3D; [&#39;hello&#39;, 10]; \nx &#x3D; [10, &#39;hello&#39;]; &#x2F;&#x2F; 这里会报错,类型错误</code></pre>\n<h2 id=\"枚举\"><a href=\"#枚举\" class=\"headerlink\" title=\"枚举\"></a>枚举</h2><p><code>enum</code> 类型是对 JavaScript 标准数据类型的一个补充。 像 C# 等其它语言一样,使用枚举类型可以为一组数值赋予友好的名字。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red, Green, Blue&#125;\nlet c: Color &#x3D; Color.Green;</code></pre>\n<p>默认情况下,<strong>从0开始为元素编号</strong>。 你也可以手动的指定成员的数值。 例如,我们将上面的例子改成从 1开始编号</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red &#x3D; 1, Green, Blue&#125;\nlet c: Color &#x3D; Color.Green;</code></pre>\n<p>或者,全部都采用手动赋值:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red &#x3D; 1, Green &#x3D; 2, Blue &#x3D; 4&#125;\nlet c: Color &#x3D; Color.Green;</code></pre>\n<p>枚举类型提供的一个便利是你可以由枚举的值得到它的名字。 例如我们知道数值为2但是不确定它映射到Color里的哪个名字我们可以查找相应的名字</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red &#x3D; 1, Green, Blue&#125;\nlet colorName: string &#x3D; Color[2];\n\n\nalert(colorName); &#x2F;&#x2F; 显示&#39;Green&#39;因为上面代码里它的值是2</code></pre>\n<h2 id=\"Any\"><a href=\"#Any\" class=\"headerlink\" title=\"Any\"></a>Any</h2><p>如果不希望类型检查器对值进行检查,直接通过编译阶段的检查。 那么我们可以使用 <code>any</code>类型来标记这些变量:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let notSure: any &#x3D; 4;\nnotSure &#x3D; &quot;这是一个字符串&quot;;\nnotSure &#x3D; false; &#x2F;&#x2F; 现在我们又可以将其改成布尔类型</code></pre>\n<p>在对现有代码进行改写的时候,<code>any</code>类型是十分有用的,它允许你在编译时可选择地包含或移除类型检查。 你可能认为 Object有相似的作用就像它在其它语言中那样。 但是 Object类型的变量只是允许你给它赋任意值 - 但是却不能够在它上面调用任意的方法,即便它真的有这些方法:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let notSure: any &#x3D; 4;\nnotSure.ifItExists();&#x2F;&#x2F; 存在这个方法\nnotSure.toFixed(); &#x2F;&#x2F; 存在这个方法\n\n\nlet prettySure: Object &#x3D; 4;\nprettySure.toFixed(); &#x2F;&#x2F; 错误:对象类型上不存在 toFixed 属性</code></pre>\n<p>当你只知道一部分数据的类型时,<code>any</code>类型也是有用的。 比如,你有一个数组,它包含了不同的类型的数据:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let list: any[] &#x3D; [1, true, &quot;free&quot;];\n\n\nlist[1] &#x3D; 100;</code></pre>\n<h2 id=\"Void\"><a href=\"#Void\" class=\"headerlink\" title=\"Void\"></a>Void</h2><p>某种程度上来说,<code>void</code>类型像是与<code>any</code>类型相反,它表示没有任何类型。 当一个函数没有返回值时,你通常会见到其返回值类型是 <code>void</code></p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function warnUser(): void &#123;\n alert(&quot;This is my warning message&quot;);\n&#125;</code></pre>\n<p>声明一个<code>void</code>类型的变量没有什么大用,因为你只能为它赋予<code>undefined</code>和<code>null</code></p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let unusable: void &#x3D; undefined;</code></pre>\n<h2 id=\"Null-和-Undefined\"><a href=\"#Null-和-Undefined\" class=\"headerlink\" title=\"Null 和 Undefined\"></a>Null 和 Undefined</h2><p>TypeScript 里,<code>undefined</code> 和 <code>null</code> 两者各自有自己的类型分别叫做 <code>undefined</code> 和 <code>null</code>。 和 <code>void</code> 相似,它们的本身的类型用处不是很大:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">&#x2F;&#x2F; 我们无法给这些变量赋值\nlet u: undefined &#x3D; undefined;\nlet n: null &#x3D; null;</code></pre>\n<p>默认情况下 <strong>null 和 undefined 是所有类型的子类型</strong>。</p>\n<p>就是说你可以把 null 和 undefined 赋值给 number 类型的变量。</p>\n<p>然而,当你编译时指定了 —strictNullChecks 标记, null 和 undefined 只能赋值给 void 和它们自己。</p>\n<blockquote>\n<p>注意:我们鼓励尽可能地使用<code>--strictNullChecks</code>,但在本教程里我们假设这个标记是关闭的。</p>\n</blockquote>\n<h2 id=\"Never\"><a href=\"#Never\" class=\"headerlink\" title=\"Never\"></a>Never</h2><p><code>never</code> 类型表示的是那些永不存在的值的类型。</p>\n<p>例如, never 类型是那些总是会抛出异常或根本就不会有返回值的函数表达式或箭头函数表达式的返回值类型;</p>\n<p><code>never</code> 类型是任何类型的子类型,也可以赋值给任何类型; 然而,没有类型是 never 的子类型或可以赋值给 never 类型(除了 never 本身之外)。 即使 any 也不可以赋值给 never 。</p>\n<p>下面是一些返回 never 类型的函数:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">&#x2F;&#x2F; 返回never的函数必须存在无法达到的终点\nfunction error(message: string): never &#123;\n throw new Error(message);\n&#125;\n\n\n&#x2F;&#x2F; 推断的返回值类型为never\nfunction fail() &#123;\n return error(&quot;Something failed&quot;);\n&#125;\n\n\n&#x2F;&#x2F; 返回never的函数必须存在无法达到的终点\nfunction infiniteLoop(): never &#123;\n while (true) &#123;\n &#125;\n&#125;</code></pre>\n<blockquote>\n<p>箭头表达式将再后面的课程中学习到。</p>\n</blockquote>\n<h2 id=\"类型断言\"><a href=\"#类型断言\" class=\"headerlink\" title=\"类型断言\"></a>类型断言</h2><p>通过类型断言这种方式可以告诉编译器,“相信我,我知道自己在干什么”。 类型断言好比其它语言里的类型转换,但是不进行特殊的数据检查和解构。 它没有运行时的影响,只是在编译阶段起作用。</p>\n<p>TypeScript 会假设你,程序员,已经进行了必须的检查。</p>\n<p>类型断言有两种形式。 其一是<code>尖括号</code>语法:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let someValue: any &#x3D; &quot;this is a string&quot;;\n\n\nlet strLength: number &#x3D; (&lt;string&gt;someValue).length;</code></pre>\n<p>另一个为<code>as</code>语法:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let someValue: any &#x3D; &quot;this is a string&quot;;\n\n\nlet strLength: number &#x3D; (someValue as string).length;</code></pre>\n<p>两种形式是等价的。 至于使用哪个大多数情况下是凭个人喜好;</p>\n<p>然而,当你在 TypeScript 里使用 <code>JSX</code> 时,只有 <code>as</code>语法断言是被允许的。</p>\n<h1 id=\"符号介绍\"><a href=\"#符号介绍\" class=\"headerlink\" title=\"符号介绍\"></a>符号介绍</h1><p>自ECMAScript 2015起symbol成为了一种新的原生类型就像number和string一样。</p>\n<p>symbol类型的值是通过Symbol构造函数创建的。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let sym1 &#x3D; Symbol();\nlet sym2 &#x3D; Symbol(&quot;key&quot;); &#x2F;&#x2F; 可选的字符串key</code></pre>\n<p>Symbols是不可改变且唯一的。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let sym2 &#x3D; Symbol(&quot;key&quot;);\nlet sym3 &#x3D; Symbol(&quot;key&quot;);\n\n\nsym2 &#x3D;&#x3D;&#x3D; sym3; &#x2F;&#x2F; false</code></pre>\n<p>symbols是唯一的像字符串一样symbols也可以被用做对象属性的键。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let sym &#x3D; Symbol();\nlet obj &#x3D; &#123;\n [sym]: &quot;value&quot;\n&#125;;\n\n\nconsole.log(obj[sym]); &#x2F;&#x2F; &quot;value&quot;</code></pre>\n<p>Symbols也可以与计算出的属性名声明相结合来声明对象的属性和类成员。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">const getClassNameSymbol &#x3D; Symbol();\n\n\nclass C &#123;\n [getClassNameSymbol]()&#123;\n return &quot;C&quot;;\n &#125;\n&#125;\n\n\nlet c &#x3D; new C();\nlet className &#x3D; c[getClassNameSymbol](); &#x2F;&#x2F; &quot;C&quot;</code></pre>\n<h1 id=\"变量声明\"><a href=\"#变量声明\" class=\"headerlink\" title=\"变量声明\"></a>变量声明</h1><h2 id=\"let和const\"><a href=\"#let和const\" class=\"headerlink\" title=\"let和const\"></a>let和const</h2><p><code>let</code>和<code>const</code>是JavaScript里相对较新的变量声明方式。 像我们之前提到过的, let在很多方面与<code>var</code>是相似的但是可以帮助大家避免在JavaScript里常见一些问题。 <code>const</code>只能一次赋值, 再次赋值会报错。</p>\n<ul>\n<li><p>let可以多次写入</p>\n</li>\n<li><p>const只允许一次写入</p>\n</li>\n</ul>\n<p>因为 TypeScript 是 JavaScript 的超集所以它本身就支持let和const。 下面我们会详细说明这些新的声明方式以及为什么推荐使用它们来代替 <code>var</code>。</p>\n<h2 id=\"var-声明\"><a href=\"#var-声明\" class=\"headerlink\" title=\"var 声明\"></a>var 声明</h2><p>一直以来我们都是通过<code>var</code>关键字定义 JavaScript 变量。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">var a &#x3D; 10;</code></pre>\n<p>大家都能理解这里定义了一个名为a值为10的变量。</p>\n<p>我们也可以在函数内部定义变量:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f() &#123;\n var message &#x3D; &quot;Hello, world!&quot;;\n\n\n return message;\n&#125;</code></pre>\n<p>并且我们也可以在其它函数内部访问相同的变量。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f() &#123;\n var a &#x3D; 10;\n return function g() &#123;\n var b &#x3D; a + 1;\n return b;\n &#125;\n&#125;\n\n\nvar g &#x3D; f();\ng(); &#x2F;&#x2F; returns 11;</code></pre>\n<p>上面的例子里g 可以获取到 f 函数里定义的 a 变量。 每当 g 被调用时,它都可以访问到 f 里的 a 变量。 即使当 g 在 f 已经执行完后才被调用,它仍然可以访问及修改 a 。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f() &#123;\n var a &#x3D; 1;\n\n\n a &#x3D; 2;\n var b &#x3D; g();\n a &#x3D; 3;\n\n\n return b;\n\n\n function g() &#123;\n return a;\n &#125;\n&#125;\n\n\nf(); &#x2F;&#x2F; returns 2</code></pre>\n<h3 id=\"作用域规则\"><a href=\"#作用域规则\" class=\"headerlink\" title=\"作用域规则\"></a>作用域规则</h3><p>对于熟悉其它语言的人来说,<code>var</code>声明有些奇怪的作用域规则。 看下面的例子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(shouldInitialize: boolean) &#123;\n if (shouldInitialize) &#123;\n var x &#x3D; 10;\n &#125;\n\n\n return x;\n&#125;\n\n\nf(true); &#x2F;&#x2F; returns &#39;10&#39;\nf(false); &#x2F;&#x2F; returns &#39;undefined&#39;</code></pre>\n<p>变量 x 是定义在 <em>if 语句里面</em> ,但是我们却可以在语句的外面访问它。 这是因为 <code>var</code>声明可以在包含它的函数,模块,命名空间或全局作用域内部任何位置被访问,包含它的代码块对此没有什么影响。</p>\n<p>这些作用域规则可能会引发一些错误。 其中之一就是,多次声明同一个变量并不会报错:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function sumMatrix(matrix: number[][]) &#123;\n var sum &#x3D; 0;\n for (var i &#x3D; 0; i &lt; matrix.length; i++) &#123;\n var currentRow &#x3D; matrix[i];\n for (var i &#x3D; 0; i &lt; currentRow.length; i++) &#123;\n sum +&#x3D; currentRow[i];\n &#125;\n &#125;\n\n\n return sum;\n&#125;</code></pre>\n<p>这里很容易看出一些问题,里层的 for 循环会覆盖变量 i因为所有 i 都引用相同的函数作用域内的变量。 这很容易引发无穷的麻烦。</p>\n<h2 id=\"let-声明\"><a href=\"#let-声明\" class=\"headerlink\" title=\"let 声明\"></a>let 声明</h2><p>现在你已经知道了<code>var</code>存在一些问题,这恰好说明了为什么用<code>let</code>语句来声明变量。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let hello &#x3D; &quot;Hello!&quot;;</code></pre>\n<h3 id=\"块作用域\"><a href=\"#块作用域\" class=\"headerlink\" title=\"块作用域\"></a>块作用域</h3><p>当用 <code>let</code> 声明一个变量,它使用的是词法作用域或块作用域。 不同于使用 <code>var</code> 声明的变量那样可以在包含它们的函数外访问,块作用域变量在包含它们的块或 <code>for</code> 循环之外是不能访问的。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(input: boolean) &#123;\n let a &#x3D; 100;\n\n\n if (input) &#123;\n &#x2F;&#x2F; Still okay to reference &#39;a&#39;\n let b &#x3D; a + 1;\n return b;\n &#125;\n\n\n &#x2F;&#x2F; Error: &#39;b&#39; doesn&#39;t exist here\n return b;\n&#125;</code></pre>\n<p>这里我们定义了2个变量 a 和 b 。 a 的作用域是 f 函数体内,而 b 的作用域是 if 语句块里。</p>\n<p>在<code>catch</code>语句里声明的变量也具有同样的作用域规则。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">try &#123;\n throw &quot;oh no!&quot;;\n&#125;\ncatch (e) &#123;\n console.log(&quot;Oh well.&quot;);\n&#125;\n\n\n&#x2F;&#x2F; Error: &#39;e&#39; doesn&#39;t exist here\nconsole.log(e);</code></pre>\n<p>拥有块级作用域的变量的另一个特点是,它们不能在被声明之前读或写。</p>\n<p>虽然这些变量始终<code>“存在”</code>于它们的作用域里,但在直到声明它的代码之前的区域都属于 暂时性死区。 它只是用来说明我们不能在 <code>let</code>语句之前访问它们,幸运的是 TypeScript 可以告诉我们这些信息。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">a++; &#x2F;&#x2F; illegal to use &#39;a&#39; before it&#39;s declared;\nlet a;</code></pre>\n<p><strong>注意</strong>: 我们仍然可以在一个拥有块作用域变量被声明前获取它。 只是我们不能在变量声明前去调用那个函数。 如果生成代码目标为ES2015现代的运行时会抛出一个错误然而现今 TypeScript 是不会报错的。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function foo() &#123;\n &#x2F;&#x2F; okay to capture &#39;a&#39;\n return a;\n&#125;\n\n\n&#x2F;&#x2F; 不能在&#39;a&#39;被声明前调用&#39;foo&#39;\n&#x2F;&#x2F; 运行时应该抛出错误\nfoo();\n\n\nlet a;</code></pre>\n<h2 id=\"重定义及屏蔽\"><a href=\"#重定义及屏蔽\" class=\"headerlink\" title=\"重定义及屏蔽\"></a>重定义及屏蔽</h2><p>我们提过使用 <code>var</code> 声明时它不在乎你声明多少次你只会得到1个。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(x) &#123;\n var x;\n var x;\n\n\n if (true) &#123;\n var x;\n &#125;\n&#125;</code></pre>\n<p>在上面的例子里,所有<code>x</code>的声明实际上都引用一个相同的<code>x</code>,并且这是完全有效的代码。 这经常会成为<code>bug</code>的来源。 好的是, <code>let</code>声明就不会这么宽松了。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let x &#x3D; 10;\nlet x &#x3D; 20; &#x2F;&#x2F; 错误不能在1个作用域里多次声明&#96;x&#96;</code></pre>\n<p>并不是要求两个均是块级作用域的声明 TypeScript 才会给出一个错误的警告。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(x) &#123;\n let x &#x3D; 100; &#x2F;&#x2F; error: interferes with parameter declaration\n&#125;\n\n\nfunction g() &#123;\n let x &#x3D; 100;\n var x &#x3D; 100; &#x2F;&#x2F; 错误:不能同时声明&#39;x&#39;\n&#125;</code></pre>\n<p>并不是说块级作用域变量不能用函数作用域变量来声明。 而是块级作用域变量需要在明显不同的块里声明。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(condition, x) &#123;\n if (condition) &#123;\n let x &#x3D; 100;\n return x;\n &#125;\n\n\n return x;\n&#125;\n\n\nf(false, 0); &#x2F;&#x2F; returns 0\nf(true, 0); &#x2F;&#x2F; returns 100</code></pre>\n<p>在一个嵌套作用域里引入一个新名字的行为称做屏蔽。 它是一把双刃剑,它可能会不小心地引入新问题,同时也可能会解决一些错误。 例如,假设我们现在用 <code>let</code>重写之前的<code>sumMatrix</code>函数。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function sumMatrix(matrix: number[][]) &#123;\n let sum &#x3D; 0;\n for (let i &#x3D; 0; i &lt; matrix.length; i++) &#123;\n var currentRow &#x3D; matrix[i];\n for (let i &#x3D; 0; i &lt; currentRow.length; i++) &#123;\n sum +&#x3D; currentRow[i];\n &#125;\n &#125;\n\n\n return sum;\n&#125;</code></pre>\n<p>这个版本的循环能得到正确的结果,因为内层循环的<code>i</code>可以屏蔽掉外层循环的<code>i</code>。</p>\n<p>通常来讲应该避免使用这种屏蔽,因为我们需要写出清晰的代码。</p>\n<h2 id=\"块级作用域变量的获取\"><a href=\"#块级作用域变量的获取\" class=\"headerlink\" title=\"块级作用域变量的获取\"></a>块级作用域变量的获取</h2><p><code>let</code>声明每次迭代都会创建一个新作用域。 这就是我们在使用立即执行的函数表达式时做的事,所以在 <code>setTimeout</code> 例子里我们仅使用 <code>let</code> 声明就可以了。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">for (let i &#x3D; 0; i &lt; 10 ; i++) &#123;\n setTimeout(function() &#123;\n console.log(i); \n &#125;, 100 * i);\n&#125;</code></pre>\n<p>会输出与预料一致的结果:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">0\n1\n2\n3\n4\n5\n6\n7\n8\n9</code></pre>\n<h2 id=\"const-声明\"><a href=\"#const-声明\" class=\"headerlink\" title=\"const 声明\"></a>const 声明</h2><p><code>const</code> 声明是声明变量的另一种方式。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">const numLivesForCat &#x3D; 9;</code></pre>\n<p>const声明的变量只允许一次赋值, 引用的值是不可变的。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">const numLivesForCat &#x3D; 9;\nconst kitty &#x3D; &#123;\n name: &quot;Aurora&quot;,\n numLives: numLivesForCat,\n&#125;\n\n\n&#x2F;&#x2F; 重新赋值一个类会报错\nkitty &#x3D; &#123;\n name: &quot;Loen&quot;,\n numLives: numLivesForCat\n&#125;;\n\n\n&#x2F;&#x2F; 属性修改是允许的\nkitty.name &#x3D; &quot;Rory&quot;;\nkitty.name &#x3D; &quot;Kitty&quot;;\nkitty.name &#x3D; &quot;Cat&quot;;\nkitty.numLives--;</code></pre>\n<p>除非你使用特殊的方法去避免,实际上<code>const</code>变量的内部状态是可修改的。 幸运的是TypeScript允许你将对象的成员设置成只读的。</p>\n<h1 id=\"解构\"><a href=\"#解构\" class=\"headerlink\" title=\"解构\"></a>解构</h1><h2 id=\"解构数组\"><a href=\"#解构数组\" class=\"headerlink\" title=\"解构数组\"></a>解构数组</h2><p>最简单的解构莫过于数组的解构赋值了:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let input &#x3D; [1, 2];\nlet [first, second] &#x3D; input;\nconsole.log(first); &#x2F;&#x2F; outputs 1\nconsole.log(second); &#x2F;&#x2F; outputs 2</code></pre>\n<p>这创建了2个命名变量 <code>first</code> 和 <code>second</code>。 相当于使用了索引,但更为方便:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">first &#x3D; input[0];\nsecond &#x3D; input[1];</code></pre>\n<p>解构作用于已声明的变量会更好:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">&#x2F;&#x2F; 对换变量的值\n[first, second] &#x3D; [second, first];</code></pre>\n<p>作用于函数参数:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f([first, second]: [number, number]) &#123;\n console.log(first);\n console.log(second);\n&#125;\nf(input);</code></pre>\n<p>你可以在数组里使用<code>...</code>语法创建剩余变量:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let [first, ...rest] &#x3D; [1, 2, 3, 4];\nconsole.log(first); &#x2F;&#x2F; outputs 1\nconsole.log(rest); &#x2F;&#x2F; outputs [ 2, 3, 4 ]</code></pre>\n<p>当然,由于是 JavaScript, 你可以忽略你不关心的尾随元素:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let [first] &#x3D; [1, 2, 3, 4];\nconsole.log(first); &#x2F;&#x2F; outputs 1</code></pre>\n<p>或其它元素:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let [, second, , fourth] &#x3D; [1, 2, 3, 4];</code></pre>\n<h2 id=\"对象解构\"><a href=\"#对象解构\" class=\"headerlink\" title=\"对象解构\"></a>对象解构</h2><p>你也可以解构对象:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let o &#x3D; &#123;\n a: &quot;foo&quot;,\n b: 12,\n c: &quot;bar&quot;\n&#125;;\nlet &#123; a, b &#125; &#x3D; o;</code></pre>\n<p>这通过 <code>o.a and o.b</code> 创建了 <code>a</code> 和 <code>b</code> 。 注意,如果你不需要 <code>c</code> 你可以忽略它。</p>\n<p>就像数组解构,你可以用没有声明的赋值:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">(&#123; a, b &#125; &#x3D; &#123; a: &quot;baz&quot;, b: 101 &#125;);</code></pre>\n<p><strong>注意</strong>:我们需要用括号将它括起来因为Javascript通常会将以 { 起始的语句解析为一个块。</p>\n<p>你可以在对象里使用…语法创建剩余变量:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let &#123; a, ...passthrough &#125; &#x3D; o;\nlet total &#x3D; passthrough.b + passthrough.c.length;</code></pre>\n<h3 id=\"属性重命名\"><a href=\"#属性重命名\" class=\"headerlink\" title=\"属性重命名\"></a>属性重命名</h3><p>你也可以给属性以不同的名字:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let &#123; a: newName1, b: newName2 &#125; &#x3D; o;</code></pre>\n<p>这里的语法开始变得混乱。 你可以将 <code>a: newName1</code> 读做 <code>a 作为 newName1</code>。 方向是从左到右,好像你写成了以下样子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let newName1 &#x3D; o.a;\nlet newName2 &#x3D; o.b;</code></pre>\n<p>令人困惑的是,这里的冒号不是指示类型的。 如果你想指定它的类型, 仍然需要在其后写上完整的模式。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let &#123;a, b&#125;: &#123;a: string, b: number&#125; &#x3D; o;</code></pre>\n<h3 id=\"默认值\"><a href=\"#默认值\" class=\"headerlink\" title=\"默认值\"></a>默认值</h3><p>默认值可以让你在属性为 <code>undefined</code> 时使用缺省值:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function keepWholeObject(wholeObject: &#123; a: string, b?: number &#125;) \n&#123;\n let &#123; a, b &#x3D; 1001 &#125; &#x3D; wholeObject;\n&#125;</code></pre>\n<p>现在,即使 <code>b</code> 为 undefined keepWholeObject 函数的变量 wholeObject 的属性 a 和 b 都会有值。</p>\n<h2 id=\"函数声明\"><a href=\"#函数声明\" class=\"headerlink\" title=\"函数声明\"></a>函数声明</h2><p>解构也能用于函数声明。 看以下简单的情况:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">type C &#x3D; &#123; a: string, b?: number &#125;\nfunction f(&#123; a, b &#125;: C): void &#123;\n &#x2F;&#x2F; ...\n&#125;</code></pre>\n<p>通常情况下更多的是指定默认值,解构默认值有些棘手。 首先,你需要在默认值之前设置其格式。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(&#123; a, b &#125; &#x3D; &#123; a: &quot;&quot;, b: 0 &#125;): void &#123;\n &#x2F;&#x2F; ...\n&#125;\nf(); &#x2F;&#x2F; 默认 &#123; a: &quot;&quot;, b: 0 &#125;</code></pre>\n<p>你需要知道在解构属性上给予一个默认或可选的属性用来替换主初始化列表。 要知道 C 的定义有一个 b 可选属性:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function f(&#123; a, b &#x3D; 0 &#125; &#x3D; &#123; a: &quot;&quot; &#125;): void &#123;\n &#x2F;&#x2F; ...\n&#125;\nf(&#123; a: &quot;yes&quot; &#125;); &#x2F;&#x2F; 默认 b &#x3D; 0\nf(); &#x2F;&#x2F; 默认 &#123;a: &quot;&quot;&#125;, b &#x3D; 0\nf(&#123;&#125;); &#x2F;&#x2F; 错误, 如果您提供参数,则需要&#39;a&#39;</code></pre>\n<p>从前面的例子可以看出, 要小心使用解构。就算是最简单的解构表达式也是难以理解的。 尤其当存在深层嵌套解构的时候,就算这时没有堆叠在一起的重命名,默认值和类型注解,也是令人难以理解的。</p>\n<blockquote>\n<p>解构表达式要尽量保持小而简单。</p>\n</blockquote>\n<h1 id=\"展开\"><a href=\"#展开\" class=\"headerlink\" title=\"展开\"></a>展开</h1><p>展开操作符正与解构相反。 它允许你将一个数组展开为另一个数组,或将一个对象展开为另一个对象。 例如:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let first &#x3D; [1, 2];\nlet second &#x3D; [3, 4];\nlet bothPlus &#x3D; [0, ...first, ...second, 5];</code></pre>\n<p>这会令<code>bothPlus</code>的值为 [0, 1, 2, 3, 4, 5] 。 展开操作创建了 first 和 second 的一份浅拷贝。 它们不会被展开操作所改变。</p>\n<p>你还可以展开对象:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let defaults &#x3D; &#123; food: &quot;spicy&quot;, price: &quot;$&quot;, ambiance: &quot;noisy&quot; &#125;;\nlet search &#x3D; &#123; ...defaults, food: &quot;rich&quot; &#125;;</code></pre>\n<p><code>search</code>的值为 { food: “rich”, price: “$”, ambiance: “noisy” } 。 对象的展开比数组的展开要复杂的多。 像数组展开一样,它是从左至右进行处理,但结果仍为对象。 这就意味着出现在展开对象后面的属性会覆盖前面的属性。 因此,如果我们修改上面的例子,在结尾处进行展开的话:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let defaults &#x3D; &#123; food: &quot;spicy&quot;, price: &quot;$&quot;, ambiance: &quot;noisy&quot; &#125;;\nlet search &#x3D; &#123; food: &quot;rich&quot;, ...defaults &#125;;</code></pre>\n<p>那么, defaults 里的 food 属性会重写 food: “rich” ,在这里这并不是我们想要的结果。</p>\n<p>对象展开还有其它一些意想不到的限制。 首先,它仅包含对象 自身的可枚举属性。 大体上是说当你展开一个对象实例时,你会丢失其方法:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class C &#123;\n p &#x3D; 12;\n m() &#123;\n &#125;\n&#125;\nlet c &#x3D; new C();\nlet clone &#x3D; &#123; ...c &#125;;\nclone.p; &#x2F;&#x2F; 没问题\nclone.m(); &#x2F;&#x2F; 错误</code></pre>\n<h1 id=\"函数\"><a href=\"#函数\" class=\"headerlink\" title=\"函数\"></a>函数</h1><h2 id=\"函数介绍\"><a href=\"#函数介绍\" class=\"headerlink\" title=\"函数介绍\"></a>函数介绍</h2><p>函数是JavaScript应用程序的基础。 它帮助你实现抽象层,模拟类,信息隐藏和模块。 在TypeScript里虽然已经支持类命名空间和模块但函数仍然是主要的定义 行为的地方。 TypeScript为JavaScript函数添加了额外的功能让我们可以更容易地使用。</p>\n<h3 id=\"Typescript-函数\"><a href=\"#Typescript-函数\" class=\"headerlink\" title=\"Typescript 函数\"></a>Typescript 函数</h3><p>和JavaScript一样TypeScript函数可以创建有名字的函数和匿名函数。 你可以随意选择适合应用程序的方式不论是定义一系列API函数还是只使用一次的函数。</p>\n<p>通过下面的例子可以迅速回想起这两种JavaScript中的函数</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">&#x2F;&#x2F; 命名函数\nfunction add(x, y) &#123;\n return x + y;\n&#125;\n\n\n&#x2F;&#x2F; 匿名函数\nlet myAdd &#x3D; function(x, y) &#123; return x + y; &#125;;</code></pre>\n<h2 id=\"函数类型\"><a href=\"#函数类型\" class=\"headerlink\" title=\"函数类型\"></a>函数类型</h2><p><strong>为函数定义类型</strong> 我们可以为函数本身添加返回值类型。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">函数():类型 &#123;&#125;</code></pre>\n<p>我们给函数添加类型:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function add(x: number, y: number): number &#123;\n return x + y;\n&#125;\n\n\nlet myAdd &#x3D; function(x: number, y: number): number &#123; return x + y; &#125;;</code></pre>\n<p>TypeScript能够根据返回语句自动推断出返回值类型因此我们通常省略它。</p>\n<h2 id=\"函数参数\"><a href=\"#函数参数\" class=\"headerlink\" title=\"函数参数\"></a>函数参数</h2><p>TypeScript里的每个函数参数都是必须的。 传递给一个函数的参数个数必须与函数期望的参数个数一致。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function buildName(firstName: string, lastName: string) &#123;\n return firstName + &quot; &quot; + lastName;\n&#125;\n&#x2F;&#x2F; error, too few parameters\nlet result1 &#x3D; buildName(&quot;Bob&quot;);\n\n\n&#x2F;&#x2F; error, too many parameters\nlet result2 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;, &quot;Sr.&quot;);\n\n\n&#x2F;&#x2F; 这种方式是正确的\nlet result3 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;);</code></pre>\n<h3 id=\"可选参数\"><a href=\"#可选参数\" class=\"headerlink\" title=\"可选参数\"></a>可选参数</h3><p>在TypeScript里我们可以在参数名旁使用 ? 实现可选参数的功能。 比如我们想让last name是可选的</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function buildName(firstName: string, lastName?: string) &#123;\n if (lastName)\n return firstName + &quot; &quot; + lastName;\n else\n return firstName;\n&#125;\n&#x2F;&#x2F; 现在这样也可以\nlet result1 &#x3D; buildName(&quot;Bob&quot;); \n\n\n&#x2F;&#x2F; error, too many parameters\nlet result2 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;, &quot;Sr.&quot;);\n\n\n&#x2F;&#x2F; 这种方式是正确的\nlet result3 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;);</code></pre>\n<p>注意: 可选参数必须跟在必须参数后面。 如果上例我们想让first name是可选的那么就必须调整它们的位置把first name放在后面。</p>\n<h3 id=\"默认参数\"><a href=\"#默认参数\" class=\"headerlink\" title=\"默认参数\"></a>默认参数</h3><p>在TypeScript里我们也可以为参数提供一个默认值。让我们修改上例把last name的默认值设置为”Smith”。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function buildName(firstName: string, lastName &#x3D; &quot;Smith&quot;) &#123;\n return firstName + &quot; &quot; + lastName;\n&#125;\n\n\n&#x2F;&#x2F; 这样是可以工作的 返回 &quot;Bob Smith&quot;\nlet result1 &#x3D; buildName(&quot;Bob&quot;);\n\n\n&#x2F;&#x2F; 这样也可以工作返回 &quot;Bob Smith&quot;\nlet result2 &#x3D; buildName(&quot;Bob&quot;, undefined);\n\n\n&#x2F;&#x2F; error, too many parameters\nlet result3 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;, &quot;Sr.&quot;);\n&#x2F;&#x2F; 这是正确的返回 &quot;Bob Adams&quot;\nlet result4 &#x3D; buildName(&quot;Bob&quot;, &quot;Adams&quot;);</code></pre>\n<h3 id=\"剩余参数\"><a href=\"#剩余参数\" class=\"headerlink\" title=\"剩余参数\"></a>剩余参数</h3><p>当你想同时操作多个参数,而你并不知道会有多少参数传递进来。 在JavaScript里你可以使用 arguments来访问所有传入的参数。 而在TypeScript里你可以使用 <strong>…变量名</strong> 把所有参数收集到一个变量里:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function buildName(firstName: string, ...restOfName: string[]) &#123;\n return firstName + &quot; &quot; + restOfName.join(&quot; &quot;);\n&#125;\n\n\nlet employeeName &#x3D; buildName(&quot;Joseph&quot;, &quot;Samuel&quot;, &quot;Lucas&quot;, &quot;MacKinzie&quot;);</code></pre>\n<p>剩余参数会被当做个数不限的可选参数。 可以一个都没有,同样也可以有任意个。</p>\n<p>这个省略号也会在带有剩余参数的函数类型定义上使用到:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function buildName(firstName: string, ...restOfName: string[]) &#123;\n return firstName + &quot; &quot; + restOfName.join(&quot; &quot;);\n&#125;</code></pre>\n<h2 id=\"箭头函数\"><a href=\"#箭头函数\" class=\"headerlink\" title=\"箭头函数\"></a>箭头函数</h2><h3 id=\"表现形式\"><a href=\"#表现形式\" class=\"headerlink\" title=\"表现形式\"></a>表现形式</h3><p>基本语法 ES6 允许使用“箭头”(=&gt;)定义函数 箭头函数相当于匿名函数,并且简化了函数定义 <strong>表现形式一:</strong> 包含一个表达式,连{ … }和return都省略掉了</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\"> x &#x3D;&gt; x * x\n&#x2F;&#x2F;等同于\nfunction (x) &#123;\n return x*x;\n&#125;;</code></pre>\n<p><strong>表示形式二:</strong> 包含多条语句,这时候就不能省略{ … }和return</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">x &#x3D;&gt; &#123;\nif (x &gt; 0) &#123;\n return x * x;\n&#125;\nelse &#123;\n return - x * x;\n&#125;\n&#125;</code></pre>\n<h3 id=\"this\"><a href=\"#this\" class=\"headerlink\" title=\"this\"></a>this</h3><p>箭头函数的引入有两个方面的作用:</p>\n<ul>\n<li>一是更简短的函数书写</li>\n<li>二是对this的词法解析。</li>\n</ul>\n<p>普通函数: this指向调用它的那个对象 箭头函数:不绑定this会捕获其所在的上下文的this值作为自己的this值,任何方法都改变不了其指向,如: call(),bind(),apply()</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">var obj &#x3D; &#123;\na: 10,\nb: () &#x3D;&gt; &#123;\nconsole.log(&#39;b this.a:&#39;,this.a); &#x2F;&#x2F; undefined\nconsole.log(&#39;b this:&#39;,this); &#x2F;&#x2F; Window\n &#125;,\n c: function() &#123;\nconsole.log(&#39;c this.a:&#39;,this.a); &#x2F;&#x2F; 10\nconsole.log(&#39;c this:&#39;,this); &#x2F;&#x2F; &#123;a: 10, b: ƒ, c: ƒ&#125;\n&#125;\n &#125;\nobj.b(); \nobj.c();</code></pre>\n<p>执行结果: <img src=\"https://www.w3cschool.cn/attachments/image/20190620/1561021902153358.png\" alt=\"\"></p>\n<h2 id=\"函数重载\"><a href=\"#函数重载\" class=\"headerlink\" title=\"函数重载\"></a>函数重载</h2><p>所谓函数重载就是同一个函数,根据传递的参数不同,会有不同的表现形式。</p>\n<p>JavaScript本身是没有重载这个概念不过可以模拟实现。 JavaScript 代码实例如下:</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">function func()&#123; \n if(arguments.length&#x3D;&#x3D;0)&#123; \n alert(&quot;欢迎来到w3cschool&quot;); \n &#125; \n else if(arguments.length&#x3D;&#x3D;1)&#123; \n alert(arguments[0]) \n &#125; \n&#125; \nfunc(); \nfunc(2);</code></pre>\n<p>上面代码利用arguments对象来判断传递参数的数量然后执行不同的代码。</p>\n<h3 id=\"TypeScript-函数重载\"><a href=\"#TypeScript-函数重载\" class=\"headerlink\" title=\"TypeScript 函数重载\"></a>TypeScript 函数重载</h3><p>TypeScript提供了重载功能TypeScript的函数重载只有一个函数体也就是说无论声明多少个同名且不同签名的函数它们共享一个函数体在调用时会根据传递实参类型的不同利用流程控制语句控制代码的执行。</p>\n<p>TypeScript代码实例如下:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function func(x:string):string;\nfunction func(x:number):number;\nfunction func(x:any):any&#123;\n if(typeof x&#x3D;&#x3D;&quot;string&quot;)&#123;\n return &quot;欢迎来到w3cschool&quot;\n &#125;else if(typeof x&#x3D;&#x3D;&quot;number&quot;)&#123;\n return 5\n &#125;\n&#125;</code></pre>\n<p>function func(x:any):any不是函数重载列表一部分所以上述代码只定义两个重载。</p>\n<p>重载函数的共用函数体部分如下:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function func(x:any):any&#123;\n if(typeof x&#x3D;&#x3D;&quot;string&quot;)&#123;\n return &quot;欢迎来到w3cschool&quot;\n &#125;else if(typeof x&#x3D;&#x3D;&quot;number&quot;)&#123;\n return 5\n &#125;\n&#125;</code></pre>\n<p>重载函数编译后的JavaScript代码:</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">function func(x) &#123;\n if (typeof x &#x3D;&#x3D; &quot;string&quot;) &#123;\n return &quot;欢迎来到w3cschool&quot;;\n &#125;\n else if (typeof x &#x3D;&#x3D; &quot;number&quot;) &#123;\n return 5;\n &#125;\n&#125;</code></pre>\n<p>由于JavaScript本身不支持重载所以TypeScript重载实质上为了方便调用者如何调用函数。</p>\n<h1 id=\"接口\"><a href=\"#接口\" class=\"headerlink\" title=\"接口\"></a>接口</h1><h2 id=\"接口介绍\"><a href=\"#接口介绍\" class=\"headerlink\" title=\"接口介绍\"></a>接口介绍</h2><p>在TypeScript里接口的作用就是为这些类型命名和为你的代码或第三方代码定义契约。</p>\n<h3 id=\"接口初探\"><a href=\"#接口初探\" class=\"headerlink\" title=\"接口初探\"></a>接口初探</h3><p>下面通过一个简单示例来观察接口是如何工作的:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function printLabel(labelledObj: &#123; label: string &#125;) &#123;\n console.log(labelledObj.label);\n&#125;\n\n\nlet myObj &#x3D; &#123; size: 10, label: &quot;Size 10 Object&quot; &#125;;\nprintLabel(myObj);</code></pre>\n<p>类型检查器会查看 printLabel 的调用。 printLabel 有一个参数,并要求这个对象参数有一个名为 label 类型为 string 的属性。</p>\n<p>需要注意的是,我们传入的对象参数实际上会包含很多属性,但是编译器只会检查那些必需的属性是否存在,并且其类型是否匹配。</p>\n<p>下面我们重写上面的例子,这次使用接口来描述:必须包含一个 label 属性且类型为 string </p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">interface LabelledValue &#123;\n label: string;\n&#125;\n\n\nfunction printLabel(labelledObj: LabelledValue) &#123;\n console.log(labelledObj.label);\n&#125;\n\n\nlet myObj &#x3D; &#123;size: 10, label: &quot;Size 10 Object&quot;&#125;;\nprintLabel(myObj);</code></pre>\n<p><code>LabelledValue</code>接口就好比一个名字,用来描述上面例子里的要求。 它代表了有一个 label 属性且类型为 string 的对象。</p>\n<p>只要传入的对象满足上面提到的必要条件,那么它就是被允许的。</p>\n<p>类型检查器不会去检查属性的顺序,只要相应的属性存在并且类型也是对的就可以。</p>\n<h2 id=\"可选属性\"><a href=\"#可选属性\" class=\"headerlink\" title=\"可选属性\"></a>可选属性</h2><p>接口里的属性不全都是必需的。 有些是只在某些条件下存在,或者根本不存在。 可选属性在应用<code>“option bags”</code>模式时很常用,即给函数传入的参数对象中只有部分属性赋值了。</p>\n<p>下面是应用了<code>“option bags”</code>的例子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface SquareConfig &#123;\n color?: string;\n width?: number;\n&#125;\n\n\nfunction createSquare(config: SquareConfig): &#123;color: string; area: number&#125; &#123;\n let newSquare &#x3D; &#123;color: &quot;white&quot;, area: 100&#125;;\n if (config.color) &#123;\n newSquare.color &#x3D; config.color;\n &#125;\n if (config.width) &#123;\n newSquare.area &#x3D; config.width * config.width;\n &#125;\n return newSquare;\n&#125;\n\n\nlet mySquare &#x3D; createSquare(&#123;color: &quot;black&quot;&#125;);</code></pre>\n<p>带有可选属性的接口与普通的接口定义差不多,只是在可选属性名字定义的后面加一个<code>?</code>符号。</p>\n<p>可选属性的好处之一是可以对可能存在的属性进行预定义,好处之二是可以捕获引用了不存在的属性时的错误。 比如,我们故意将 <code>createSquare</code>里的<code>color</code>属性名拼错,就会得到一个错误提示:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface SquareConfig &#123;\n color?: string;\n width?: number;\n&#125;\n\n\nfunction createSquare(config: SquareConfig): &#123; color: string; area: number &#125; &#123;\n let newSquare &#x3D; &#123;color: &quot;white&quot;, area: 100&#125;;\n if (config.color) &#123;\n &#x2F;&#x2F; Error: Property &#39;clor&#39; does not exist on type &#39;SquareConfig&#39;\n newSquare.color &#x3D; config.clor;\n &#125;\n if (config.width) &#123;\n newSquare.area &#x3D; config.width * config.width;\n &#125;\n return newSquare;\n&#125;\n\n\nlet mySquare &#x3D; createSquare(&#123;color: &quot;black&quot;&#125;);</code></pre>\n<h2 id=\"只读属性\"><a href=\"#只读属性\" class=\"headerlink\" title=\"只读属性\"></a>只读属性</h2><p>可以在属性名前用 <code>readonly</code>来指定只读属性:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface Point &#123;\n readonly x: number;\n readonly y: number;\n&#125;</code></pre>\n<p>可以通过赋值一个对象字面量来构造一个<code>Point</code>。 赋值后, x 和 y 再也不能被改变了。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let p1: Point &#x3D; &#123; x: 10, y: 20 &#125;;\np1.x &#x3D; 5; &#x2F;&#x2F; error!</code></pre>\n<p>TypeScript 具有 ReadonlyArray<T> 类型,它与 Array<T> 相似,只是把所有可变方法去掉了,因此可以确保数组创建后再也不能被修改:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let a: number[] &#x3D; [1, 2, 3, 4];\nlet ro: ReadonlyArray&lt;number&gt; &#x3D; a;\nro[0] &#x3D; 12; &#x2F;&#x2F; error!\nro.push(5); &#x2F;&#x2F; error!\nro.length &#x3D; 100; &#x2F;&#x2F; error!\na &#x3D; ro; &#x2F;&#x2F; error!</code></pre>\n<p>上面代码的最后一行,可以看到就算把整个<code>ReadonlyArray</code>赋值到一个普通数组也是不可以的。 但是你可以用类型断言重写:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">a &#x3D; ro as number[];</code></pre>\n<h3 id=\"readonly-const使用时机\"><a href=\"#readonly-const使用时机\" class=\"headerlink\" title=\"readonly, const使用时机\"></a>readonly, const使用时机</h3><p>做为变量使用的话用 const ,若做为属性则使用 readonly 。</p>\n<h2 id=\"函数类型-1\"><a href=\"#函数类型-1\" class=\"headerlink\" title=\"函数类型\"></a>函数类型</h2><p>接口能够描述JavaScript中对象拥有的各种各样的外形。 除了描述带有属性的普通对象外,接口也可以描述函数类型。</p>\n<p>为了使用接口表示函数类型,我们需要给接口定义一个调用签名。 它就像是一个只有参数列表和返回值类型的函数定义。参数列表里的每个参数都需要名字和类型。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface SearchFunc &#123;\n (source: string, subString: string): boolean;\n&#125;</code></pre>\n<p>这样定义后,我们可以像使用其它接口一样使用这个函数类型的接口。 下例展示了如何创建一个函数类型的变量,并将一个同类型的函数赋值给这个变量。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let mySearch: SearchFunc;\nmySearch &#x3D; function(source: string, subString: string) &#123;\n let result &#x3D; source.search(subString);\n return result &gt; -1;\n&#125;</code></pre>\n<p>对于函数类型的类型检查来说,函数的参数名不需要与接口里定义的名字相匹配。 比如,我们使用下面的代码重写上面的例子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let mySearch: SearchFunc;\nmySearch &#x3D; function(src: string, sub: string): boolean &#123;\n let result &#x3D; src.search(sub);\n return result &gt; -1;\n&#125;</code></pre>\n<p>函数的参数会逐个进行检查,要求对应位置上的参数类型是兼容的。 如果你不想指定类型TypeScript的类型系统会推断出参数类型因为函数直接赋值给了 <code>SearchFunc</code>类型变量。 函数的返回值类型是通过其返回值推断出来的(此例是 <code>false</code>和<code>true</code>)。 如果让这个函数返回数字或字符串,类型检查器会警告我们函数的返回值类型与<code>SearchFunc</code>接口中的定义不匹配。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let mySearch: SearchFunc;\nmySearch &#x3D; function(src, sub) &#123;\n let result &#x3D; src.search(sub);\n return result &gt; -1;\n&#125;</code></pre>\n<h2 id=\"实现接口\"><a href=\"#实现接口\" class=\"headerlink\" title=\"实现接口\"></a>实现接口</h2><p>与C#或Java里接口的基本作用一样TypeScript也能够用它来明确的强制一个类去符合某种契约。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface ClockInterface &#123;\n currentTime: Date;\n&#125;\n\n\nclass Clock implements ClockInterface &#123;\n currentTime: Date;\n constructor(h: number, m: number) &#123; &#125;\n&#125;</code></pre>\n<p>你也可以在接口中描述一个方法,在类里实现它,如同下面的<code>setTime</code>方法一样:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface ClockInterface &#123;\n currentTime: Date;\n setTime(d: Date);\n&#125;\n\n\nclass Clock implements ClockInterface &#123;\n currentTime: Date;\n setTime(d: Date) &#123;\n this.currentTime &#x3D; d;\n &#125;\n constructor(h: number, m: number) &#123; &#125;\n&#125;</code></pre>\n<p>接口描述了类的公共部分,而不是公共和私有两部分。 它不会帮你检查类是否具有某些私有成员。</p>\n<h2 id=\"继承接口\"><a href=\"#继承接口\" class=\"headerlink\" title=\"继承接口\"></a>继承接口</h2><p>和类一样,接口也可以相互继承。 这让我们能够从一个接口里复制成员到另一个接口里,可以更灵活地将接口分割到可重用的模块里。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface Shape &#123;\n color: string;\n&#125;\n\n\ninterface Square extends Shape &#123;\n sideLength: number;\n&#125;\n\n\nlet square &#x3D; &lt;Square&gt;&#123;&#125;;\nsquare.color &#x3D; &quot;blue&quot;;\nsquare.sideLength &#x3D; 10;</code></pre>\n<p>一个接口可以继承多个接口,创建出多个接口的合成接口。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">interface Shape &#123;\n color: string;\n&#125;\n\n\ninterface PenStroke &#123;\n penWidth: number;\n&#125;\n\n\ninterface Square extends Shape, PenStroke &#123;\n sideLength: number;\n&#125;\n\n\nlet square &#x3D; &lt;Square&gt;&#123;&#125;;\nsquare.color &#x3D; &quot;blue&quot;;\nsquare.sideLength &#x3D; 10;\nsquare.penWidth &#x3D; 5.0;</code></pre>\n<h1 id=\"类\"><a href=\"#类\" class=\"headerlink\" title=\"类\"></a>类</h1><h2 id=\"类介绍\"><a href=\"#类介绍\" class=\"headerlink\" title=\"类介绍\"></a>类介绍</h2><p>传统的JavaScript程序使用函数和基于原型的继承来创建可重用的组件但对于熟悉使用面向对象方式的程序员来讲就有些棘手因为他们用的是基于类的继承并且对象是由类构建出来的。 从ECMAScript 2015也就是ECMAScript 6开始JavaScript程序员将能够使用基于类的面向对象的方式。</p>\n<p>使用TypeScript我们允许开发者现在就使用这些特性并且编译后的JavaScript可以在所有主流浏览器和平台上运行而不需要等到下个JavaScript版本。</p>\n<h3 id=\"类-1\"><a href=\"#类-1\" class=\"headerlink\" title=\"类\"></a>类</h3><p>下面看一个使用类的例子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Greeter &#123;\n greeting: string;\n constructor(message: string) &#123;\n this.greeting &#x3D; message;\n &#125;\n greet() &#123;\n return &quot;Hello, &quot; + this.greeting;\n &#125;\n&#125;\n\n\nlet greeter &#x3D; new Greeter(&quot;world&quot;);</code></pre>\n<p>如果你使用过C#或Java你会对这种语法非常熟悉。 我们声明一个 <code>Greeter</code>类。这个类有3个成员一个叫做 <code>greeting</code>的属性,一个构造函数和一个 greet方法。</p>\n<p>你会注意到,我们在引用任何一个类成员的时候都用了 <code>this</code>。 它表示我们访问的是类的成员。</p>\n<p>最后一行,我们使用 <code>new</code> 构造了 Greeter类的一个实例。 它会调用之前定义的构造函数创建一个Greeter类型的新对象并执行构造函数初始化它。</p>\n<h2 id=\"继承\"><a href=\"#继承\" class=\"headerlink\" title=\"继承\"></a>继承</h2><p>在TypeScript里我们可以使用常用的面向对象模式。 基于类的程序设计中一种最基本的模式是允许使用继承来扩展现有的类。</p>\n<p>看下面的例子:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Animal &#123;\n move(distanceInMeters: number &#x3D; 0) &#123;\n console.log(&#96;Animal moved $&#123;distanceInMeters&#125;m.&#96;);\n &#125;\n&#125;\n\n\nclass Dog extends Animal &#123;\n bark() &#123;\n console.log(&#39;Woof! Woof!&#39;);\n &#125;\n&#125;\n\n\nconst dog &#x3D; new Dog();\ndog.bark();\ndog.move(10);\ndog.bark();</code></pre>\n<p>这个例子展示了最基本的继承:类从基类中继承了属性和方法。 这里, Dog是一个 <code>派生类</code>,它派生自<code>Animal 基类</code>,通过 <code>extends关键字</code>。 派生类通常被称作 子类,<strong>基类通常被称作 超类</strong>。</p>\n<p>因为 Dog继承了 Animal的功能因此我们可以创建一个 Dog的实例它能够 <code>bark() 和 move()</code>。</p>\n<p>下面我们来看个更加复杂的例子。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Animal &#123;\n name: string;\n constructor(theName: string) &#123; this.name &#x3D; theName; &#125;\n move(distanceInMeters: number &#x3D; 0) &#123;\n console.log(&#96;$&#123;this.name&#125; moved $&#123;distanceInMeters&#125;m.&#96;);\n &#125;\n&#125;\n\n\nclass Snake extends Animal &#123;\n constructor(name: string) &#123; super(name); &#125;\n move(distanceInMeters &#x3D; 5) &#123;\n console.log(&quot;Slithering...&quot;);\n super.move(distanceInMeters);\n &#125;\n&#125;\n\n\nclass Horse extends Animal &#123;\n constructor(name: string) &#123; super(name); &#125;\n move(distanceInMeters &#x3D; 45) &#123;\n console.log(&quot;Galloping...&quot;);\n super.move(distanceInMeters);\n &#125;\n&#125;\n\n\nlet sam &#x3D; new Snake(&quot;Sammy the Python&quot;);\nlet tom: Animal &#x3D; new Horse(&quot;Tommy the Palomino&quot;);\n\n\nsam.move();\ntom.move(34);</code></pre>\n<p>这个例子展示了一些上面没有提到的特性。 这一次,我们使用 extends关键字创建了 Animal的两个子类 <code>Horse 和 Snake</code>。</p>\n<p>与前一个例子的不同点是,派生类包含了一个构造函数,它必须调用 <code>super()</code>,它会执行基类的构造函数。 而且,在构造函数里访问 this的属性之前我们 一定要调用 <code>super()</code>。 这个是TypeScript强制执行的一条重要规则。</p>\n<p>这个例子演示了如何在子类里可以重写父类的方法。 Snake类和 Horse类都创建了 move方法它们重写了从 Animal继承来的 move方法使得 move方法根据不同的类而具有不同的功能。 注意即使tom被声明为 Animal类型但因为它的值是 Horse调用 tom.move(34)时,它会调用 Horse里重写的方法</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">Slithering...\nSammy the Python moved 5m.\nGalloping...\nTommy the Palomino moved 34m.</code></pre>\n<h2 id=\"公共,私有与受保护的修饰符\"><a href=\"#公共,私有与受保护的修饰符\" class=\"headerlink\" title=\"公共,私有与受保护的修饰符\"></a>公共,私有与受保护的修饰符</h2><h3 id=\"public\"><a href=\"#public\" class=\"headerlink\" title=\"public\"></a>public</h3><p>在TypeScript里成员都默认为 <code>public</code>。</p>\n<p>你也可以明确的将一个成员标记成 public。 我们可以用下面的方式来重写 Animal类</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Animal &#123;\n public name: string;\n public constructor(theName: string) &#123; this.name &#x3D; theName; &#125;\n public move(distanceInMeters: number) &#123;\n console.log(&#96;$&#123;this.name&#125; moved $&#123;distanceInMeters&#125;m.&#96;);\n &#125;\n&#125;</code></pre>\n<h2 id=\"private\"><a href=\"#private\" class=\"headerlink\" title=\"private\"></a>private</h2><p>当成员被标记成 <code>private</code>时,它就不能在声明它的类的外部访问。比如:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Animal &#123;\n private name: string;\n constructor(theName: string) &#123; this.name &#x3D; theName; &#125;\n&#125;\n\n\nnew Animal(&quot;Cat&quot;).name; &#x2F;&#x2F; 错误: &#39;name&#39; 是私有的.</code></pre>\n<h2 id=\"protected\"><a href=\"#protected\" class=\"headerlink\" title=\"protected\"></a>protected</h2><p>protected修饰符与 private修饰符的行为很相似但有一点不同 protected成员在派生类中仍然可以访问。例如</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Person &#123;\n protected name: string;\n constructor(name: string) &#123; this.name &#x3D; name; &#125;\n&#125;\n\n\nclass Employee extends Person &#123;\n private department: string;\n\n\n constructor(name: string, department: string) &#123;\n super(name)\n this.department &#x3D; department;\n &#125;\n\n\n public getElevatorPitch() &#123;\n return &#96;Hello, my name is $&#123;this.name&#125; and I work in $&#123;this.department&#125;.&#96;;\n &#125;\n&#125;\n\n\nlet howard &#x3D; new Employee(&quot;Howard&quot;, &quot;Sales&quot;);\nconsole.log(howard.getElevatorPitch());\nconsole.log(howard.name); &#x2F;&#x2F; 错误</code></pre>\n<p>注意,我们不能在 Person类外使用 name但是我们仍然可以通过 Employee类的实例方法访问因为 Employee是由 Person派生而来的。</p>\n<p>构造函数也可以被标记成 protected。 这意味着这个类不能在包含它的类外被实例化,但是能被继承。比如,</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Person &#123;\n protected name: string;\n protected constructor(theName: string) &#123; this.name &#x3D; theName; &#125;\n&#125;\n\n\n&#x2F;&#x2F; Employee 能够继承 Person\nclass Employee extends Person &#123;\n private department: string;\n\n\n constructor(name: string, department: string) &#123;\n super(name);\n this.department &#x3D; department;\n &#125;\n\n\n public getElevatorPitch() &#123;\n return &#96;Hello, my name is $&#123;this.name&#125; and I work in $&#123;this.department&#125;.&#96;;\n &#125;\n&#125;\n\n\nlet howard &#x3D; new Employee(&quot;Howard&quot;, &quot;Sales&quot;);\nlet john &#x3D; new Person(&quot;John&quot;); &#x2F;&#x2F; 错误: &#39;Person&#39; 的构造函数是被保护的.</code></pre>\n<h2 id=\"readonly修饰符\"><a href=\"#readonly修饰符\" class=\"headerlink\" title=\"readonly修饰符\"></a>readonly修饰符</h2><p>你可以使用 readonly关键字将属性设置为只读的。 只读属性必须在声明时或构造函数里被初始化。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Octopus &#123;\n readonly name: string;\n readonly numberOfLegs: number &#x3D; 8;\n constructor (theName: string) &#123;\n this.name &#x3D; theName;\n &#125;\n&#125;\nlet dad &#x3D; new Octopus(&quot;Man with the 8 strong legs&quot;);\ndad.name &#x3D; &quot;Man with the 3-piece suit&quot;; &#x2F;&#x2F; 错误! name 是只读的.</code></pre>\n<h3 id=\"参数属性\"><a href=\"#参数属性\" class=\"headerlink\" title=\"参数属性\"></a>参数属性</h3><p>在上面的例子中,我们不得不定义一个受保护的成员 name和一个构造函数参数 theName在 Person类里并且立刻给 name和 theName赋值。 这种情况经常会遇到。 参数属性可以方便地让我们在一个地方定义并初始化一个成员。 下面的例子是对之前 Animal类的修改版使用了参数属性</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Animal &#123;\n constructor(private name: string) &#123; &#125;\n move(distanceInMeters: number) &#123;\n console.log(&#96;$&#123;this.name&#125; moved $&#123;distanceInMeters&#125;m.&#96;);\n &#125;\n&#125;</code></pre>\n<p>注意看我们是如何舍弃了 theName仅在构造函数里使用 private name: string参数来创建和初始化 name成员。 我们把声明和赋值合并至一处。</p>\n<p>参数属性通过给构造函数参数添加一个访问限定符来声明。 使用 private限定一个参数属性会声明并初始化一个私有成员对于 public和 protected来说也是一样。</p>\n<h2 id=\"存取器\"><a href=\"#存取器\" class=\"headerlink\" title=\"存取器\"></a>存取器</h2><p>TypeScript支持通过getters/setters来截取对对象成员的访问。 它能帮助你有效的控制对对象成员的访问。</p>\n<p>下面来看如何把一个简单的类改写成使用 get和 set。 首先,我们从一个没有使用存取器的例子开始。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Employee &#123;\n fullName: string;\n&#125;\n\nlet employee &#x3D; new Employee();\nemployee.fullName &#x3D; &quot;Bob Smith&quot;;\nif (employee.fullName) &#123;\n console.log(employee.fullName);\n&#125;</code></pre>\n<p>我们可以随意的设置 fullName这是非常方便的但是这也可能会带来麻烦。</p>\n<p>下面这个版本里,我们先检查用户密码是否正确,然后再允许其修改员工信息。 我们把对 fullName的直接访问改成了可以检查密码的 set方法。 我们也加了一个 get方法让上面的例子仍然可以工作。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let passcode &#x3D; &quot;secret passcode&quot;;\n\nclass Employee &#123;\n private _fullName: string;\n\n get fullName(): string &#123;\n return this._fullName;\n &#125;\n\n set fullName(newName: string) &#123;\n if (passcode &amp;&amp; passcode &#x3D;&#x3D; &quot;secret passcode&quot;) &#123;\n this._fullName &#x3D; newName;\n &#125;\n else &#123;\n console.log(&quot;Error: Unauthorized update of employee!&quot;);\n &#125;\n &#125;\n&#125;\n\nlet employee &#x3D; new Employee();\nemployee.fullName &#x3D; &quot;Bob Smith&quot;;\nif (employee.fullName) &#123;\n alert(employee.fullName);\n&#125;</code></pre>\n<p>我们可以修改一下密码,来验证一下存取器是否是工作的。当密码不对时,会提示我们没有权限去修改员工。</p>\n<p>对于存取器有下面几点需要注意的:</p>\n<p>首先存取器要求你将编译器设置为输出ECMAScript 5或更高。 不支持降级到ECMAScript 3。 其次,只带有 get不带有 set的存取器自动被推断为 readonly。 这在从代码生成 .d.ts文件时是有帮助的因为利用这个属性的用户会看到不允许够改变它的值。</p>\n<h2 id=\"静态属性\"><a href=\"#静态属性\" class=\"headerlink\" title=\"静态属性\"></a>静态属性</h2><p>到目前为止,我们只讨论了类的实例成员,那些仅当类被实例化的时候才会被初始化的属性。 我们也可以创建类的静态成员,这些属性存在于类本身上面而不是类的实例上。 在这个例子里我们使用static定义 origin因为它是所有网格都会用到的属性。 每个实例想要访问这个属性的时候,都要在 origin前面加上类名。 如同在实例属性上使用 this.前缀来访问属性一样,这里我们使用 Grid.来访问静态属性。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class Grid &#123;\n static origin &#x3D; &#123;x: 0, y: 0&#125;;\n calculateDistanceFromOrigin(point: &#123;x: number; y: number;&#125;) &#123;\n let xDist &#x3D; (point.x - Grid.origin.x);\n let yDist &#x3D; (point.y - Grid.origin.y);\n return Math.sqrt(xDist * xDist + yDist * yDist) &#x2F; this.scale;\n &#125;\n constructor (public scale: number) &#123; &#125;\n&#125;\n\nlet grid1 &#x3D; new Grid(1.0); &#x2F;&#x2F; 1x scale\nlet grid2 &#x3D; new Grid(5.0); &#x2F;&#x2F; 5x scale\n\nconsole.log(grid1.calculateDistanceFromOrigin(&#123;x: 10, y: 10&#125;));\nconsole.log(grid2.calculateDistanceFromOrigin(&#123;x: 10, y: 10&#125;));</code></pre>\n<h2 id=\"抽象类\"><a href=\"#抽象类\" class=\"headerlink\" title=\"抽象类\"></a>抽象类</h2><p>抽象类做为其它派生类的基类使用。 它们一般不会直接被实例化。 不同于接口,抽象类可以包含成员的实现细节。 abstract关键字是用于定义抽象类和在抽象类内部定义抽象方法。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">abstract class Animal &#123;\n abstract makeSound(): void;\n move(): void &#123;\n console.log(&#39;roaming the earch...&#39;);\n &#125;\n&#125;</code></pre>\n<p>抽象类中的抽象方法不包含具体实现并且必须在派生类中实现。 抽象方法的语法与接口方法相似。 两者都是定义方法签名但不包含方法体。 然而,抽象方法必须包含 abstract关键字并且可以包含访问修饰符。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">abstract class Department &#123;\n\n constructor(public name: string) &#123;\n &#125;\n\n printName(): void &#123;\n console.log(&#39;Department name: &#39; + this.name);\n &#125;\n\n abstract printMeeting(): void; &#x2F;&#x2F; 必须在派生类中实现\n&#125;\n\nclass AccountingDepartment extends Department &#123;\n\n constructor() &#123;\n super(&#39;Accounting and Auditing&#39;); &#x2F;&#x2F; 在派生类的构造函数中必须调用 super()\n &#125;\n\n printMeeting(): void &#123;\n console.log(&#39;The Accounting Department meets each Monday at 10am.&#39;);\n &#125;\n\n generateReports(): void &#123;\n console.log(&#39;Generating accounting reports...&#39;);\n &#125;\n&#125;\n\nlet department: Department; &#x2F;&#x2F; 允许创建一个对抽象类型的引用\ndepartment &#x3D; new Department(); &#x2F;&#x2F; 错误: 不能创建一个抽象类的实例\ndepartment &#x3D; new AccountingDepartment(); &#x2F;&#x2F; 允许对一个抽象子类进行实例化和赋值\ndepartment.printName();\ndepartment.printMeeting();\ndepartment.generateReports(); &#x2F;&#x2F; 错误: 方法在声明的抽象类中不存在</code></pre>\n<h1 id=\"泛型\"><a href=\"#泛型\" class=\"headerlink\" title=\"泛型\"></a>泛型</h1><h2 id=\"泛型介绍\"><a href=\"#泛型介绍\" class=\"headerlink\" title=\"泛型介绍\"></a>泛型介绍</h2><p>软件工程中我们不仅要创建一致的定义良好的API同时也要考虑可重用性。 组件不仅能够支持当前的数据类型,同时也能支持未来的数据类型,这在创建大型系统时为你提供了十分灵活的功能。</p>\n<p>在像C#和Java这样的语言中可以使用泛型来创建可重用的组件一个组件可以支持多种类型的数据。 这样用户就可以以自己的数据类型来使用组件。</p>\n<h2 id=\"非泛型例子\"><a href=\"#非泛型例子\" class=\"headerlink\" title=\"非泛型例子\"></a>非泛型例子</h2><p>下面来创建 identity函数。 这个函数会返回任何传入它的值。 你可以把这个函数当成是 echo命令。</p>\n<p>非泛型例子1</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function identity(arg: number): number &#123;\n return arg;\n&#125;</code></pre>\n<p>非泛型例子2: 使用any类型来定义函数</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function identity(arg: any): any &#123;\n return arg;\n&#125;</code></pre>\n<p>使用any类型会导致这个函数可以接收任何类型的arg参数这样就丢失了一些信息传入的类型与返回的类型应该是相同的。如果我们传入一个数字我们只知道任何类型的值都有可能被返回。</p>\n<h2 id=\"泛型的例子\"><a href=\"#泛型的例子\" class=\"headerlink\" title=\"泛型的例子\"></a>泛型的例子</h2><p>我们需要一种方法使返回值的类型与传入参数的类型是相同的。 这里,我们使用了 <strong>类型变量</strong>,它是一种特殊的变量,只用于表示类型而不是值。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">function identity&lt;T&gt;(arg: T): T &#123;\n return arg;\n&#125;</code></pre>\n<p>我们给identity添加了类型变量T。 T帮助我们捕获用户传入的类型比如number之后我们就可以使用这个类型。 之后我们再次使用了 T当做返回值类型。现在我们可以知道参数类型与返回值类型是相同的了。 这允许我们跟踪函数里使用的类型的信息。</p>\n<p>我们把这个版本的identity函数叫做泛型因为它可以适用于多个类型。 不同于使用 any它不会丢失信息像第一个例子那像保持准确性传入数值类型并返回数值类型。</p>\n<h2 id=\"泛型类\"><a href=\"#泛型类\" class=\"headerlink\" title=\"泛型类\"></a>泛型类</h2><p>泛型类看上去与泛型接口差不多。 泛型类使用( &lt;&gt;)括起泛型类型,跟在类名后面。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">class GenericNumber&lt;T&gt; &#123;\n zeroValue: T;\n add: (x: T, y: T) &#x3D;&gt; T;\n&#125;\n\n\nlet myGenericNumber &#x3D; new GenericNumber&lt;number&gt;();\nmyGenericNumber.zeroValue &#x3D; 0;\nmyGenericNumber.add &#x3D; function(x, y) &#123; return x + y; &#125;;</code></pre>\n<p>GenericNumber类的使用是十分直观的并且你可能已经注意到了没有什么去限制它只能使用number类型。 也可以使用字符串或其它更复杂的类型。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let stringNumeric &#x3D; new GenericNumber&lt;string&gt;();\nstringNumeric.zeroValue &#x3D; &quot;&quot;;\nstringNumeric.add &#x3D; function(x, y) &#123; return x + y; &#125;;\n\n\nconsole.log(stringNumeric.add(stringNumeric.zeroValue, &quot;test&quot;));</code></pre>\n<p>与接口一样,直接把泛型类型放在类后面,可以帮助我们确认类的所有属性都在使用相同的类型。</p>\n<p>我们在类那节说过,类有两部分:静态部分和实例部分。 泛型类指的是实例部分的类型,所以类的静态属性不能使用这个泛型类型。</p>\n<h1 id=\"枚举-1\"><a href=\"#枚举-1\" class=\"headerlink\" title=\"枚举\"></a>枚举</h1><p>默认情况下,枚举是基于 0 的,也就是说第一个值是 0后面的值依次递增。不要担心当中的每一个值都可以显式指定只要不出现重复即可没有被显式指定的值都会在前一个值的基础上递增。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red, Green, Blue&#125;\nlet c: Color &#x3D; Color.Green; &#x2F;&#x2F; 1</code></pre>\n<p>或者</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red &#x3D; 1, Green, Blue &#x3D; 4&#125;\nlet c: Color &#x3D; Color.Green; &#x2F;&#x2F; 2</code></pre>\n<p>枚举有一个很方便的特性,就是您也可以向枚举传递一个数值,然后获取它对应的名称值。举个例子,如果我们有一个值 2但是不清楚在 Color 枚举中与之对应的名称是什么,我们就可以通过以下的方式来进行检索:</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">enum Color &#123;Red &#x3D; 1, Green, Blue&#125;\nlet colorName: string &#x3D; Color[2]; &#x2F;&#x2F; &#39;Green&#39;</code></pre>\n<p>但是像上面的这种写法不是太好,因为如果您给定的数值没有与之对应的枚举项,那么结果就是 undefined。所以如果您想要得到指定枚举项的字符串名称可以使用类似这样的写法</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">let colorName: string &#x3D; Color[Color.Green]; &#x2F;&#x2F; &#39;Green&#39;</code></pre>\n<h1 id=\"命名空间\"><a href=\"#命名空间\" class=\"headerlink\" title=\"命名空间\"></a>命名空间</h1><p>TypeScript里使用命名空间之前叫做“内部模块”来组织你的代码。任何使用 module关键字来声明一个内部模块的地方都应该使用namespace关键字来替换。 这就避免了让新的使用者被相似的名称所迷惑。</p>\n<h3 id=\"命名空间介绍\"><a href=\"#命名空间介绍\" class=\"headerlink\" title=\"命名空间介绍\"></a>命名空间介绍</h3><p>下面的例子里把所有与验证器相关的类型都放到一个叫做Validation的命名空间里。 因为我们想让这些接口和类在命名空间之外也是可访问的,所以需要使用 export。 相反的,变量 lettersRegexp和numberRegexp是实现的细节不需要导出因此它们在命名空间外是不能访问的。 在文件末尾的测试代码里,由于是在命名空间之外访问,因此需要限定类型的名称,比如 Validation.LettersOnlyValidator。</p>\n<pre class=\"line-numbers language-typescript\" data-language=\"typescript\"><code class=\"language-typescript\">namespace Validation &#123;\n export interface StringValidator &#123;\n isAcceptable(s: string): boolean;\n &#125;\n\n\n const lettersRegexp &#x3D; &#x2F;^[A-Za-z]+$&#x2F;;\n const numberRegexp &#x3D; &#x2F;^[0-9]+$&#x2F;;\n\n\n export class LettersOnlyValidator implements StringValidator &#123;\n isAcceptable(s: string) &#123;\n return lettersRegexp.test(s);\n &#125;\n &#125;\n\n\n export class ZipCodeValidator implements StringValidator &#123;\n isAcceptable(s: string) &#123;\n return s.length &#x3D;&#x3D;&#x3D; 5 &amp;&amp; numberRegexp.test(s);\n &#125;\n &#125;\n&#125;\n\n\n&#x2F;&#x2F; Some samples to try\nlet strings &#x3D; [&quot;Hello&quot;, &quot;98052&quot;, &quot;101&quot;];\n\n\n&#x2F;&#x2F; Validators to use\nlet validators: &#123; [s: string]: Validation.StringValidator; &#125; &#x3D; &#123;&#125;;\nvalidators[&quot;ZIP code&quot;] &#x3D; new Validation.ZipCodeValidator();\nvalidators[&quot;Letters only&quot;] &#x3D; new Validation.LettersOnlyValidator();\n\n\n&#x2F;&#x2F; Show whether each string passed each validator\nfor (let s of strings) &#123;\n for (let name in validators) &#123;\n console.log(&#96;&quot;$&#123; s &#125;&quot; - $&#123; validators[name].isAcceptable(s) ? &quot;matches&quot; : &quot;does not match&quot; &#125; $&#123; name &#125;&#96;);\n &#125;\n&#125;</code></pre>","categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"}]},{"title":"win电脑安装绿色版MySQL8","slug":"win-dian-nao-an-zhuang-lv-se-ban-mysql8","date":"2024-03-19T05:17:52.000Z","updated":"2024-03-19T05:52:31.395Z","comments":true,"path":"/post/win-dian-nao-an-zhuang-lv-se-ban-mysql8/","link":"","excerpt":"","content":"<h1 id=\"一、下载压缩包\"><a href=\"#一、下载压缩包\" class=\"headerlink\" title=\"一、下载压缩包\"></a>一、下载压缩包</h1><p>下载mysql server的zip文件地址<a href=\"https://dev.mysql.com/downloads/file/?id=526085\">Windows (x86, 64-bit), ZIP Archive</a></p>\n<p>解压后:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/win-dian-nao-an-zhuang-lv-se-ban-mysql8/2024-03-19-13-28-15-image.png\" alt=\"\"></p>\n<h1 id=\"二、创建配置文件(可忽略)\"><a href=\"#二、创建配置文件(可忽略)\" class=\"headerlink\" title=\"二、创建配置文件(可忽略)\"></a>二、创建配置文件(可忽略)</h1><p>配置文件可存放位置及名称:</p>\n<ul>\n<li><p>C:\\WINDOWS\\my.ini</p>\n</li>\n<li><p>C:\\WINDOWS\\my.cnf</p>\n</li>\n<li><p>C:\\my.ini</p>\n</li>\n<li><p>C:\\my.cnf</p>\n</li>\n<li><p>解压目录的根目录下mysql-8.3.0-winx64\\my.ini </p>\n</li>\n<li><p>解压目录的根目录下mysql-8.3.0-winx64\\my.cnf</p>\n</li>\n</ul>\n<h1 id=\"三、初始化数据库\"><a href=\"#三、初始化数据库\" class=\"headerlink\" title=\"三、初始化数据库\"></a>三、初始化数据库</h1><p>以管理员身份运行<code>cmd</code>,进入到<code>bin</code>目录运行下面的命令创建mysql默认的数据库并创建一个root账号空密码</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mysqld --initialize-insecure</code></pre>\n<h1 id=\"四、启动MySQL服务\"><a href=\"#四、启动MySQL服务\" class=\"headerlink\" title=\"四、启动MySQL服务\"></a>四、启动MySQL服务</h1><p>我使用的是安装到服务的方式,执行下面的命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mysqld --install-manual</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/win-dian-nao-an-zhuang-lv-se-ban-mysql8/2024-03-19-13-43-14-image.png\" alt=\"\"></p>\n<p>默认创建的服务名称为MySQL然后在服务中启动</p>\n<p><img src=\"https://img.huangge1199.cn/blog/win-dian-nao-an-zhuang-lv-se-ban-mysql8/2024-03-19-13-44-34-image.png\" alt=\"\"></p>\n<p>也可以直接运行一下命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mysqld</code></pre>\n<p>这是最简单的方式了,但是无法安装到服务中,其他详细的可参看帮助说明</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mysqld --verbose --help | more</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/win-dian-nao-an-zhuang-lv-se-ban-mysql8/2024-03-19-13-39-49-image.png\" alt=\"\"></p>\n<p>红色框内的是安装相关的命令,蓝色框内是移除服务相关的命令</p>\n<h1 id=\"五、测试\"><a href=\"#五、测试\" class=\"headerlink\" title=\"五、测试\"></a>五、测试</h1><p>运行命令确认MySQL能够使用</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mysql -uroot</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/win-dian-nao-an-zhuang-lv-se-ban-mysql8/2024-03-19-13-47-00-image.png\" alt=\"\"></p>\n<h1 id=\"六、修改root密码\"><a href=\"#六、修改root密码\" class=\"headerlink\" title=\"六、修改root密码\"></a>六、修改root密码</h1><p>由于前面的方式root用户没有密码需要添加个密码MySQL进入后执行下面的命令给root设置密码</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">use mysql\nALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED WITH mysql_native_password BY &#39;新密码&#39;;\nFLUSH PRIVILEGES;</code></pre>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"Git操作指南子模块、用户名修改和Subtree","slug":"gitcao-zuo-zhi-nan-zi-mo-kuai-yong-hu-ming-xiu-gai-he-subtree","date":"2024-03-13T08:22:06.000Z","updated":"2024-03-13T08:53:05.816Z","comments":true,"path":"/post/gitcao-zuo-zhi-nan-zi-mo-kuai-yong-hu-ming-xiu-gai-he-subtree/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>在软件开发中版本控制是一个至关重要的环节。Git 作为目前最流行的版本控制工具之一,提供了丰富的功能和灵活的操作方式。本文将介绍一些常用的 Git 操作,包括管理子模块、修改用户名、使用 Git Subtree 合并项目以及其他一些常见操作。</p>\n<h1 id=\"一、引用子模块\"><a href=\"#一、引用子模块\" class=\"headerlink\" title=\"一、引用子模块\"></a>一、引用子模块</h1><p><code>git submodule</code>是一个用于将其他两个 Git 仓库嵌入到一个主仓库中。这样做可以使主仓库包含其他两个仓库的内容,并能够管理它们的版本和更新。以下是将两个其他仓库添加为子模块到主仓库的基本步骤:</p>\n<h2 id=\"1、初始化主仓库\"><a href=\"#1、初始化主仓库\" class=\"headerlink\" title=\"1、初始化主仓库\"></a>1、初始化主仓库</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mkdir main_project\ncd main_project\ngit init</code></pre>\n<h2 id=\"2、添加子模块\"><a href=\"#2、添加子模块\" class=\"headerlink\" title=\"2、添加子模块\"></a>2、添加子模块</h2><p>使用 <code>git submodule add</code> 命令将其他仓库添加为子模块到主仓库中。</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git submodule add &lt;URL_of_repository1&gt; repository1_folder\ngit submodule add &lt;URL_of_repository2&gt; repository2_folder</code></pre>\n<h2 id=\"3、提交更改\"><a href=\"#3、提交更改\" class=\"headerlink\" title=\"3、提交更改\"></a>3、提交更改</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git commit -m &quot;Add submodules repository1 and repository2&quot;</code></pre>\n<p>现在,主仓库包含了两个子模块,它们的内容在 <code>repository1_folder</code> 和 <code>repository2_folder</code> 中。</p>\n<p>当你克隆主仓库时,子模块的内容并不会自动下载。你需要执行以下命令来初始化和更新子模块:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git submodule update --init --recursive</code></pre>\n<p>这会初始化并拉取子模块的内容。之后,你可以像管理普通的 Git 仓库一样来管理这些子模块,例如切换到不同的分支或提交更改。</p>\n<p>需要注意的是,子模块在主仓库中只是一个指向子仓库的引用,它不会把子仓库的内容直接嵌入到主仓库中。这意味着你可以独立地管理每个子仓库的版本和更新。</p>\n<p>在主仓库中,如果需要查看子模块的提交记录,可以使用下面的命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git log --recurse-submodules</code></pre>\n<h1 id=\"二、删除引用的子模块\"><a href=\"#二、删除引用的子模块\" class=\"headerlink\" title=\"二、删除引用的子模块\"></a>二、删除引用的子模块</h1><p>如果需要删除子模块,你需要执行以下步骤:</p>\n<h2 id=\"1、移除子模块的配置\"><a href=\"#1、移除子模块的配置\" class=\"headerlink\" title=\"1、移除子模块的配置\"></a>1、移除子模块的配置</h2><p>使用 <code>git submodule deinit</code> 命令来从 <code>.gitmodules</code> 文件中移除子模块的配置信息,并删除 <code>.git/modules/&lt;submodule_folder&gt;</code> 文件夹中的子模块内容。例如,假设子模块的文件夹名为 <code>submodule_folder</code></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git submodule deinit -f &lt;submodule_folder&gt;</code></pre>\n<h2 id=\"2、-删除子模块的文件夹\"><a href=\"#2、-删除子模块的文件夹\" class=\"headerlink\" title=\"2、 删除子模块的文件夹\"></a>2、 删除子模块的文件夹</h2><p>删除主项目中包含子模块内容的文件夹。在上面的例子中,删除名为 <code>&lt;submodule_folder&gt;</code> 的文件夹:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git rm -f &lt;submodule_folder&gt;</code></pre>\n<h2 id=\"3、提交更改-1\"><a href=\"#3、提交更改-1\" class=\"headerlink\" title=\"3、提交更改\"></a>3、提交更改</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git commit -m &quot;Remove submodule &lt;submodule_folder&gt;&quot;\ngit push</code></pre>\n<h1 id=\"三、修改用户名\"><a href=\"#三、修改用户名\" class=\"headerlink\" title=\"三、修改用户名\"></a>三、修改用户名</h1><p>要修改 Git 中的用户名,你需要执行以下步骤:</p>\n<h2 id=\"1、全局修改用户名\"><a href=\"#1、全局修改用户名\" class=\"headerlink\" title=\"1、全局修改用户名\"></a>1、全局修改用户名</h2><p>使用以下命令设置全局用户名:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git config --global user.name &quot;Your New Username&quot;</code></pre>\n<p>替换 <code>&quot;Your New Username&quot;</code> 为你想要设置的新用户名。</p>\n<h2 id=\"2、针对单个仓库修改用户名可选\"><a href=\"#2、针对单个仓库修改用户名可选\" class=\"headerlink\" title=\"2、针对单个仓库修改用户名可选\"></a>2、针对单个仓库修改用户名可选</h2><p>如果你只想在特定的仓库中修改用户名,而不是全局修改,可以在该仓库中执行以下命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git config user.name &quot;Your New Username&quot;</code></pre>\n<h2 id=\"3、验证修改是否成功\"><a href=\"#3、验证修改是否成功\" class=\"headerlink\" title=\"3、验证修改是否成功\"></a>3、验证修改是否成功</h2><p>你可以运行以下命令来验证修改是否成功:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git config user.name</code></pre>\n<p> 这会显示当前配置的用户名,确保它已经更新为你想要的新用户名。</p>\n<p>通过执行上述步骤,你就可以修改 Git 中的用户名了。</p>\n<h1 id=\"四、整合子模块\"><a href=\"#四、整合子模块\" class=\"headerlink\" title=\"四、整合子模块\"></a>四、整合子模块</h1><p>Git Subtree 是一个用于合并不同 Git 仓库的工具,它允许将一个仓库的部分历史合并到另一个仓库中,而且可以保留提交记录。</p>\n<p>以下是将子模块项目转移到主项目中并保存子模块项目的提交记录的基本步骤:</p>\n<h2 id=\"1、添加子模块内容到主项目中\"><a href=\"#1、添加子模块内容到主项目中\" class=\"headerlink\" title=\"1、添加子模块内容到主项目中\"></a>1、添加子模块内容到主项目中</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git subtree add --prefix&#x3D;&lt;submodule_folder&gt; &lt;submodule_repo_url&gt; &lt;submodule_branch&gt; --squash</code></pre>\n<p>这个命令将子模块的内容合并到主项目中的指定文件夹 <code>&lt;submodule_folder&gt;</code> 中。<code>--squash</code> 选项用于将子模块的历史压缩成一个新的提交。</p>\n<h2 id=\"2、提交更改到主项目\"><a href=\"#2、提交更改到主项目\" class=\"headerlink\" title=\"2、提交更改到主项目\"></a>2、提交更改到主项目</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git commit -m &quot;Merge submodule repository into main project&quot;</code></pre>\n<p>这个提交将包含所有合并的子模块内容。</p>\n<h2 id=\"3、在以后的更新中同步子模块内容可选\"><a href=\"#3、在以后的更新中同步子模块内容可选\" class=\"headerlink\" title=\"3、在以后的更新中同步子模块内容可选\"></a>3、在以后的更新中同步子模块内容可选</h2><p>如果子模块的内容在原始仓库中发生了变化,你可能想要将这些变化同步到主项目中。你可以使用以下命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git subtree pull --prefix&#x3D;&lt;submodule_folder&gt; &lt;submodule_repo_url&gt; &lt;submodule_branch&gt; --squash</code></pre>\n<p>这会将子模块的最新更改合并到主项目中。</p>\n<p>使用 <code>git subtree</code> 的主要优点是它可以保留子模块项目的提交历史,并将其合并到主项目的提交历史中。这样可以更清晰地追踪子模块项目的变化,并且可以保持主项目的整洁性。</p>\n<h1 id=\"五、其他常见操作\"><a href=\"#五、其他常见操作\" class=\"headerlink\" title=\"五、其他常见操作\"></a>五、其他常见操作</h1><p>除了上述操作之外,还有一些其他常见的 Git 操作:</p>\n<ul>\n<li>提交代码:使用 <code>git commit</code> 命令将修改提交到本地仓库。</li>\n<li>推送代码:使用 <code>git push</code> 命令将本地仓库中的修改推送到远程仓库。</li>\n<li>合并代码:使用 <code>git merge</code> 命令将不同分支的代码合并到当前分支。</li>\n<li>创建分支:使用 <code>git branch</code> 命令创建新的分支。</li>\n<li>拉取代码:使用 <code>git pull</code> 命令从远程仓库拉取最新的代码。</li>\n</ul>\n<h1 id=\"结语\"><a href=\"#结语\" class=\"headerlink\" title=\"结语\"></a>结语</h1><p>本文介绍了一些常见的 Git 操作,包括管理子模块、修改用户名、使用 Git Subtree 合并项目以及其他一些常用操作。通过熟练掌握这些操作,你将能够更加高效地使用 Git 进行版本控制,并且更好地管理你的项目代码。</p>\n","categories":[{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/categories/git/"}],"tags":[{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/tags/git/"}]},{"title":"docker-compose部署单机版nacos","slug":"docker-composebu-shu-dan-ji-ban-nacos","date":"2024-03-08T08:47:43.000Z","updated":"2024-03-08T08:53:09.144Z","comments":true,"path":"/post/docker-composebu-shu-dan-ji-ban-nacos/","link":"","excerpt":"","content":"<h1 id=\"nacos数据库建表语句\"><a href=\"#nacos数据库建表语句\" class=\"headerlink\" title=\"nacos数据库建表语句\"></a>nacos数据库建表语句</h1><pre class=\"line-numbers language-sql\" data-language=\"sql\"><code class=\"language-sql\">&#x2F;*\n * Copyright 1999-2018 Alibaba Group Holding Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http:&#x2F;&#x2F;www.apache.org&#x2F;licenses&#x2F;LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *&#x2F;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; config_info *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;config_info&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT &#39;id&#39;,\n &#96;data_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;data_id&#39;,\n &#96;group_id&#96; VARCHAR(255) DEFAULT NULL,\n &#96;content&#96; LONGTEXT NOT NULL COMMENT &#39;content&#39;,\n &#96;md5&#96; VARCHAR(32) DEFAULT NULL COMMENT &#39;md5&#39;,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;修改时间&#39;,\n &#96;src_user&#96; TEXT COMMENT &#39;source user&#39;,\n &#96;src_ip&#96; VARCHAR(50) DEFAULT NULL COMMENT &#39;source ip&#39;,\n &#96;app_name&#96; VARCHAR(128) DEFAULT NULL,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;租户字段&#39;,\n &#96;c_desc&#96; VARCHAR(256) DEFAULT NULL,\n &#96;c_use&#96; VARCHAR(64) DEFAULT NULL,\n &#96;effect&#96; VARCHAR(64) DEFAULT NULL,\n &#96;type&#96; VARCHAR(64) DEFAULT NULL,\n &#96;c_schema&#96; TEXT,\n &#96;encrypted_data_key&#96; TEXT NOT NULL COMMENT &#39;秘钥&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_configinfo_datagrouptenant&#96; (&#96;data_id&#96;,&#96;group_id&#96;,&#96;tenant_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;config_info&#39;;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; config_info_aggr *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;config_info_aggr&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT &#39;id&#39;,\n &#96;data_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;data_id&#39;,\n &#96;group_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;group_id&#39;,\n &#96;datum_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;datum_id&#39;,\n &#96;content&#96; LONGTEXT NOT NULL COMMENT &#39;内容&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL COMMENT &#39;修改时间&#39;,\n &#96;app_name&#96; VARCHAR(128) DEFAULT NULL,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;租户字段&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_configinfoaggr_datagrouptenantdatum&#96; (&#96;data_id&#96;,&#96;group_id&#96;,&#96;tenant_id&#96;,&#96;datum_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;增加租户字段&#39;;\n\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; config_info_beta *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;config_info_beta&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT &#39;id&#39;,\n &#96;data_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;data_id&#39;,\n &#96;group_id&#96; VARCHAR(128) NOT NULL COMMENT &#39;group_id&#39;,\n &#96;app_name&#96; VARCHAR(128) DEFAULT NULL COMMENT &#39;app_name&#39;,\n &#96;content&#96; LONGTEXT NOT NULL COMMENT &#39;content&#39;,\n &#96;beta_ips&#96; VARCHAR(1024) DEFAULT NULL COMMENT &#39;betaIps&#39;,\n &#96;md5&#96; VARCHAR(32) DEFAULT NULL COMMENT &#39;md5&#39;,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;修改时间&#39;,\n &#96;src_user&#96; TEXT COMMENT &#39;source user&#39;,\n &#96;src_ip&#96; VARCHAR(50) DEFAULT NULL COMMENT &#39;source ip&#39;,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;租户字段&#39;,\n &#96;encrypted_data_key&#96; TEXT NOT NULL COMMENT &#39;秘钥&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_configinfobeta_datagrouptenant&#96; (&#96;data_id&#96;,&#96;group_id&#96;,&#96;tenant_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;config_info_beta&#39;;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; config_info_tag *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;config_info_tag&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT &#39;id&#39;,\n &#96;data_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;data_id&#39;,\n &#96;group_id&#96; VARCHAR(128) NOT NULL COMMENT &#39;group_id&#39;,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;tenant_id&#39;,\n &#96;tag_id&#96; VARCHAR(128) NOT NULL COMMENT &#39;tag_id&#39;,\n &#96;app_name&#96; VARCHAR(128) DEFAULT NULL COMMENT &#39;app_name&#39;,\n &#96;content&#96; LONGTEXT NOT NULL COMMENT &#39;content&#39;,\n &#96;md5&#96; VARCHAR(32) DEFAULT NULL COMMENT &#39;md5&#39;,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;修改时间&#39;,\n &#96;src_user&#96; TEXT COMMENT &#39;source user&#39;,\n &#96;src_ip&#96; VARCHAR(50) DEFAULT NULL COMMENT &#39;source ip&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_configinfotag_datagrouptenanttag&#96; (&#96;data_id&#96;,&#96;group_id&#96;,&#96;tenant_id&#96;,&#96;tag_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;config_info_tag&#39;;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; config_tags_relation *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;config_tags_relation&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL COMMENT &#39;id&#39;,\n &#96;tag_name&#96; VARCHAR(128) NOT NULL COMMENT &#39;tag_name&#39;,\n &#96;tag_type&#96; VARCHAR(64) DEFAULT NULL COMMENT &#39;tag_type&#39;,\n &#96;data_id&#96; VARCHAR(255) NOT NULL COMMENT &#39;data_id&#39;,\n &#96;group_id&#96; VARCHAR(128) NOT NULL COMMENT &#39;group_id&#39;,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;tenant_id&#39;,\n &#96;nid&#96; BIGINT(20) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (&#96;nid&#96;),\n UNIQUE KEY &#96;uk_configtagrelation_configidtag&#96; (&#96;id&#96;,&#96;tag_name&#96;,&#96;tag_type&#96;),\n KEY &#96;idx_tenant_id&#96; (&#96;tenant_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;config_tag_relation&#39;;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; group_capacity *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;group_capacity&#96; (\n &#96;id&#96; BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT &#39;主键ID&#39;,\n &#96;group_id&#96; VARCHAR(128) NOT NULL DEFAULT &#39;&#39; COMMENT &#39;Group ID空字符表示整个集群&#39;,\n &#96;quota&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;配额0表示使用默认值&#39;,\n &#96;usage&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;使用量&#39;,\n &#96;max_size&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;单个配置大小上限单位为字节0表示使用默认值&#39;,\n &#96;max_aggr_count&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;聚合子配置最大个数0表示使用默认值&#39;,\n &#96;max_aggr_size&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;单个聚合数据的子配置大小上限单位为字节0表示使用默认值&#39;,\n &#96;max_history_count&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;最大变更历史数量&#39;,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;修改时间&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_group_id&#96; (&#96;group_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;集群、各Group容量信息表&#39;;\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; his_config_info *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;his_config_info&#96; (\n &#96;id&#96; BIGINT(64) UNSIGNED NOT NULL,\n &#96;nid&#96; BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n &#96;data_id&#96; VARCHAR(255) NOT NULL,\n &#96;group_id&#96; VARCHAR(128) NOT NULL,\n &#96;app_name&#96; VARCHAR(128) DEFAULT NULL COMMENT &#39;app_name&#39;,\n &#96;content&#96; LONGTEXT NOT NULL,\n &#96;md5&#96; VARCHAR(32) DEFAULT NULL,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n &#96;src_user&#96; TEXT,\n &#96;src_ip&#96; VARCHAR(50) DEFAULT NULL,\n &#96;op_type&#96; CHAR(10) DEFAULT NULL,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;租户字段&#39;,\n &#96;encrypted_data_key&#96; TEXT NOT NULL COMMENT &#39;秘钥&#39;,\n PRIMARY KEY (&#96;nid&#96;),\n KEY &#96;idx_gmt_create&#96; (&#96;gmt_create&#96;),\n KEY &#96;idx_gmt_modified&#96; (&#96;gmt_modified&#96;),\n KEY &#96;idx_did&#96; (&#96;data_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;多租户改造&#39;;\n\n\n&#x2F;******************************************&#x2F;\n&#x2F;* 数据库全名 &#x3D; nacos_config *&#x2F;\n&#x2F;* 表名称 &#x3D; tenant_capacity *&#x2F;\n&#x2F;******************************************&#x2F;\nCREATE TABLE &#96;tenant_capacity&#96; (\n &#96;id&#96; BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT &#39;主键ID&#39;,\n &#96;tenant_id&#96; VARCHAR(128) NOT NULL DEFAULT &#39;&#39; COMMENT &#39;Tenant ID&#39;,\n &#96;quota&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;配额0表示使用默认值&#39;,\n &#96;usage&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;使用量&#39;,\n &#96;max_size&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;单个配置大小上限单位为字节0表示使用默认值&#39;,\n &#96;max_aggr_count&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;聚合子配置最大个数&#39;,\n &#96;max_aggr_size&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;单个聚合数据的子配置大小上限单位为字节0表示使用默认值&#39;,\n &#96;max_history_count&#96; INT(10) UNSIGNED NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;最大变更历史数量&#39;,\n &#96;gmt_create&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT &#39;修改时间&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_tenant_id&#96; (&#96;tenant_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;租户容量信息表&#39;;\n\n\nCREATE TABLE &#96;tenant_info&#96; (\n &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT &#39;id&#39;,\n &#96;kp&#96; VARCHAR(128) NOT NULL COMMENT &#39;kp&#39;,\n &#96;tenant_id&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;tenant_id&#39;,\n &#96;tenant_name&#96; VARCHAR(128) DEFAULT &#39;&#39; COMMENT &#39;tenant_name&#39;,\n &#96;tenant_desc&#96; VARCHAR(256) DEFAULT NULL COMMENT &#39;tenant_desc&#39;,\n &#96;create_source&#96; VARCHAR(32) DEFAULT NULL COMMENT &#39;create_source&#39;,\n &#96;gmt_create&#96; BIGINT(20) NOT NULL COMMENT &#39;创建时间&#39;,\n &#96;gmt_modified&#96; BIGINT(20) NOT NULL COMMENT &#39;修改时间&#39;,\n PRIMARY KEY (&#96;id&#96;),\n UNIQUE KEY &#96;uk_tenant_info_kptenantid&#96; (&#96;kp&#96;,&#96;tenant_id&#96;),\n KEY &#96;idx_tenant_id&#96; (&#96;tenant_id&#96;)\n) ENGINE&#x3D;INNODB DEFAULT CHARSET&#x3D;utf8 COLLATE&#x3D;utf8_bin COMMENT&#x3D;&#39;tenant_info&#39;;\n\nCREATE TABLE &#96;users&#96; (\n &#96;username&#96; VARCHAR(50) NOT NULL PRIMARY KEY,\n &#96;password&#96; VARCHAR(500) NOT NULL,\n &#96;enabled&#96; BOOLEAN NOT NULL\n);\n\nCREATE TABLE &#96;roles&#96; (\n &#96;username&#96; VARCHAR(50) NOT NULL,\n &#96;role&#96; VARCHAR(50) NOT NULL,\n UNIQUE INDEX &#96;idx_user_role&#96; (&#96;username&#96; ASC, &#96;role&#96; ASC) USING BTREE\n);\n\nCREATE TABLE &#96;permissions&#96; (\n &#96;role&#96; VARCHAR(50) NOT NULL,\n &#96;resource&#96; VARCHAR(255) NOT NULL,\n &#96;action&#96; VARCHAR(8) NOT NULL,\n UNIQUE INDEX &#96;uk_role_permission&#96; (&#96;role&#96;,&#96;resource&#96;,&#96;action&#96;) USING BTREE\n);\n\nINSERT INTO users (username, PASSWORD, enabled) VALUES (&#39;nacos&#39;, &#39;$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu&#39;, TRUE);\n\nINSERT INTO roles (username, role) VALUES (&#39;nacos&#39;, &#39;ROLE_ADMIN&#39;);</code></pre>\n<h1 id=\"docker-compose-yaml内容如下\"><a href=\"#docker-compose-yaml内容如下\" class=\"headerlink\" title=\"docker-compose.yaml内容如下\"></a>docker-compose.yaml内容如下</h1><pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">version: &quot;3.0&quot;\nservices:\n nacos:\n image: nacos&#x2F;nacos-server:2.0.3\n container_name: nacos\n volumes:\n - .&#x2F;logs&#x2F;:&#x2F;home&#x2F;nacos&#x2F;logs\n ports:\n - &quot;8848:8848&quot;\n - &quot;9848:9848&quot;\n environment:\n MODE: standalone\n PREFER_HOST_MODE: hostname\n SPRING_DATASOURCE_PLATFORM: mysql\n MYSQL_SERVICE_HOST: 数据库IP地址127.0.0.1\n MYSQL_SERVICE_DB_NAME: 数据库名称\n MYSQL_SERVICE_PORT: 数据库端口号\n MYSQL_SERVICE_USER: 数据库连接用户名\n MYSQL_SERVICE_PASSWORD: 数据库连接密码\n restart: always</code></pre>\n<h1 id=\"web登录页\"><a href=\"#web登录页\" class=\"headerlink\" title=\"web登录页\"></a>web登录页</h1><p><a href=\"http://IP:8848/nacos\">http://IP:8848/nacos</a><br>用户名和密码都是nacos</p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"Map类方法整理jdk8","slug":"maplei-xiang-jie-jdk8","date":"2024-02-19T03:09:55.000Z","updated":"2024-02-19T06:04:13.167Z","comments":true,"path":"/post/maplei-xiang-jie-jdk8/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>今天在查看力扣周赛385题解时发现了几个我平时没注意的map方法看了jdk相关的源码感觉很巧妙可以帮我节省代码于是乎顺带着整个Map类的方法都过了一遍下面是我看后整理的内容。</p>\n<p>Map类中包括了以下方法</p>\n<ul>\n<li><p><a href=\"#clear\">clear()</a></p>\n</li>\n<li><p><a href=\"#computekbifunctionkvv\">compute(K,BiFunction<K,V,V>)</a></p>\n</li>\n<li><p><a href=\"#computeifabsentkfunctionkv\">computeIfAbsent(K,Function<K,V>)</a></p>\n</li>\n<li><p><a href=\"#computeifpresentkbifunctionkvv\">computeIfPresent(K,BiFunction<K,V,V>)</a></p>\n</li>\n<li><p><a href=\"#containskeyobject\">containsKey(Object)</a></p>\n</li>\n<li><p><a href=\"#containsvalueobject\">containsValue(Object)</a></p>\n</li>\n<li><p><a href=\"#entryset\">entrySet()</a></p>\n</li>\n<li><p><a href=\"#equalsobject\">equals(Object)</a></p>\n</li>\n<li><p><a href=\"#foreachbiconsumerkv\">forEach(BiConsumer<K,V>)</a></p>\n</li>\n<li><p><a href=\"#getobject\">get(Object)</a></p>\n</li>\n<li><p><a href=\"#getordefaultobject\">getOrDefault(Object, V)</a></p>\n</li>\n<li><p><a href=\"#hashcode\">hashCode()</a></p>\n</li>\n<li><p><a href=\"#isempty\">isEmpty()</a></p>\n</li>\n<li><p><a href=\"#keyset\">keySet()</a></p>\n</li>\n<li><p><a href=\"#mergekvbifunctionvvv\">merge(K,V,BiFunction<V,V,V>)</a></p>\n</li>\n<li><p><a href=\"#putkv\">put(K,V)</a></p>\n</li>\n<li><p><a href=\"#putallmapkv\">putAll(Map<K,V>)</a></p>\n</li>\n<li><p><a href=\"#putifabsentkv\">putIfAbsent(K,V)</a></p>\n</li>\n<li><p><a href=\"#removeobject\">remove(Object)</a></p>\n</li>\n<li><p><a href=\"#removeobjectobject\">remove(Object,Object)</a></p>\n</li>\n<li><p><a href=\"#replacekvv\">replace(K,V,V)</a></p>\n</li>\n<li><p><a href=\"#replacekv\">replace(K,V)</a></p>\n</li>\n<li><p><a href=\"#replaceallbifunctionkvv\">replaceAll(BiFunction<K,V,V>)</a></p>\n</li>\n<li><p><a href=\"#size\">size()</a></p>\n</li>\n<li><p><a href=\"#values\">values()</a></p>\n</li>\n</ul>\n<h1 id=\"方法详解\"><a href=\"#方法详解\" class=\"headerlink\" title=\"方法详解\"></a>方法详解</h1><h2 id=\"clear\"><a href=\"#clear\" class=\"headerlink\" title=\"clear()\"></a><a id=\"clear\">clear()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Removes all of the mappings from this map (optional operation).\n * The map will be empty after this call returns.\n *\n * @throws UnsupportedOperationException if the &lt;tt&gt;clear&lt;&#x2F;tt&gt; operation\n * is not supported by this map\n *&#x2F;\nvoid clear();</code></pre>\n<p>功能移除Map中所有的键值对。</p>\n<h2 id=\"compute-K-BiFunction\"><a href=\"#compute-K-BiFunction\" class=\"headerlink\" title=\"compute(K,BiFunction)\"></a><a id=\"computekbifunctionkvv\">compute(K,BiFunction<K,V,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Attempts to compute a mapping for the specified key and its current\n * mapped value (or &#123;@code null&#125; if there is no current mapping). For\n * example, to either create or append a &#123;@code String&#125; msg to a value\n * mapping:\n *\n * &lt;pre&gt; &#123;@code\n * map.compute(key, (k, v) -&gt; (v &#x3D;&#x3D; null) ? msg : v.concat(msg))&#125;&lt;&#x2F;pre&gt;\n * (Method &#123;@link #merge merge()&#125; is often simpler to use for such purposes.)\n *\n * &lt;p&gt;If the function returns &#123;@code null&#125;, the mapping is removed (or\n * remains absent if initially absent). If the function itself throws an\n * (unchecked) exception, the exception is rethrown, and the current mapping\n * is left unchanged.\n *\n * @implSpec\n * The default implementation is equivalent to performing the following\n * steps for this &#123;@code map&#125;, then returning the current value or\n * &#123;@code null&#125; if absent:\n *\n * &lt;pre&gt; &#123;@code\n * V oldValue &#x3D; map.get(key);\n * V newValue &#x3D; remappingFunction.apply(key, oldValue);\n * if (oldValue !&#x3D; null ) &#123;\n * if (newValue !&#x3D; null)\n * map.put(key, newValue);\n * else\n * map.remove(key);\n * &#125; else &#123;\n * if (newValue !&#x3D; null)\n * map.put(key, newValue);\n * else\n * return null;\n * &#125;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties. In particular, all implementations of\n * subinterface &#123;@link java.util.concurrent.ConcurrentMap&#125; must document\n * whether the function is applied once atomically only if the value is not\n * present.\n *\n * @param key key with which the specified value is to be associated\n * @param remappingFunction the function to compute a value\n * @return the new value associated with the specified key, or null if none\n * @throws NullPointerException if the specified key is null and\n * this map does not support null keys, or the\n * remappingFunction is null\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;\n * @since 1.8\n *&#x2F;\ndefault V compute(K key,\n BiFunction&lt;? super K, ? super V, ? extends V&gt; remappingFunction) &#123;\n Objects.requireNonNull(remappingFunction);\n V oldValue &#x3D; get(key);\n V newValue &#x3D; remappingFunction.apply(key, oldValue);\n if (newValue &#x3D;&#x3D; null) &#123;\n &#x2F;&#x2F; delete mapping\n if (oldValue !&#x3D; null || containsKey(key)) &#123;\n &#x2F;&#x2F; something to remove\n remove(key);\n return null;\n &#125; else &#123;\n &#x2F;&#x2F; nothing to do. Leave things as they were.\n return null;\n &#125;\n &#125; else &#123;\n &#x2F;&#x2F; add or replace old mapping\n put(key, newValue);\n return newValue;\n &#125;\n&#125;</code></pre>\n<p>功能:</p>\n<ul>\n<li>根据指定的键和重新映射函数计算新值并将新值存储到Map中。</li>\n<li>如果键存在则根据提供的函数计算新值并更新到Map中然后返回新值如果键不存在则不执行任何操作。</li>\n</ul>\n<h2 id=\"computeIfAbsent-K-Function\"><a href=\"#computeIfAbsent-K-Function\" class=\"headerlink\" title=\"computeIfAbsent(K,Function)\"></a><a id=\"computeifabsentkfunctionkv\">computeIfAbsent(K,Function<K,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * If the specified key is not already associated with a value (or is mapped\n * to &#123;@code null&#125;), attempts to compute its value using the given mapping\n * function and enters it into this map unless &#123;@code null&#125;.\n *\n * &lt;p&gt;If the function returns &#123;@code null&#125; no mapping is recorded. If\n * the function itself throws an (unchecked) exception, the\n * exception is rethrown, and no mapping is recorded. The most\n * common usage is to construct a new object serving as an initial\n * mapped value or memoized result, as in:\n *\n * &lt;pre&gt; &#123;@code\n * map.computeIfAbsent(key, k -&gt; new Value(f(k)));\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;Or to implement a multi-value map, &#123;@code Map&lt;K,Collection&lt;V&gt;&gt;&#125;,\n * supporting multiple values per key:\n *\n * &lt;pre&gt; &#123;@code\n * map.computeIfAbsent(key, k -&gt; new HashSet&lt;V&gt;()).add(v);\n * &#125;&lt;&#x2F;pre&gt;\n *\n *\n * @implSpec\n * The default implementation is equivalent to the following steps for this\n * &#123;@code map&#125;, then returning the current value or &#123;@code null&#125; if now\n * absent:\n *\n * &lt;pre&gt; &#123;@code\n * if (map.get(key) &#x3D;&#x3D; null) &#123;\n * V newValue &#x3D; mappingFunction.apply(key);\n * if (newValue !&#x3D; null)\n * map.put(key, newValue);\n * &#125;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties. In particular, all implementations of\n * subinterface &#123;@link java.util.concurrent.ConcurrentMap&#125; must document\n * whether the function is applied once atomically only if the value is not\n * present.\n *\n * @param key key with which the specified value is to be associated\n * @param mappingFunction the function to compute a value\n * @return the current (existing or computed) value associated with\n * the specified key, or null if the computed value is null\n * @throws NullPointerException if the specified key is null and\n * this map does not support null keys, or the mappingFunction\n * is null\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @since 1.8\n *&#x2F;\ndefault V computeIfAbsent(K key,\n Function&lt;? super K, ? extends V&gt; mappingFunction) &#123;\n Objects.requireNonNull(mappingFunction);\n V v;\n if ((v &#x3D; get(key)) &#x3D;&#x3D; null) &#123;\n V newValue;\n if ((newValue &#x3D; mappingFunction.apply(key)) !&#x3D; null) &#123;\n put(key, newValue);\n return newValue;\n &#125;\n &#125;\n return v;\n&#125;</code></pre>\n<p>功能:</p>\n<ul>\n<li>如果指定键不存在则根据指定的映射函数计算并将结果存储到Map中如果键已经存在则不执行任何操作。</li>\n<li>这个方法允许根据键的不存在来动态计算值并将计算结果存储到Map中。</li>\n</ul>\n<h2 id=\"computeIfPresent-K-BiFunction\"><a href=\"#computeIfPresent-K-BiFunction\" class=\"headerlink\" title=\"computeIfPresent(K,BiFunction)\"></a><a id=\"computeifpresentkbifunctionkvv\">computeIfPresent(K,BiFunction<K,V,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * If the value for the specified key is present and non-null, attempts to\n * compute a new mapping given the key and its current mapped value.\n *\n * &lt;p&gt;If the function returns &#123;@code null&#125;, the mapping is removed. If the\n * function itself throws an (unchecked) exception, the exception is\n * rethrown, and the current mapping is left unchanged.\n*\n * @implSpec\n * The default implementation is equivalent to performing the following\n * steps for this &#123;@code map&#125;, then returning the current value or\n * &#123;@code null&#125; if now absent:\n *\n * &lt;pre&gt; &#123;@code\n * if (map.get(key) !&#x3D; null) &#123;\n * V oldValue &#x3D; map.get(key);\n * V newValue &#x3D; remappingFunction.apply(key, oldValue);\n * if (newValue !&#x3D; null)\n * map.put(key, newValue);\n * else\n * map.remove(key);\n * &#125;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties. In particular, all implementations of\n * subinterface &#123;@link java.util.concurrent.ConcurrentMap&#125; must document\n * whether the function is applied once atomically only if the value is not\n * present.\n *\n * @param key key with which the specified value is to be associated\n * @param remappingFunction the function to compute a value\n * @return the new value associated with the specified key, or null if none\n * @throws NullPointerException if the specified key is null and\n * this map does not support null keys, or the\n * remappingFunction is null\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @since 1.8\n *&#x2F;\ndefault V computeIfPresent(K key,\n BiFunction&lt;? super K, ? super V, ? extends V&gt; remappingFunction) &#123;\n Objects.requireNonNull(remappingFunction);\n V oldValue;\n if ((oldValue &#x3D; get(key)) !&#x3D; null) &#123;\n V newValue &#x3D; remappingFunction.apply(key, oldValue);\n if (newValue !&#x3D; null) &#123;\n put(key, newValue);\n return newValue;\n &#125; else &#123;\n remove(key);\n return null;\n &#125;\n &#125; else &#123;\n return null;\n &#125;\n&#125;</code></pre>\n<p>功能:</p>\n<ul>\n<li>如果指定键存在则根据提供的重新映射函数计算新值并将新值存储到Map中如果键不存在则不执行任何操作。</li>\n<li>这个方法允许在键存在时根据原始值计算新值并更新到Map中。</li>\n</ul>\n<h2 id=\"containsKey-Object\"><a href=\"#containsKey-Object\" class=\"headerlink\" title=\"containsKey(Object)\"></a><a id=\"containskeyobject\">containsKey(Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map contains a mapping for the specified\n * key. More formally, returns &lt;tt&gt;true&lt;&#x2F;tt&gt; if and only if\n * this map contains a mapping for a key &lt;tt&gt;k&lt;&#x2F;tt&gt; such that\n * &lt;tt&gt;(key&#x3D;&#x3D;null ? k&#x3D;&#x3D;null : key.equals(k))&lt;&#x2F;tt&gt;. (There can be\n * at most one such mapping.)\n *\n * @param key key whose presence in this map is to be tested\n * @return &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map contains a mapping for the specified\n * key\n * @throws ClassCastException if the key is of an inappropriate type for\n * this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key is null and this map\n * does not permit null keys\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n *&#x2F;\nboolean containsKey(Object key);</code></pre>\n<p>功能判断Map中是否包含指定的键。</p>\n<h2 id=\"containsValue-Object\"><a href=\"#containsValue-Object\" class=\"headerlink\" title=\"containsValue(Object)\"></a><a id=\"containsvalueobject\">containsValue(Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map maps one or more keys to the\n * specified value. More formally, returns &lt;tt&gt;true&lt;&#x2F;tt&gt; if and only if\n * this map contains at least one mapping to a value &lt;tt&gt;v&lt;&#x2F;tt&gt; such that\n * &lt;tt&gt;(value&#x3D;&#x3D;null ? v&#x3D;&#x3D;null : value.equals(v))&lt;&#x2F;tt&gt;. This operation\n * will probably require time linear in the map size for most\n * implementations of the &lt;tt&gt;Map&lt;&#x2F;tt&gt; interface.\n *\n * @param value value whose presence in this map is to be tested\n * @return &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map maps one or more keys to the\n * specified value\n * @throws ClassCastException if the value is of an inappropriate type for\n * this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified value is null and this\n * map does not permit null values\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n *&#x2F;\nboolean containsValue(Object value);</code></pre>\n<p>功能判断Map中是否包含指定的值。</p>\n<h2 id=\"entrySet\"><a href=\"#entrySet\" class=\"headerlink\" title=\"entrySet()\"></a><a id=\"entrySet\">entrySet()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns a &#123;@link Set&#125; view of the mappings contained in this map.\n * The set is backed by the map, so changes to the map are\n * reflected in the set, and vice-versa. If the map is modified\n * while an iteration over the set is in progress (except through\n * the iterator&#39;s own &lt;tt&gt;remove&lt;&#x2F;tt&gt; operation, or through the\n * &lt;tt&gt;setValue&lt;&#x2F;tt&gt; operation on a map entry returned by the\n * iterator) the results of the iteration are undefined. The set\n * supports element removal, which removes the corresponding\n * mapping from the map, via the &lt;tt&gt;Iterator.remove&lt;&#x2F;tt&gt;,\n * &lt;tt&gt;Set.remove&lt;&#x2F;tt&gt;, &lt;tt&gt;removeAll&lt;&#x2F;tt&gt;, &lt;tt&gt;retainAll&lt;&#x2F;tt&gt; and\n * &lt;tt&gt;clear&lt;&#x2F;tt&gt; operations. It does not support the\n * &lt;tt&gt;add&lt;&#x2F;tt&gt; or &lt;tt&gt;addAll&lt;&#x2F;tt&gt; operations.\n *\n * @return a set view of the mappings contained in this map\n *&#x2F;\nSet&lt;Map.Entry&lt;K, V&gt;&gt; entrySet();</code></pre>\n<p>功能返回一个包含Map中所有键值对的Set集合。</p>\n<h2 id=\"equals-Object\"><a href=\"#equals-Object\" class=\"headerlink\" title=\"equals(Object)\"></a><a id=\"equalsobject\">equals(Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Compares the specified object with this map for equality. Returns\n * &lt;tt&gt;true&lt;&#x2F;tt&gt; if the given object is also a map and the two maps\n * represent the same mappings. More formally, two maps &lt;tt&gt;m1&lt;&#x2F;tt&gt; and\n * &lt;tt&gt;m2&lt;&#x2F;tt&gt; represent the same mappings if\n * &lt;tt&gt;m1.entrySet().equals(m2.entrySet())&lt;&#x2F;tt&gt;. This ensures that the\n * &lt;tt&gt;equals&lt;&#x2F;tt&gt; method works properly across different implementations\n * of the &lt;tt&gt;Map&lt;&#x2F;tt&gt; interface.\n *\n * @param o object to be compared for equality with this map\n * @return &lt;tt&gt;true&lt;&#x2F;tt&gt; if the specified object is equal to this map\n *&#x2F;\nboolean equals(Object o);</code></pre>\n<p>功能:比较两个 <code>Map</code> 对象是否相等。两个 <code>Map</code> 相等的条件是:</p>\n<ol>\n<li><p>两个 <code>Map</code> 对象具有相同的键值对数量。</p>\n</li>\n<li><p>对于每个键,两个 <code>Map</code> 对象的键值必须相等。</p>\n</li>\n</ol>\n<h2 id=\"forEach-BiConsumer\"><a href=\"#forEach-BiConsumer\" class=\"headerlink\" title=\"forEach(BiConsumer)\"></a><a id=\"foreachbiconsumerkv\">forEach(BiConsumer<K,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Performs the given action for each entry in this map until all entries\n * have been processed or the action throws an exception. Unless\n * otherwise specified by the implementing class, actions are performed in\n * the order of entry set iteration (if an iteration order is specified.)\n * Exceptions thrown by the action are relayed to the caller.\n *\n * @implSpec\n * The default implementation is equivalent to, for this &#123;@code map&#125;:\n * &lt;pre&gt; &#123;@code\n * for (Map.Entry&lt;K, V&gt; entry : map.entrySet())\n * action.accept(entry.getKey(), entry.getValue());\n * &#125;&lt;&#x2F;pre&gt;\n *\n * The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param action The action to be performed for each entry\n * @throws NullPointerException if the specified action is null\n * @throws ConcurrentModificationException if an entry is found to be\n * removed during iteration\n * @since 1.8\n *&#x2F;\ndefault void forEach(BiConsumer&lt;? super K, ? super V&gt; action) &#123;\n Objects.requireNonNull(action);\n for (Map.Entry&lt;K, V&gt; entry : entrySet()) &#123;\n K k;\n V v;\n try &#123;\n k &#x3D; entry.getKey();\n v &#x3D; entry.getValue();\n &#125; catch(IllegalStateException ise) &#123;\n &#x2F;&#x2F; this usually means the entry is no longer in the map.\n throw new ConcurrentModificationException(ise);\n &#125;\n action.accept(k, v);\n &#125;\n&#125;</code></pre>\n<p>功能对Map中的每个键值对执行指定的操作。</p>\n<h2 id=\"get-Object\"><a href=\"#get-Object\" class=\"headerlink\" title=\"get(Object)\"></a><a id=\"getobject\">get(Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns the value to which the specified key is mapped,\n * or &#123;@code null&#125; if this map contains no mapping for the key.\n *\n * &lt;p&gt;More formally, if this map contains a mapping from a key\n * &#123;@code k&#125; to a value &#123;@code v&#125; such that &#123;@code (key&#x3D;&#x3D;null ? k&#x3D;&#x3D;null :\n * key.equals(k))&#125;, then this method returns &#123;@code v&#125;; otherwise\n * it returns &#123;@code null&#125;. (There can be at most one such mapping.)\n *\n * &lt;p&gt;If this map permits null values, then a return value of\n * &#123;@code null&#125; does not &lt;i&gt;necessarily&lt;&#x2F;i&gt; indicate that the map\n * contains no mapping for the key; it&#39;s also possible that the map\n * explicitly maps the key to &#123;@code null&#125;. The &#123;@link #containsKey\n * containsKey&#125; operation may be used to distinguish these two cases.\n *\n * @param key the key whose associated value is to be returned\n * @return the value to which the specified key is mapped, or\n * &#123;@code null&#125; if this map contains no mapping for the key\n * @throws ClassCastException if the key is of an inappropriate type for\n * this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key is null and this map\n * does not permit null keys\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n *&#x2F;\nV get(Object key);</code></pre>\n<p>功能获取指定键对应的值如果键不存在则返回null。</p>\n<h2 id=\"getOrDefault-Object-V\"><a href=\"#getOrDefault-Object-V\" class=\"headerlink\" title=\"getOrDefault(Object, V)\"></a><a id=\"getordefaultobject\">getOrDefault(Object, V)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns the value to which the specified key is mapped, or\n * &#123;@code defaultValue&#125; if this map contains no mapping for the key.\n *\n * @implSpec\n * The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param key the key whose associated value is to be returned\n * @param defaultValue the default mapping of the key\n * @return the value to which the specified key is mapped, or\n * &#123;@code defaultValue&#125; if this map contains no mapping for the key\n * @throws ClassCastException if the key is of an inappropriate type for\n * this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key is null and this map\n * does not permit null keys\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @since 1.8\n *&#x2F;\ndefault V getOrDefault(Object key, V defaultValue) &#123;\n V v;\n return (((v &#x3D; get(key)) !&#x3D; null) || containsKey(key))\n ? v\n : defaultValue;\n&#125;</code></pre>\n<p>功能:获取指定键对应的值,如果键不存在,则返回指定的默认值。</p>\n<h2 id=\"hashCode\"><a href=\"#hashCode\" class=\"headerlink\" title=\"hashCode()\"></a><a id=\"hashcode\">hashCode()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns the hash code value for this map. The hash code of a map is\n * defined to be the sum of the hash codes of each entry in the map&#39;s\n * &lt;tt&gt;entrySet()&lt;&#x2F;tt&gt; view. This ensures that &lt;tt&gt;m1.equals(m2)&lt;&#x2F;tt&gt;\n * implies that &lt;tt&gt;m1.hashCode()&#x3D;&#x3D;m2.hashCode()&lt;&#x2F;tt&gt; for any two maps\n * &lt;tt&gt;m1&lt;&#x2F;tt&gt; and &lt;tt&gt;m2&lt;&#x2F;tt&gt;, as required by the general contract of\n * &#123;@link Object#hashCode&#125;.\n *\n * @return the hash code value for this map\n * @see Map.Entry#hashCode()\n * @see Object#equals(Object)\n * @see #equals(Object)\n *&#x2F;\nint hashCode();</code></pre>\n<p>功能:返回 <code>Map</code> 对象的哈希码。</p>\n<h2 id=\"isEmpty\"><a href=\"#isEmpty\" class=\"headerlink\" title=\"isEmpty()\"></a><a id=\"isempty\">isEmpty()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map contains no key-value mappings.\n *\n * @return &lt;tt&gt;true&lt;&#x2F;tt&gt; if this map contains no key-value mappings\n *&#x2F;\nboolean isEmpty();</code></pre>\n<p>功能判断Map是否为空</p>\n<h2 id=\"keySet\"><a href=\"#keySet\" class=\"headerlink\" title=\"keySet()\"></a><a id=\"keyset\">keySet()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns a &#123;@link Set&#125; view of the keys contained in this map.\n * The set is backed by the map, so changes to the map are\n * reflected in the set, and vice-versa. If the map is modified\n * while an iteration over the set is in progress (except through\n * the iterator&#39;s own &lt;tt&gt;remove&lt;&#x2F;tt&gt; operation), the results of\n * the iteration are undefined. The set supports element removal,\n * which removes the corresponding mapping from the map, via the\n * &lt;tt&gt;Iterator.remove&lt;&#x2F;tt&gt;, &lt;tt&gt;Set.remove&lt;&#x2F;tt&gt;,\n * &lt;tt&gt;removeAll&lt;&#x2F;tt&gt;, &lt;tt&gt;retainAll&lt;&#x2F;tt&gt;, and &lt;tt&gt;clear&lt;&#x2F;tt&gt;\n * operations. It does not support the &lt;tt&gt;add&lt;&#x2F;tt&gt; or &lt;tt&gt;addAll&lt;&#x2F;tt&gt;\n * operations.\n *\n * @return a set view of the keys contained in this map\n *&#x2F;\nSet&lt;K&gt; keySet();</code></pre>\n<p>功能:返回 <code>Map</code> 中所有键的 <code>Set</code> 集合</p>\n<h2 id=\"merge-K-V-BiFunction\"><a href=\"#merge-K-V-BiFunction\" class=\"headerlink\" title=\"merge(K,V,BiFunction)\"></a><a id=\"mergekvbifunctionvvv\">merge(K,V,BiFunction<V,V,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * If the specified key is not already associated with a value or is\n * associated with null, associates it with the given non-null value.\n * Otherwise, replaces the associated value with the results of the given\n * remapping function, or removes if the result is &#123;@code null&#125;. This\n * method may be of use when combining multiple mapped values for a key.\n * For example, to either create or append a &#123;@code String msg&#125; to a\n * value mapping:\n *\n * &lt;pre&gt; &#123;@code\n * map.merge(key, msg, String::concat)\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;If the function returns &#123;@code null&#125; the mapping is removed. If the\n * function itself throws an (unchecked) exception, the exception is\n * rethrown, and the current mapping is left unchanged.\n *\n * @implSpec\n * The default implementation is equivalent to performing the following\n * steps for this &#123;@code map&#125;, then returning the current value or\n * &#123;@code null&#125; if absent:\n *\n * &lt;pre&gt; &#123;@code\n * V oldValue &#x3D; map.get(key);\n * V newValue &#x3D; (oldValue &#x3D;&#x3D; null) ? value :\n * remappingFunction.apply(oldValue, value);\n * if (newValue &#x3D;&#x3D; null)\n * map.remove(key);\n * else\n * map.put(key, newValue);\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties. In particular, all implementations of\n * subinterface &#123;@link java.util.concurrent.ConcurrentMap&#125; must document\n * whether the function is applied once atomically only if the value is not\n * present.\n *\n * @param key key with which the resulting value is to be associated\n * @param value the non-null value to be merged with the existing value\n * associated with the key or, if no existing value or a null value\n * is associated with the key, to be associated with the key\n * @param remappingFunction the function to recompute a value if present\n * @return the new value associated with the specified key, or null if no\n * value is associated with the key\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key is null and this map\n * does not support null keys or the value or remappingFunction is\n * null\n * @since 1.8\n *&#x2F;\ndefault V merge(K key, V value,\n BiFunction&lt;? super V, ? super V, ? extends V&gt; remappingFunction) &#123;\n Objects.requireNonNull(remappingFunction);\n Objects.requireNonNull(value);\n V oldValue &#x3D; get(key);\n V newValue &#x3D; (oldValue &#x3D;&#x3D; null) ? value :\n remappingFunction.apply(oldValue, value);\n if(newValue &#x3D;&#x3D; null) &#123;\n remove(key);\n &#125; else &#123;\n put(key, newValue);\n &#125;\n return newValue;\n&#125;</code></pre>\n<p>功能将指定的键和值合并到Map中根据提供的函数计算新值。</p>\n<h2 id=\"put-K-V\"><a href=\"#put-K-V\" class=\"headerlink\" title=\"put(K,V)\"></a><a id=\"putkv\">put(K,V)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Associates the specified value with the specified key in this map\n * (optional operation). If the map previously contained a mapping for\n * the key, the old value is replaced by the specified value. (A map\n * &lt;tt&gt;m&lt;&#x2F;tt&gt; is said to contain a mapping for a key &lt;tt&gt;k&lt;&#x2F;tt&gt; if and only\n * if &#123;@link #containsKey(Object) m.containsKey(k)&#125; would return\n * &lt;tt&gt;true&lt;&#x2F;tt&gt;.)\n *\n * @param key key with which the specified value is to be associated\n * @param value value to be associated with the specified key\n * @return the previous value associated with &lt;tt&gt;key&lt;&#x2F;tt&gt;, or\n * &lt;tt&gt;null&lt;&#x2F;tt&gt; if there was no mapping for &lt;tt&gt;key&lt;&#x2F;tt&gt;.\n * (A &lt;tt&gt;null&lt;&#x2F;tt&gt; return can also indicate that the map\n * previously associated &lt;tt&gt;null&lt;&#x2F;tt&gt; with &lt;tt&gt;key&lt;&#x2F;tt&gt;,\n * if the implementation supports &lt;tt&gt;null&lt;&#x2F;tt&gt; values.)\n * @throws UnsupportedOperationException if the &lt;tt&gt;put&lt;&#x2F;tt&gt; operation\n * is not supported by this map\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * @throws NullPointerException if the specified key or value is null\n * and this map does not permit null keys or values\n * @throws IllegalArgumentException if some property of the specified key\n * or value prevents it from being stored in this map\n *&#x2F;\nV put(K key, V value);</code></pre>\n<p>功能将指定的键值对添加到Map中。</p>\n<h2 id=\"putAll-Map\"><a href=\"#putAll-Map\" class=\"headerlink\" title=\"putAll(Map)\"></a><a id=\"putallmapkv\">putAll(Map<K,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Copies all of the mappings from the specified map to this map\n * (optional operation). The effect of this call is equivalent to that\n * of calling &#123;@link #put(Object,Object) put(k, v)&#125; on this map once\n * for each mapping from key &lt;tt&gt;k&lt;&#x2F;tt&gt; to value &lt;tt&gt;v&lt;&#x2F;tt&gt; in the\n * specified map. The behavior of this operation is undefined if the\n * specified map is modified while the operation is in progress.\n *\n * @param m mappings to be stored in this map\n * @throws UnsupportedOperationException if the &lt;tt&gt;putAll&lt;&#x2F;tt&gt; operation\n * is not supported by this map\n * @throws ClassCastException if the class of a key or value in the\n * specified map prevents it from being stored in this map\n * @throws NullPointerException if the specified map is null, or if\n * this map does not permit null keys or values, and the\n * specified map contains null keys or values\n * @throws IllegalArgumentException if some property of a key or value in\n * the specified map prevents it from being stored in this map\n *&#x2F;\nvoid putAll(Map&lt;? extends K, ? extends V&gt; m);</code></pre>\n<p>功能将指定Map中的所有键值对添加到当前Map中。</p>\n<h2 id=\"putIfAbsent-K-V\"><a href=\"#putIfAbsent-K-V\" class=\"headerlink\" title=\"putIfAbsent(K,V)\"></a><a id=\"putifabsentkv\">putIfAbsent(K,V)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * If the specified key is not already associated with a value (or is mapped\n * to &#123;@code null&#125;) associates it with the given value and returns\n * &#123;@code null&#125;, else returns the current value.\n *\n * @implSpec\n * The default implementation is equivalent to, for this &#123;@code\n * map&#125;:\n *\n * &lt;pre&gt; &#123;@code\n * V v &#x3D; map.get(key);\n * if (v &#x3D;&#x3D; null)\n * v &#x3D; map.put(key, value);\n *\n * return v;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param key key with which the specified value is to be associated\n * @param value value to be associated with the specified key\n * @return the previous value associated with the specified key, or\n * &#123;@code null&#125; if there was no mapping for the key.\n * (A &#123;@code null&#125; return can also indicate that the map\n * previously associated &#123;@code null&#125; with the key,\n * if the implementation supports null values.)\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the key or value is of an inappropriate\n * type for this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key or value is null,\n * and this map does not permit null keys or values\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws IllegalArgumentException if some property of the specified key\n * or value prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @since 1.8\n *&#x2F;\ndefault V putIfAbsent(K key, V value) &#123;\n V v &#x3D; get(key);\n if (v &#x3D;&#x3D; null) &#123;\n v &#x3D; put(key, value);\n &#125;\n return v;\n&#125;</code></pre>\n<p>功能将指定的键值对添加到Map中但仅当指定的键在Map中不存在时。</p>\n<h2 id=\"remove-Object\"><a href=\"#remove-Object\" class=\"headerlink\" title=\"remove(Object)\"></a><a id=\"removeobject\">remove(Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Removes the mapping for a key from this map if it is present\n * (optional operation). More formally, if this map contains a mapping\n * from key &lt;tt&gt;k&lt;&#x2F;tt&gt; to value &lt;tt&gt;v&lt;&#x2F;tt&gt; such that\n * &lt;code&gt;(key&#x3D;&#x3D;null ? k&#x3D;&#x3D;null : key.equals(k))&lt;&#x2F;code&gt;, that mapping\n * is removed. (The map can contain at most one such mapping.)\n *\n * &lt;p&gt;Returns the value to which this map previously associated the key,\n * or &lt;tt&gt;null&lt;&#x2F;tt&gt; if the map contained no mapping for the key.\n *\n * &lt;p&gt;If this map permits null values, then a return value of\n * &lt;tt&gt;null&lt;&#x2F;tt&gt; does not &lt;i&gt;necessarily&lt;&#x2F;i&gt; indicate that the map\n * contained no mapping for the key; it&#39;s also possible that the map\n * explicitly mapped the key to &lt;tt&gt;null&lt;&#x2F;tt&gt;.\n *\n * &lt;p&gt;The map will not contain a mapping for the specified key once the\n * call returns.\n *\n * @param key key whose mapping is to be removed from the map\n * @return the previous value associated with &lt;tt&gt;key&lt;&#x2F;tt&gt;, or\n * &lt;tt&gt;null&lt;&#x2F;tt&gt; if there was no mapping for &lt;tt&gt;key&lt;&#x2F;tt&gt;.\n * @throws UnsupportedOperationException if the &lt;tt&gt;remove&lt;&#x2F;tt&gt; operation\n * is not supported by this map\n * @throws ClassCastException if the key is of an inappropriate type for\n * this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key is null and this\n * map does not permit null keys\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n *&#x2F;\nV remove(Object key);</code></pre>\n<p>功能移除Map中指定键对应的值。</p>\n<h2 id=\"remove-Object-Object\"><a href=\"#remove-Object-Object\" class=\"headerlink\" title=\"remove(Object,Object)\"></a><a id=\"removeobjectobject\">remove(Object,Object)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Removes the entry for the specified key only if it is currently\n * mapped to the specified value.\n *\n * @implSpec\n * The default implementation is equivalent to, for this &#123;@code map&#125;:\n *\n * &lt;pre&gt; &#123;@code\n * if (map.containsKey(key) &amp;&amp; Objects.equals(map.get(key), value)) &#123;\n * map.remove(key);\n * return true;\n * &#125; else\n * return false;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param key key with which the specified value is associated\n * @param value value expected to be associated with the specified key\n * @return &#123;@code true&#125; if the value was removed\n * @throws UnsupportedOperationException if the &#123;@code remove&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the key or value is of an inappropriate\n * type for this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key or value is null,\n * and this map does not permit null keys or values\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @since 1.8\n *&#x2F;\ndefault boolean remove(Object key, Object value) &#123;\n Object curValue &#x3D; get(key);\n if (!Objects.equals(curValue, value) ||\n (curValue &#x3D;&#x3D; null &amp;&amp; !containsKey(key))) &#123;\n return false;\n &#125;\n remove(key);\n return true;\n&#125;</code></pre>\n<p>功能移除Map中指定键对应的值仅当该键关联的值与指定值相等时才移除。</p>\n<h2 id=\"replace-K-V-V\"><a href=\"#replace-K-V-V\" class=\"headerlink\" title=\"replace(K,V,V)\"></a><a id=\"replacekvv\">replace(K,V,V)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Replaces the entry for the specified key only if currently\n * mapped to the specified value.\n *\n * @implSpec\n * The default implementation is equivalent to, for this &#123;@code map&#125;:\n *\n * &lt;pre&gt; &#123;@code\n * if (map.containsKey(key) &amp;&amp; Objects.equals(map.get(key), value)) &#123;\n * map.put(key, newValue);\n * return true;\n * &#125; else\n * return false;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * The default implementation does not throw NullPointerException\n * for maps that do not support null values if oldValue is null unless\n * newValue is also null.\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param key key with which the specified value is associated\n * @param oldValue value expected to be associated with the specified key\n * @param newValue value to be associated with the specified key\n * @return &#123;@code true&#125; if the value was replaced\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the class of a specified key or value\n * prevents it from being stored in this map\n * @throws NullPointerException if a specified key or newValue is null,\n * and this map does not permit null keys or values\n * @throws NullPointerException if oldValue is null and this map does not\n * permit null values\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws IllegalArgumentException if some property of a specified key\n * or value prevents it from being stored in this map\n * @since 1.8\n *&#x2F;\ndefault boolean replace(K key, V oldValue, V newValue) &#123;\n Object curValue &#x3D; get(key);\n if (!Objects.equals(curValue, oldValue) ||\n (curValue &#x3D;&#x3D; null &amp;&amp; !containsKey(key))) &#123;\n return false;\n &#125;\n put(key, newValue);\n return true;\n&#125;</code></pre>\n<p>功能将Map中指定键对应的旧值替换为新值仅当键对应的值与旧值相等时才替换。</p>\n<h2 id=\"replace-K-V\"><a href=\"#replace-K-V\" class=\"headerlink\" title=\"replace(K,V)\"></a><a id=\"replacekv\">replace(K,V)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Replaces the entry for the specified key only if it is\n * currently mapped to some value.\n *\n * @implSpec\n * The default implementation is equivalent to, for this &#123;@code map&#125;:\n *\n * &lt;pre&gt; &#123;@code\n * if (map.containsKey(key)) &#123;\n * return map.put(key, value);\n * &#125; else\n * return null;\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param key key with which the specified value is associated\n * @param value value to be associated with the specified key\n * @return the previous value associated with the specified key, or\n * &#123;@code null&#125; if there was no mapping for the key.\n * (A &#123;@code null&#125; return can also indicate that the map\n * previously associated &#123;@code null&#125; with the key,\n * if the implementation supports null values.)\n * @throws UnsupportedOperationException if the &#123;@code put&#125; operation\n * is not supported by this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ClassCastException if the class of the specified key or value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if the specified key or value is null,\n * and this map does not permit null keys or values\n * @throws IllegalArgumentException if some property of the specified key\n * or value prevents it from being stored in this map\n * @since 1.8\n *&#x2F;\ndefault V replace(K key, V value) &#123;\n V curValue;\n if (((curValue &#x3D; get(key)) !&#x3D; null) || containsKey(key)) &#123;\n curValue &#x3D; put(key, value);\n &#125;\n return curValue;\n&#125;</code></pre>\n<p>功能将Map中指定键对应的值替换为新值返回旧值。</p>\n<h2 id=\"replaceAll-BiFunction\"><a href=\"#replaceAll-BiFunction\" class=\"headerlink\" title=\"replaceAll(BiFunction)\"></a><a id=\"replaceallbifunctionkvv\">replaceAll(BiFunction<K,V,V>)</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Replaces each entry&#39;s value with the result of invoking the given\n * function on that entry until all entries have been processed or the\n * function throws an exception. Exceptions thrown by the function are\n * relayed to the caller.\n *\n * @implSpec\n * &lt;p&gt;The default implementation is equivalent to, for this &#123;@code map&#125;:\n * &lt;pre&gt; &#123;@code\n * for (Map.Entry&lt;K, V&gt; entry : map.entrySet())\n * entry.setValue(function.apply(entry.getKey(), entry.getValue()));\n * &#125;&lt;&#x2F;pre&gt;\n *\n * &lt;p&gt;The default implementation makes no guarantees about synchronization\n * or atomicity properties of this method. Any implementation providing\n * atomicity guarantees must override this method and document its\n * concurrency properties.\n *\n * @param function the function to apply to each entry\n * @throws UnsupportedOperationException if the &#123;@code set&#125; operation\n * is not supported by this map&#39;s entry set iterator.\n * @throws ClassCastException if the class of a replacement value\n * prevents it from being stored in this map\n * @throws NullPointerException if the specified function is null, or the\n * specified replacement value is null, and this map does not permit null\n * values\n * @throws ClassCastException if a replacement value is of an inappropriate\n * type for this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws NullPointerException if function or a replacement value is null,\n * and this map does not permit null keys or values\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws IllegalArgumentException if some property of a replacement value\n * prevents it from being stored in this map\n * (&lt;a href&#x3D;&quot;&#123;@docRoot&#125;&#x2F;java&#x2F;util&#x2F;Collection.html#optional-restrictions&quot;&gt;optional&lt;&#x2F;a&gt;)\n * @throws ConcurrentModificationException if an entry is found to be\n * removed during iteration\n * @since 1.8\n *&#x2F;\ndefault void replaceAll(BiFunction&lt;? super K, ? super V, ? extends V&gt; function) &#123;\n Objects.requireNonNull(function);\n for (Map.Entry&lt;K, V&gt; entry : entrySet()) &#123;\n K k;\n V v;\n try &#123;\n k &#x3D; entry.getKey();\n v &#x3D; entry.getValue();\n &#125; catch(IllegalStateException ise) &#123;\n &#x2F;&#x2F; this usually means the entry is no longer in the map.\n throw new ConcurrentModificationException(ise);\n &#125;\n &#x2F;&#x2F; ise thrown from function is not a cme.\n v &#x3D; function.apply(k, v);\n try &#123;\n entry.setValue(v);\n &#125; catch(IllegalStateException ise) &#123;\n &#x2F;&#x2F; this usually means the entry is no longer in the map.\n throw new ConcurrentModificationException(ise);\n &#125;\n &#125;\n&#125;</code></pre>\n<p>功能对Map中的每个键值对执行指定的替换操作。</p>\n<h2 id=\"size\"><a href=\"#size\" class=\"headerlink\" title=\"size()\"></a><a id=\"size\">size()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns the number of key-value mappings in this map. If the\n * map contains more than &lt;tt&gt;Integer.MAX_VALUE&lt;&#x2F;tt&gt; elements, returns\n * &lt;tt&gt;Integer.MAX_VALUE&lt;&#x2F;tt&gt;.\n *\n * @return the number of key-value mappings in this map\n *&#x2F;\nint size();</code></pre>\n<p>功能返回Map中键值对的数量。</p>\n<h2 id=\"values\"><a href=\"#values\" class=\"headerlink\" title=\"values()\"></a><a id=\"values\">values()</a></h2><p>源码:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Returns a &#123;@link Collection&#125; view of the values contained in this map.\n * The collection is backed by the map, so changes to the map are\n * reflected in the collection, and vice-versa. If the map is\n * modified while an iteration over the collection is in progress\n * (except through the iterator&#39;s own &lt;tt&gt;remove&lt;&#x2F;tt&gt; operation),\n * the results of the iteration are undefined. The collection\n * supports element removal, which removes the corresponding\n * mapping from the map, via the &lt;tt&gt;Iterator.remove&lt;&#x2F;tt&gt;,\n * &lt;tt&gt;Collection.remove&lt;&#x2F;tt&gt;, &lt;tt&gt;removeAll&lt;&#x2F;tt&gt;,\n * &lt;tt&gt;retainAll&lt;&#x2F;tt&gt; and &lt;tt&gt;clear&lt;&#x2F;tt&gt; operations. It does not\n * support the &lt;tt&gt;add&lt;&#x2F;tt&gt; or &lt;tt&gt;addAll&lt;&#x2F;tt&gt; operations.\n *\n * @return a collection view of the values contained in this map\n *&#x2F;\nCollection&lt;V&gt; values();</code></pre>\n<p>功能返回包含Map中所有值的Collection集合。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"win11新电脑环境安装","slug":"win11xin-dian-nao-huan-jing-an-zhuang","date":"2024-02-04T01:19:58.000Z","updated":"2024-02-04T06:34:55.541Z","comments":true,"path":"/post/win11xin-dian-nao-huan-jing-an-zhuang/","link":"","excerpt":"","content":"<p>新的mini主机到了为了之后的开发方便需要先安装各种软件这里记录下需要安装的软件我这边是以Java为主</p>\n<h1 id=\"Java\"><a href=\"#Java\" class=\"headerlink\" title=\"Java\"></a>Java</h1><p>我这边Java下载安装的是17版本的下载地址<a href=\"https://www.oracle.com/java/technologies/downloads/#jdk17-windows\">Java Downloads | Oracle</a>,下面是下载页面,根据自己电脑的情况安装不同的版本</p>\n<p><img src=\"https://img.huangge1199.cn/blog/win11xin-dian-nao-huan-jing-an-zhuang/2024-02-04-09-41-42-image.png\" alt=\"\"></p>\n<h1 id=\"maven\"><a href=\"#maven\" class=\"headerlink\" title=\"maven\"></a>maven</h1><p>我使用的是3.6.3,下载地址:<a href=\"https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/\">maven</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/win11xin-dian-nao-huan-jing-an-zhuang/2024-02-04-10-27-27-image.png\" alt=\"\"></p>\n<h1 id=\"nvm\"><a href=\"#nvm\" class=\"headerlink\" title=\"nvm\"></a>nvm</h1><p>安装包在GitHub中下载的安装说明也挺详细地址<a href=\"https://github.com/coreybutler/nvm-windows\">nvm-windows</a></p>\n<h1 id=\"git\"><a href=\"#git\" class=\"headerlink\" title=\"git\"></a>git</h1><p>官网下载地址:<a href=\"https://git-scm.com/download\">git</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/win11xin-dian-nao-huan-jing-an-zhuang/2024-02-04-13-54-17-image.png\" alt=\"\"></p>\n<h1 id=\"nodejs\"><a href=\"#nodejs\" class=\"headerlink\" title=\"nodejs\"></a>nodejs</h1><p>通过nvm安装LTS版本</p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"1686. 石子游戏 VI2024-02-02","slug":"1686-shi-zi-you-xi-vi-2024-02-02","date":"2024-02-02T07:25:51.000Z","updated":"2024-02-02T07:32:45.137Z","comments":true,"path":"/post/1686-shi-zi-you-xi-vi-2024-02-02/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/stone-game-vi/\">1686. 石子游戏 VI</a></p>\n<p><img src=\"https://img.huangge1199.cn/halo/2024-02-02.png\" alt=\"2024-02-02.png\"></p>\n<p>日期2024-02-02<br>用时15 m 0 s<br>时间103ms<br>内存57.95MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int stoneGameVI(int[] aliceValues, int[] bobValues) &#123;\n int cnt &#x3D; aliceValues.length;\n int[][] arrs &#x3D; new int[cnt][2];\n for (int i &#x3D; 0; i &lt; cnt; i++) &#123;\n arrs[i] &#x3D; new int[]&#123;aliceValues[i],bobValues[i]&#125;;\n &#125;\n Arrays.sort(arrs,(a,b)-&gt;(b[0]+ b[1])-(a[0]+ a[1]));\n int sub &#x3D; 0;\n for (int i &#x3D; 0; i &lt; cnt; i++) &#123;\n sub+&#x3D;i%2&#x3D;&#x3D;0?arrs[i][0]:-arrs[i][1];\n &#125;\n return sub &#x3D;&#x3D; 0? 0 :sub &#x2F; Math.abs(sub);\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2024-01-27-跑章整理","slug":"2024-01-27-pao-zhang-zheng-li","date":"2024-01-29T01:31:39.000Z","updated":"2024-02-05T06:36:39.349Z","comments":true,"path":"/post/2024-01-27-pao-zhang-zheng-li/","link":"","excerpt":"","content":"<h1 id=\"总览\"><a href=\"#总览\" class=\"headerlink\" title=\"总览\"></a>总览</h1><p>通过几天晚上的整理规划出了今天的路线大概上要去下面这些地方辽宁美术馆城市规划馆万豪酒店k11广电博物馆文化路万达盛京龙城盛京大家庭大悦城乐高全运路万达在跑章的过程中临时加入了大悦城霸王别姬</p>\n<h1 id=\"计划\"><a href=\"#计划\" class=\"headerlink\" title=\"计划\"></a>计划</h1><p>通过整理这些地方的地点和营业时间,初步按照下面的顺序依次跑章</p>\n<h2 id=\"辽宁美术馆\"><a href=\"#辽宁美术馆\" class=\"headerlink\" title=\"辽宁美术馆\"></a>辽宁美术馆</h2><ul>\n<li><p>营业时间9:00~17:001600后不让进</p>\n</li>\n<li><p>路线2号线 “市图书馆”B口</p>\n</li>\n<li><p>盖章数5枚</p>\n</li>\n</ul>\n<h2 id=\"城市规划馆\"><a href=\"#城市规划馆\" class=\"headerlink\" title=\"城市规划馆\"></a>城市规划馆</h2><ul>\n<li><p>时间9:00~17:001600后不让进</p>\n</li>\n<li><p>路线2号线”沈阳市图书馆站“C口辽宁美术馆步行过来700米</p>\n</li>\n<li><p>盖章数7枚</p>\n</li>\n<li><p>注意事项:需要带身份证</p>\n</li>\n</ul>\n<h2 id=\"沈阳皇朝万豪酒店\"><a href=\"#沈阳皇朝万豪酒店\" class=\"headerlink\" title=\"沈阳皇朝万豪酒店\"></a>沈阳皇朝万豪酒店</h2><ul>\n<li><p>时间2024.1.191.2810001800</p>\n</li>\n<li><p>路线2号线五里河站B1口辽宁美术馆步行900米城市规划馆步行900米</p>\n</li>\n<li><p>盖章数17枚</p>\n</li>\n<li><p>注意事项分布在1楼和3楼的各个摊位需要挨个问</p>\n</li>\n</ul>\n<h2 id=\"k11\"><a href=\"#k11\" class=\"headerlink\" title=\"k11\"></a>k11</h2><ul>\n<li><p>路线2号线五里河B1口万豪酒店步行800米</p>\n</li>\n<li><p>盖章数共6枚中信书店2枚3楼歌德书店2枚2楼西西弗书店2枚1楼</p>\n</li>\n</ul>\n<h2 id=\"广电博物馆\"><a href=\"#广电博物馆\" class=\"headerlink\" title=\"广电博物馆\"></a>广电博物馆</h2><ul>\n<li><p>时间2024.1.27 10:00~15:30</p>\n</li>\n<li><p>路线2号线工业展览馆C口沈阳美术馆步行936米</p>\n</li>\n</ul>\n<h2 id=\"文化路万达\"><a href=\"#文化路万达\" class=\"headerlink\" title=\"文化路万达\"></a>文化路万达</h2><ul>\n<li><p>时间10:00~22:00</p>\n</li>\n<li><p>路线: 2号线工业展览馆C口</p>\n</li>\n</ul>\n<h2 id=\"盛京龙城\"><a href=\"#盛京龙城\" class=\"headerlink\" title=\"盛京龙城\"></a>盛京龙城</h2><ul>\n<li><p>盖章数14枚</p>\n</li>\n<li><p>注意事项1楼盛京阿哥</p>\n</li>\n</ul>\n<h2 id=\"盛京大家庭\"><a href=\"#盛京大家庭\" class=\"headerlink\" title=\"盛京大家庭\"></a>盛京大家庭</h2><ul>\n<li><p>时间2024.1.26 ~ 2024.1.30</p>\n</li>\n<li><p>注意事项:负一层大脸鸭记</p>\n</li>\n</ul>\n<h2 id=\"大悦城乐高\"><a href=\"#大悦城乐高\" class=\"headerlink\" title=\"大悦城乐高\"></a>大悦城乐高</h2><ul>\n<li><p>盖章数3枚</p>\n</li>\n<li><p>注意事项: 中街乐高大悦城C馆一进门那个泡泡玛特对面</p>\n</li>\n</ul>\n","categories":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/categories/%E7%9B%96%E7%AB%A0/"}],"tags":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/tags/%E7%9B%96%E7%AB%A0/"}]},{"title":"162. 寻找峰值2023-12-18","slug":"162-xun-zhao-feng-zhi-2023-12-18","date":"2023-12-18T03:10:01.000Z","updated":"2023-12-18T03:10:51.151Z","comments":true,"path":"/post/162-xun-zhao-feng-zhi-2023-12-18/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/find-peak-element/description/\">162. 寻找峰值</a></p>\n<p><img src=\"https://img.huangge1199.cn/halo/2023-12-18.png\" alt=\"2023-12-18.png\"><br>日期2023-12-18<br>用时10 m 9 s<br>时间0 ms<br>内存40.54 MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int findPeakElement(int[] nums) &#123;\n if(nums.length&#x3D;&#x3D;1)&#123;\n return 0;\n &#125;\n if(nums.length&#x3D;&#x3D;2)&#123;\n return nums[0]&gt;nums[1]?0:1;\n &#125;\n if(nums[0]&gt;nums[1])&#123;\n return 0;\n &#125;\n if(nums[nums.length-1]&gt;nums[nums.length-2])&#123;\n return nums.length-1;\n &#125;\n for(int i&#x3D;1;i&lt;nums.length-1;i++)&#123;\n if(nums[i]&gt;nums[i-1]&amp;&amp;nums[i]&gt;nums[i+1])&#123;\n return i;\n &#125;\n &#125;\n return 0;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2415. 反转二叉树的奇数层2023-12-15","slug":"2415-fan-zhuan-er-cha-shu-de-qi-shu-ceng-2023-12-15","date":"2023-12-18T03:04:16.000Z","updated":"2023-12-18T03:05:01.251Z","comments":true,"path":"/post/2415-fan-zhuan-er-cha-shu-de-qi-shu-ceng-2023-12-15/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/reverse-odd-levels-of-binary-tree/description/\">2415. 反转二叉树的奇数层</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-15.png\" alt=\"2023-12-15.png\"><br>日期2023-12-15<br>用时6 m 51 s<br>时间0 ms<br>内存46.97 MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Definition for a binary tree node.\n * public class TreeNode &#123;\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() &#123;&#125;\n * TreeNode(int val) &#123; this.val &#x3D; val; &#125;\n * TreeNode(int val, TreeNode left, TreeNode right) &#123;\n * this.val &#x3D; val;\n * this.left &#x3D; left;\n * this.right &#x3D; right;\n * &#125;\n * &#125;\n *&#x2F;\nclass Solution &#123;\n public TreeNode reverseOddLevels(TreeNode root) &#123;\n dfs(root.left, root.right, 1);\n return root;\n &#125;\n\n void dfs(TreeNode left,TreeNode right,int odd)&#123;\n if(left&#x3D;&#x3D;null)&#123;\n return;\n &#125;\n if(odd&#x3D;&#x3D;1)&#123;\n int temp &#x3D; left.val;\n left.val &#x3D; right.val;\n right.val &#x3D; temp;\n &#125;\n dfs(left.left, right.right, 1-odd);\n dfs(left.right, right.left, 1-odd);\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2132. 用邮票贴满网格图2023-12-14","slug":"2132-yong-you-piao-tie-man-wang-ge-tu-2023-12-14","date":"2023-12-14T01:39:13.000Z","updated":"2023-12-14T01:39:59.531Z","comments":true,"path":"/post/2132-yong-you-piao-tie-man-wang-ge-tu-2023-12-14/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/stamping-the-grid/description/\">2132. 用邮票贴满网格图</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-14.png\" alt=\"2023-12-14.png\"><br>日期2023-12-14<br>用时38 m 32 s<br>思路:使用前缀和+差分,只是往常是一维,现在变二维了,原理差不多<br>时间22ms<br>内存98.24MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) &#123;\n int xl &#x3D; grid.length;\n int yl &#x3D; grid[0].length;\n\n &#x2F;&#x2F; 前缀和\n int[][] sum &#x3D; new int[xl+1][yl+1];\n for(int i&#x3D;1;i&lt;&#x3D;xl;i++)&#123;\n for(int j&#x3D;1;j&lt;&#x3D;yl;j++)&#123;\n sum[i][j] &#x3D; sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+grid[i-1][j-1];\n &#125;\n &#125;\n\n &#x2F;&#x2F; 差分\n int[][] cnt &#x3D; new int[xl+2][yl+2];\n for(int xStart&#x3D;stampHeight;xStart&lt;&#x3D;xl;xStart++)&#123;\n for(int yStart&#x3D;stampWidth;yStart&lt;&#x3D;yl;yStart++)&#123;\n int xEnd &#x3D; xStart-stampHeight+1;\n int yEnd &#x3D; yStart-stampWidth+1;\n if(sum[xStart][yStart]+sum[xEnd-1][yEnd-1]-sum[xStart][yEnd-1]-sum[xEnd-1][yStart]&#x3D;&#x3D;0)&#123;\n cnt[xEnd][yEnd]++;\n cnt[xStart+1][yStart+1]++;\n cnt[xEnd][yStart+1]--;\n cnt[xStart+1][yEnd]--;\n &#125;\n &#125;\n &#125;\n\n &#x2F;&#x2F; 判断单元格是否能放邮戳\n for(int i&#x3D;1;i&lt;&#x3D;xl;i++)&#123;\n for(int j&#x3D;1;j&lt;&#x3D;yl;j++)&#123;\n cnt[i][j] +&#x3D; cnt[i][j-1]+cnt[i-1][j]-cnt[i-1][j-1];\n if(grid[i-1][j-1]&#x3D;&#x3D;0&amp;&amp;cnt[i][j]&#x3D;&#x3D;0)&#123;\n return false;\n &#125;\n &#125;\n &#125;\n\n return true;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2697. 字典序最小回文串2023-12-13","slug":"2697-zi-dian-xu-zui-xiao-hui-wen-chuan-2023-12-13","date":"2023-12-13T01:01:34.000Z","updated":"2023-12-13T01:03:09.576Z","comments":true,"path":"/post/2697-zi-dian-xu-zui-xiao-hui-wen-chuan-2023-12-13/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/lexicographically-smallest-palindrome/description/\">2697. 字典序最小回文串</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-13.png\" alt=\"2023-12-13.png\"><br>日期2023-12-13<br>用时4 m 53 s<br>时间7ms<br>内存43.61MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public String makeSmallestPalindrome(String s) &#123;\n char[] chs &#x3D; s.toCharArray();\n int size &#x3D; s.length();\n for(int i&#x3D;0;i&lt;size&#x2F;2;i++)&#123;\n if(chs[i]&gt;chs[size-1-i])&#123;\n chs[i] &#x3D; chs[size-1-i];\n &#125;else&#123;\n chs[size-1-i] &#x3D; chs[i];\n &#125;\n &#125;\n return new String(chs);\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2454. 下一个更大元素 IV2023-12-12","slug":"2454-xia-yi-ge-geng-da-yuan-su-iv","date":"2023-12-13T00:55:55.000Z","updated":"2023-12-13T00:57:15.476Z","comments":true,"path":"/post/2454-xia-yi-ge-geng-da-yuan-su-iv/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/next-greater-element-iv/description/\">2454. 下一个更大元素 IV</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-12.png\" alt=\"2023-12-12.png\"><br>日期2023-12-12<br>用时35 m 09 s<br>时间614ms<br>内存57.18MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int[] secondGreaterElement(int[] nums) &#123;\n int[] res &#x3D; new int[nums.length];\n Arrays.fill(res, -1);\n List&lt;Integer&gt; list1 &#x3D; new ArrayList&lt;&gt;();\n List&lt;Integer&gt; list2 &#x3D; new ArrayList&lt;&gt;();\n for (int i &#x3D; 0; i &lt; nums.length; i++) &#123;\n while (!list2.isEmpty() &amp;&amp; nums[list2.get(list2.size() - 1)] &lt; nums[i]) &#123;\n res[list2.get(list2.size() - 1)] &#x3D; nums[i];\n list2.remove(list2.size() - 1);\n &#125;\n int j &#x3D; list1.size();\n for(;j&gt;0;j--)&#123;\n if(nums[list1.get(j - 1)] &gt;&#x3D; nums[i])&#123;\n break;\n &#125;\n &#125;\n while (j&lt;list1.size()) &#123;\n list2.add(list1.get(j));\n list1.remove(j);\n &#125;\n list1.add(i);\n &#125;\n return res;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"沈阳四家万达2023-12-09、2023-12-10","slug":"shen-yang-si-jia-wan-da-2023-12-09-2023-12-10","date":"2023-12-13T00:54:12.000Z","updated":"2023-12-13T00:55:20.471Z","comments":true,"path":"/post/shen-yang-si-jia-wan-da-2023-12-09-2023-12-10/","link":"","excerpt":"","content":"<p>全运路万达8枚<br>铁西万达4枚<br>北一路万达16枚<br>太原街万达8枚</p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_17_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_17_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_18_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_18_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_14_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_14_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_13_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_13_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_16_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_16_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_15_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_15_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_11_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_11_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_12_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_12_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_9_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_9_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_10_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_10_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_3_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_3_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_2_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_2_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_4_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_4_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_5_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_5_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_1_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_1_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_7_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_7_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_8_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_8_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p><img src=\"https://img.huangge1199.cn/halo/%E6%B2%88%E9%98%B3%E5%9B%9B%E5%AE%B6%E4%B8%87%E8%BE%BE%E7%9B%96%E7%AB%A0%E6%89%93%E5%8D%A1_6_%E5%A4%8F%E5%A4%9C%E6%99%9A%E9%A3%8E_%E6%9D%A5%E8%87%AA%E5%B0%8F%E7%BA%A2%E4%B9%A6%E7%BD%91%E9%A1%B5%E7%89%88.jpg\" alt=\"沈阳四家万达盖章打卡_6_夏夜晚风_来自小红书网页版.jpg\"></p>\n<p>(摘自小红书<a href=\"https://www.xiaohongshu.com/explore/65758b310000000006020803?m_source=mengfanwetab\">https://www.xiaohongshu.com/explore/65758b310000000006020803?m_source=mengfanwetab</a>)</p>\n","categories":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/categories/%E7%9B%96%E7%AB%A0/"}],"tags":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/tags/%E7%9B%96%E7%AB%A0/"}]},{"title":"2008. 出租车的最大盈利2023-12-08","slug":"2008-chu-zu-che-de-zui-da-ying-li-2023-12-08","date":"2023-12-13T00:52:23.000Z","updated":"2023-12-13T00:53:09.585Z","comments":true,"path":"/post/2008-chu-zu-che-de-zui-da-ying-li-2023-12-08/","link":"","excerpt":"","content":"<p>力扣每日一题</p>\n<h1 id=\"题目2008-出租车的最大盈利\"><a href=\"#题目2008-出租车的最大盈利\" class=\"headerlink\" title=\"题目2008. 出租车的最大盈利\"></a>题目:<a href=\"https://leetcode.cn/problems/maximum-earnings-from-taxi/description/\">2008. 出租车的最大盈利</a></h1><p><img src=\"https://img.huangge1199.cn/halo/2023-12-08.png\" alt=\"2023-12-08.png\"></p>\n<h1 id=\"简短说明\"><a href=\"#简短说明\" class=\"headerlink\" title=\"简短说明\"></a>简短说明</h1><p>今天的解题有点曲折完全是一步一步优化来的看上面的截图最开始的超时超时后我加了记忆化搜索虽然通过了但是执行时间不太理想接下来我稍微优化了下但是执行时间基本没动过接下来又尝试着去掉递归这次效果很显著执行时间直接从2000多毫秒降低到了18毫秒</p>\n<h1 id=\"过程\"><a href=\"#过程\" class=\"headerlink\" title=\"过程\"></a>过程</h1><p>下面我分别把这四次的代码都展示出来,记录下每次的优化,代码展示顺序是按照上面的截图从下往上的</p>\n<h2 id=\"超出时间限制\"><a href=\"#超出时间限制\" class=\"headerlink\" title=\"超出时间限制\"></a>超出时间限制</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public long maxTaxiEarnings(int n, int[][] rides) &#123;\n List&lt;int[]&gt;[] prices &#x3D; new ArrayList[n+1];\n for(int[] ride:rides)&#123;\n if(prices[ride[1]]&#x3D;&#x3D;null)&#123;\n prices[ride[1]] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n prices[ride[1]].add(new int[]&#123;ride[0],ride[1]-ride[0]+ride[2]&#125;);\n &#125;\n return dfs(n,prices);\n &#125;\n long dfs(int index,List&lt;int[]&gt;[] prices)&#123;\n if(index&#x3D;&#x3D;1)&#123;\n return 0;\n &#125;\n long res &#x3D; dfs(index-1,prices);\n if(prices[index]!&#x3D;null)&#123;\n for(int[] price:prices[index])&#123;\n res &#x3D; Math.max(res,dfs(price[0],prices)+price[1]);\n &#125;\n &#125;\n return res;\n &#125;\n&#125;</code></pre>\n<h2 id=\"2219ms-84-8MB\"><a href=\"#2219ms-84-8MB\" class=\"headerlink\" title=\"2219ms + 84.8MB\"></a>2219ms + 84.8MB</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public long maxTaxiEarnings(int n, int[][] rides) &#123;\n List&lt;int[]&gt;[] prices &#x3D; new ArrayList[n+1];\n for(int[] ride:rides)&#123;\n if(prices[ride[1]]&#x3D;&#x3D;null)&#123;\n prices[ride[1]] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n prices[ride[1]].add(new int[]&#123;ride[0],ride[1]-ride[0]+ride[2]&#125;);\n &#125;\n max &#x3D; new long[n+1];\n return dfs(n,prices);\n &#125; \n long[] max;\n long dfs(int index,List&lt;int[]&gt;[] prices)&#123;\n if(index&#x3D;&#x3D;1)&#123;\n return 0;\n &#125;\n long res &#x3D; dfs(index-1,prices);\n if(prices[index]!&#x3D;null)&#123;\n for(int[] price:prices[index])&#123;\n if(max[price[0]]&gt;0)&#123;\n res &#x3D; Math.max(res,max[price[0]]+price[1]);\n &#125;else&#123;\n res &#x3D; Math.max(res,dfs(price[0],prices)+price[1]);\n &#125;\n &#125;\n &#125;\n max[index] &#x3D; res;\n return res;\n &#125;\n&#125;</code></pre>\n<h2 id=\"2306ms-84-2MB\"><a href=\"#2306ms-84-2MB\" class=\"headerlink\" title=\"2306ms + 84.2MB\"></a>2306ms + 84.2MB</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public long maxTaxiEarnings(int n, int[][] rides) &#123;\n List&lt;int[]&gt;[] prices &#x3D; new ArrayList[n+1];\n for(int[] ride:rides)&#123;\n if(prices[ride[1]]&#x3D;&#x3D;null)&#123;\n prices[ride[1]] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n prices[ride[1]].add(new int[]&#123;ride[0],ride[1]-ride[0]+ride[2]&#125;);\n &#125;\n max &#x3D; new long[n+1];\n return dfs(n,prices);\n &#125; \n long[] max;\n long dfs(int index,List&lt;int[]&gt;[] prices)&#123;\n if(index&#x3D;&#x3D;1)&#123;\n return 0;\n &#125;\n if(max[index]&gt;0)&#123;\n return max[index];\n &#125;\n long res &#x3D; dfs(index-1,prices);\n if(prices[index]!&#x3D;null)&#123;\n for(int[] price:prices[index])&#123;\n res &#x3D; Math.max(res,dfs(price[0],prices)+price[1]);\n &#125;\n &#125;\n max[index] &#x3D; res;\n return res;\n &#125;\n&#125;</code></pre>\n<h2 id=\"18ms-67-3MB\"><a href=\"#18ms-67-3MB\" class=\"headerlink\" title=\"18ms + 67.3MB\"></a>18ms + 67.3MB</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public long maxTaxiEarnings(int n, int[][] rides) &#123;\n List&lt;int[]&gt;[] prices &#x3D; new ArrayList[n+1];\n for(int[] ride:rides)&#123;\n if(prices[ride[1]]&#x3D;&#x3D;null)&#123;\n prices[ride[1]] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n prices[ride[1]].add(new int[]&#123;ride[0],ride[1]-ride[0]+ride[2]&#125;);\n &#125;\n long[] max &#x3D; new long[n+1];\n for(int i&#x3D;2;i&lt;&#x3D;n;i++)&#123;\n max[i] &#x3D; max[i-1];\n if(prices[i]!&#x3D;null)&#123;\n for(int[] price:prices[i])&#123;\n max[i] &#x3D; Math.max(max[i],max[price[0]]+price[1]);\n &#125;\n &#125;\n &#125;\n return max[n];\n &#125;\n&#125;</code></pre>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"1466. 重新规划路线2023-12-07","slug":"1466-chong-xin-gui-hua-lu-xian-2023-12-07","date":"2023-12-13T00:48:55.000Z","updated":"2023-12-13T00:50:31.436Z","comments":true,"path":"/post/1466-chong-xin-gui-hua-lu-xian-2023-12-07/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/description/\">1466. 重新规划路线</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-07.png\" alt=\"2023-12-07.png\"><br>日期2023-12-07<br>用时45 m 36 s<br>时间37ms<br>内存69.64MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int minReorder(int n, int[][] connections) &#123;\n list &#x3D; new List[n];\n Arrays.setAll(list, k -&gt; new ArrayList&lt;&gt;());\n for (int[] connection : connections) &#123;\n int start &#x3D; connection[0];\n int end &#x3D; connection[1];\n list[start].add(new int[] &#123;end, 1&#125;);\n list[end].add(new int[] &#123;start, 0&#125;);\n &#125;\n return dfs(0, -1);\n &#125;\n \n List&lt;int[]&gt;[] list;\n\n private int dfs(int index, int target) &#123;\n int ans &#x3D; 0;\n for (int[] num : list[index]) &#123;\n if (num[0] !&#x3D; target) &#123;\n ans +&#x3D; num[1] + dfs(num[0], index);\n &#125;\n &#125;\n return ans;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2646. 最小化旅行的价格总和2023-12-06","slug":"2646-zui-xiao-hua-lu-xing-de-jie-ge-zong-he-2023-12-06","date":"2023-12-06T14:03:31.000Z","updated":"2023-12-07T01:07:09.586Z","comments":true,"path":"/post/2646-zui-xiao-hua-lu-xing-de-jie-ge-zong-he-2023-12-06/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/minimize-the-total-price-of-the-trips/description/\">2646. 最小化旅行的价格总和</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-06.png\" alt=\"2023-12-06.png\"><br>日期2023-12-06<br>用时30 m 14 s<br>时间8ms<br>内存42.98MB<br>思路先统计旅行中每个节点路过的次数dfs方法再计算减半后的价格之和的最小值dp方法最后比较下减半和未减半的价格。dp方法中对于相邻的父子节点有两种情况</p>\n<ul>\n<li>如果父节点价格不变,那么子节点的价格取减半和不变两种情况的最小值</li>\n<li>如果父节点价格减半,那么子节点的价格只能不变</li>\n</ul>\n<p>代码:每条路上通过的城市数量实际就是图中每个节点的子节点数量。<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int minimumTotalPrice(int n, int[][] edges, int[] price, int[][] trips) &#123;\n list &#x3D; new ArrayList[n];\n for(int i&#x3D;0;i&lt;n;i++)&#123;\n list[i] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n for(int[] edge:edges)&#123;\n list[edge[0]].add(edge[1]);\n list[edge[1]].add(edge[0]);\n &#125;\n cnt &#x3D; new int[n];\n for(int[] trip:trips)&#123;\n end &#x3D; trip[1];\n dfs(trip[0],-1);\n &#125;\n int[] res &#x3D; dp(0,-1,price);\n return Math.min(res[0],res[1]);\n &#125;\n List&lt;Integer&gt;[] list;\n int end;\n int[] cnt;\n boolean dfs(int x, int fa) &#123;\n if (x &#x3D;&#x3D; end) &#123;\n cnt[x]++;\n return true;\n &#125;\n for (int y : list[x]) &#123;\n if (y !&#x3D; fa &amp;&amp; dfs(y, x)) &#123;\n cnt[x]++;\n return true;\n &#125;\n &#125;\n return false;\n &#125;\n int[] dp(int index,int target,int[] price)&#123;\n int prices &#x3D; price[index]*cnt[index];\n int halfPrices &#x3D; prices&#x2F;2;\n for(int num:list[index])&#123;\n if(num!&#x3D;target)&#123;\n int[] res &#x3D; dp(num,index,price);\n prices +&#x3D; Math.min(res[0],res[1]);\n halfPrices +&#x3D; res[0];\n &#125;\n &#125;\n return new int[]&#123;prices,halfPrices&#125;;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2477. 到达首都的最少油耗2023-12-05","slug":"2477-dao-da-shou-du-de-zui-shao-you-hao-2023-12-05","date":"2023-12-05T02:03:09.000Z","updated":"2023-12-07T01:05:51.468Z","comments":true,"path":"/post/2477-dao-da-shou-du-de-zui-shao-you-hao-2023-12-05/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/minimum-fuel-cost-to-report-to-the-capital/description/\">2477. 到达首都的最少油耗</a><br><img src=\"https://img.huangge1199.cn/halo/2023-12-05.png\" alt=\"2023-12-05.png\"><br>日期2023-12-05<br>用时34 m 15 s<br>时间37ms<br>内存84.8MB<br>思路:分别计算每条路上通过的城市数量(数量/座位数,向上取整),然后求和,这里每条路上通过的城市数量实际就是图中每个节点的子节点数量。<br>代码:每条路上通过的城市数量实际就是图中每个节点的子节点数量。<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public long minimumFuelCost(int[][] roads, int seats) &#123;\n int size &#x3D; roads.length+1;\n List&lt;Integer&gt;[] list &#x3D; new ArrayList[size];\n for(int i&#x3D;0;i&lt;size;i++)&#123;\n list[i] &#x3D; new ArrayList&lt;&gt;();\n &#125;\n for(int[] road:roads)&#123;\n int num1 &#x3D; road[0];\n int num2 &#x3D; road[1];\n list[num1].add(num2);\n list[num2].add(num1);\n &#125;;\n dfs(0,-1,list,seats);\n return sum;\n &#125;\n long sum &#x3D; 0;\n private int dfs(int start,int end,List&lt;Integer&gt;[] list,int seats)&#123;\n int cnt &#x3D;1;\n for(int num: list[start])&#123;\n if(num!&#x3D;end)&#123;\n cnt+&#x3D;dfs(num,start,list,seats);\n &#125;\n &#125;\n if(start&gt;0)&#123;\n sum+&#x3D;(cnt-1)&#x2F;seats+1;\n &#125;\n return cnt;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"1038. 从二叉搜索树到更大和树2023-12-04","slug":"1038-cong-er-cha-sou-suo-shu-dao-geng-da-he-shu-2023-12-04","date":"2023-12-04T02:27:05.000Z","updated":"2023-12-07T01:02:59.188Z","comments":true,"path":"/post/1038-cong-er-cha-sou-suo-shu-dao-geng-da-he-shu-2023-12-04/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/binary-search-tree-to-greater-sum-tree/description/\">1038. 从二叉搜索树到更大和树</a></p>\n<p><img src=\"https://img.huangge1199.cn/halo/2023-12-04.png\" alt=\"2023-12-04.png\"><br>日期2023-12-04<br>用时12 m 23 s<br>时间0ms<br>内存39.39MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * Definition for a binary tree node.\n * public class TreeNode &#123;\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() &#123;&#125;\n * TreeNode(int val) &#123; this.val &#x3D; val; &#125;\n * TreeNode(int val, TreeNode left, TreeNode right) &#123;\n * this.val &#x3D; val;\n * this.left &#x3D; left;\n * this.right &#x3D; right;\n * &#125;\n * &#125;\n *&#x2F;\nclass Solution &#123;\n public TreeNode bstToGst(TreeNode root) &#123;\n dfs(root);\n return root;\n &#125;\n int sum &#x3D; 0;\n private void dfs(TreeNode node) &#123;\n if (node &#x3D;&#x3D; null) &#123;\n return;\n &#125;\n dfs(node.right);\n sum +&#x3D; node.val;\n node.val &#x3D; sum;\n dfs(node.left);\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2661. 找出叠涂元素2023-12-01","slug":"2661-zhao-chu-die-tu-yuan-su-2023-12-01","date":"2023-12-01T01:44:29.000Z","updated":"2023-12-07T01:01:34.575Z","comments":true,"path":"/post/2661-zhao-chu-die-tu-yuan-su-2023-12-01/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/first-completely-painted-row-or-column/description/\">2661. 找出叠涂元素</a></p>\n<p><img src=\"https://img.huangge1199.cn/halo/2023-12-01.png\" alt=\"2023-12-01.png\"><br>日期2023-12-01<br>用时7 m 4 s<br>时间26ms<br>内存67.45MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int firstCompleteIndex(int[] arr, int[][] mat) &#123;\n Map&lt;Integer,int[]&gt; map &#x3D; new HashMap&lt;&gt;();\n for(int i&#x3D;0;i&lt;mat.length;i++)&#123;\n for(int j&#x3D;0;j&lt;mat[0].length;j++)&#123;\n map.put(mat[i][j],new int[]&#123;i,j&#125;);\n &#125;\n &#125;\n int[] xc &#x3D; new int[mat.length];\n int[] yc &#x3D; new int[mat[0].length];\n for(int i&#x3D;0;i&lt;arr.length;i++)&#123;\n int[] tmp &#x3D; map.get(arr[i]);\n xc[tmp[0]]++;\n yc[tmp[1]]++;\n if(xc[tmp[0]]&#x3D;&#x3D;mat[0].length||yc[tmp[1]]&#x3D;&#x3D;mat.length)&#123;\n return i;\n &#125;\n &#125;\n return 0;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"1657. 确定两个字符串是否接近2023-11-30","slug":"1657-que-ding-liang-ge-zi-fu-chuan-shi-fou-jie-jin-2023-11-30","date":"2023-11-30T02:33:56.000Z","updated":"2023-12-07T00:59:51.192Z","comments":true,"path":"/post/1657-que-ding-liang-ge-zi-fu-chuan-shi-fou-jie-jin-2023-11-30/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/determine-if-two-strings-are-close/description/\">1657. 确定两个字符串是否接近</a></p>\n<p><img src=\"https://img.huangge1199.cn/halo/2023-11-30.png\" alt=\"2023-11-30.png\"><br>日期2023-11-30<br>用时21 m 07 s<br>时间11ms<br>内存43.70MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean closeStrings(String word1, String word2) &#123;\n if(word1.length()!&#x3D;word2.length())&#123;\n return false;\n &#125;\n int[] arr1 &#x3D; new int[26];\n int[] arr2 &#x3D; new int[26];\n int mask1&#x3D;0;\n int mask2&#x3D;0;\n for(int i&#x3D;0;i&lt;word1.length();i++)&#123;\n arr1[word1.charAt(i)-&#39;a&#39;]++;\n arr2[word2.charAt(i)-&#39;a&#39;]++;\n mask1 |&#x3D; 1&lt;&lt;(word1.charAt(i)-&#39;a&#39;);\n mask2 |&#x3D; 1&lt;&lt;(word2.charAt(i)-&#39;a&#39;);\n &#125;\n Arrays.sort(arr1);\n Arrays.sort(arr2);\n return Arrays.equals(arr1,arr2)&amp;&amp;mask1&#x3D;&#x3D;mask2;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"2336. 无限集中的最小数字2023.11.29","slug":"2336-wu-xian-ji-zhong-de-zui-xiao-shu-zi-2023-11-29","date":"2023-11-29T01:57:56.000Z","updated":"2023-12-07T00:58:03.312Z","comments":true,"path":"/post/2336-wu-xian-ji-zhong-de-zui-xiao-shu-zi-2023-11-29/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/smallest-number-in-infinite-set/description/\">2336. 无限集中的最小数字</a><br><img src=\"https://img.huangge1199.cn/halo/2023-11-29.png\" alt=\"2023-11-29.png\"><br>日期2023-11-29<br>用时3 m 50 s<br>时间71ms<br>内存43.68MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class SmallestInfiniteSet &#123;\n\n List&lt;Integer&gt; list;\n\n public SmallestInfiniteSet() &#123;\n list &#x3D; new ArrayList&lt;&gt;();\n for(int i&#x3D;1;i&lt;1001;i++)&#123;\n list.add(i);\n &#125;\n Collections.sort(list);\n &#125;\n \n public int popSmallest() &#123;\n int num &#x3D; list.get(0);\n list.remove(0);\n return num;\n &#125;\n \n public void addBack(int num) &#123;\n if(!list.contains(num))&#123;\n list.add(num);\n Collections.sort(list);\n &#125;\n &#125;\n&#125;\n\n&#x2F;**\n * Your SmallestInfiniteSet object will be instantiated and called as such:\n * SmallestInfiniteSet obj &#x3D; new SmallestInfiniteSet();\n * int param_1 &#x3D; obj.popSmallest();\n * obj.addBack(num);\n *&#x2F;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"1670. 设计前中后队列2023.11.28","slug":"1670-she-ji-qian-zhong-hou-dui-lie-2023-11-28","date":"2023-11-28T07:56:04.000Z","updated":"2023-12-07T00:55:56.841Z","comments":true,"path":"/post/1670-she-ji-qian-zhong-hou-dui-lie-2023-11-28/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/design-front-middle-back-queue/description/\">1670. 设计前中后队列</a><br>日期2023-11-28<br>用时8 m 23 s<br>时间6ms<br>内存43.55MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class FrontMiddleBackQueue &#123;\n\n List&lt;Integer&gt; list;\n\n public FrontMiddleBackQueue() &#123;\n list &#x3D; new ArrayList&lt;&gt;();\n &#125;\n \n public void pushFront(int val) &#123;\n list.add(0,val);\n &#125;\n \n public void pushMiddle(int val) &#123;\n list.add(list.size()&#x2F;2,val);\n &#125;\n \n public void pushBack(int val) &#123;\n list.add(val);\n &#125;\n \n public int popFront() &#123;\n if(list.size()&#x3D;&#x3D;0)&#123;\n return -1;\n &#125;\n int res &#x3D; list.get(0);\n list.remove(0);\n return res;\n &#125;\n \n public int popMiddle() &#123;\n if(list.size()&#x3D;&#x3D;0)&#123;\n return -1;\n &#125;\n int res &#x3D; list.get((list.size()-1)&#x2F;2);\n list.remove((list.size()-1)&#x2F;2);\n return res;\n &#125;\n \n public int popBack() &#123;\n if(list.size()&#x3D;&#x3D;0)&#123;\n return -1;\n &#125;\n int res &#x3D; list.get(list.size()-1);\n list.remove(list.size()-1);\n return res;\n &#125;\n&#125;\n\n&#x2F;**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj &#x3D; new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 &#x3D; obj.popFront();\n * int param_5 &#x3D; obj.popMiddle();\n * int param_6 &#x3D; obj.popBack();\n *&#x2F;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"907. 子数组的最小值之和2023.11.27","slug":"907-zi-shu-zu-de-zui-xiao-zhi-zhi-he-2023-11-27","date":"2023-11-27T01:41:39.000Z","updated":"2023-12-07T00:46:34.473Z","comments":true,"path":"/post/907-zi-shu-zu-de-zui-xiao-zhi-zhi-he-2023-11-27/","link":"","excerpt":"","content":"<p>力扣每日一题<br>题目:<a href=\"https://leetcode.cn/problems/sum-of-subarray-minimums/description/\">907. 子数组的最小值之和</a><br>日期2023-11-27<br>用时14 m 14 s<br>时间19ms<br>内存47.42MB<br>代码:<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int sumSubarrayMins(int[] arr) &#123;\n int n&#x3D;arr.length;\n int res &#x3D; 0;\n int mod&#x3D;1000000007;\n Deque&lt;Integer&gt; deque&#x3D;new ArrayDeque&lt;&gt;();\n for (int i&#x3D;0; i &lt;&#x3D; n; i++) &#123;\n int cur &#x3D; i&lt;n?arr[i] : 0;\n while (!deque.isEmpty() &amp;&amp; arr[deque.peekLast()] &gt;&#x3D; cur) &#123;\n int index &#x3D; deque.pollLast();\n int l&#x3D;deque.isEmpty()?-1:deque.peekLast();\n res +&#x3D; 1L*(index-l)*(i-index)%mod*arr[index]%mod;\n res %&#x3D; mod;\n &#125;\n deque.addLast(i);\n &#125;\n return res;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"Python静态爬虫","slug":"pyStaticSpiders","date":"2023-11-01T02:19:20.000Z","updated":"2023-11-01T03:33:01.838Z","comments":true,"path":"/post/pyStaticSpiders/","link":"","excerpt":"","content":"<h1 id=\"什么是Python静态爬虫\"><a href=\"#什么是Python静态爬虫\" class=\"headerlink\" title=\"什么是Python静态爬虫\"></a>什么是Python静态爬虫</h1><p>Python静态爬虫是一种使用Python编写的网络爬虫程序用于从互联网上抓取网页内容。与动态爬虫不同静态爬虫只获取网页的HTML源代码不执行JavaScript代码。因此静态爬虫适用于那些主要通过HTML展示信息的网站。</p>\n<h2 id=\"什么是爬虫\"><a href=\"#什么是爬虫\" class=\"headerlink\" title=\"什么是爬虫\"></a>什么是爬虫</h2><p>网络爬虫又被称为网页蜘蛛、网络机器人等是一种按照一定的规则自动地抓取万维网信息的程序或者脚本。通俗的讲就是通过程序去获取web页面上自己想要的数据也就是自动抓取数据。<br>你可以将每个爬虫视作你的”分身”<br>它的基本操作就像模拟人的行为去各个网站溜达点点按钮查查数据或者把看到的信息背回来。比如搜索引擎离不开爬虫比如百度搜索引擎的爬虫叫作百度蜘蛛Baiduspider。百度蜘蛛每天会在海量的互联网信息中进行爬取爬取优质信息并收录当用户在百度搜索引擎上检索对应关键词时百度将对关键词进行分析处理从收录的网页中找出相关网页按照一定的排名规则进行排序并将结果展现给用户。</p>\n<h2 id=\"爬虫可以做什么\"><a href=\"#爬虫可以做什么\" class=\"headerlink\" title=\"爬虫可以做什么\"></a>爬虫可以做什么</h2><p>爬虫可以用于爬取图片、视频或其他任何可以通过浏览器访问的资源。通过编写爬虫程序,可以模拟浏览器向服务器发送请求,获取所需的资源,并将其保存到本地或进行进一步处理和分析。</p>\n<p>对于图片,爬虫可以爬取网页上的图片链接,然后将图片下载到本地。这可以用于批量下载图片,或者从多个网站上收集特定主题的图片。</p>\n<p>对于视频爬虫可以爬取视频的URL或嵌入代码然后使用相应的工具将视频下载到本地。这可以用于下载在线视频、音乐视频或其他多媒体内容。</p>\n<p>需要注意的是,在爬取资源时需要遵守网站的使用条款和服务协议,并尊重知识产权和版权法律。此外,为了避免给目标网站造成过大的负担,建议合理设置爬取频率和并发请求数。</p>\n<h2 id=\"爬虫的本质是什么\"><a href=\"#爬虫的本质是什么\" class=\"headerlink\" title=\"爬虫的本质是什么\"></a>爬虫的本质是什么</h2><p>爬虫可以用于以下方面:</p>\n<ol>\n<li><p>数据采集:爬虫可以模拟浏览器向服务器发送请求,获取网页中的数据。通过编写爬虫程序,可以自动化地从网站上抓取所需的数据,如商品信息、新闻内容、评论等。</p>\n</li>\n<li><p>搜索引擎:爬虫是搜索引擎的重要组成部分。搜索引擎通过爬取互联网上的网页,建立索引库,并根据用户的搜索请求返回相关的搜索结果。</p>\n</li>\n<li><p>数据分析:爬虫可以从各种网站上抓取大量的数据,然后对这些数据进行分析和处理。通过对数据的挖掘和分析,可以发现有价值的信息和趋势,为决策提供支持。</p>\n</li>\n<li><p>价格比较:爬虫可以定期爬取不同电商平台上的商品信息,包括价格、评论等。通过对这些数据的分析,可以帮助用户找到最优惠的购物选择。</p>\n</li>\n<li><p>舆情监测:爬虫可以定期爬取社交媒体、新闻网站等平台上的评论和帖子,对其中的内容进行情感分析和主题分类。这可以帮助企业了解公众对其产品或品牌的看法,及时调整营销策略。</p>\n</li>\n</ol>\n<p>总之,爬虫的本质是通过模拟浏览器自动向服务器发送请求,获取、处理并解析结果的自动化程序。它可以用于数据采集、搜索引擎、数据分析、价格比较和舆情监测等多个领域。</p>\n<h1 id=\"Python静态爬虫的实现方法\"><a href=\"#Python静态爬虫的实现方法\" class=\"headerlink\" title=\"Python静态爬虫的实现方法\"></a>Python静态爬虫的实现方法</h1><ol>\n<li><p>发送HTTP请求静态爬虫首先向目标网站发送一个HTTP请求以获取网页的HTML源代码。</p>\n</li>\n<li><p>解析HTML静态爬虫使用HTML解析器如BeautifulSoup、lxml等对获取到的HTML源代码进行解析提取出所需的信息。</p>\n</li>\n<li><p>存储数据:静态爬虫将提取到的数据存储在本地文件或数据库中,以便后续处理和分析。</p>\n</li>\n<li><p>重复执行:静态爬虫可以设置定时任务,定期执行上述操作,以持续抓取网页内容。</p>\n</li>\n</ol>\n<h1 id=\"Python静态爬虫常用库\"><a href=\"#Python静态爬虫常用库\" class=\"headerlink\" title=\"Python静态爬虫常用库\"></a>Python静态爬虫常用库</h1><h2 id=\"requests\"><a href=\"#requests\" class=\"headerlink\" title=\"requests\"></a>requests</h2><h3 id=\"介绍\"><a href=\"#介绍\" class=\"headerlink\" title=\"介绍\"></a>介绍</h3><p>Requests 是一个 Python 第三方库,用于发送 HTTP/1.1 请求。它继承了 urllib2 的所有特性,并提供了更加简洁、友好的 API。以下是 Requests 的一些主要特性:</p>\n<ol>\n<li><p>支持 HTTP连接保持和连接池。 </p>\n</li>\n<li><p>支持使用 cookie 保持会话。 </p>\n</li>\n<li><p>支持文件上传。 </p>\n</li>\n<li><p>自动确定响应内容的编码。 </p>\n</li>\n<li><p>支持国际化的 URL 和 POST 数据自动编码。</p>\n</li>\n</ol>\n<h3 id=\"安装\"><a href=\"#安装\" class=\"headerlink\" title=\"安装\"></a>安装</h3><p>要使用 Requests 库,首先需要安装。可以通过以下命令安装:<br><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">pip install requests\n# 或者\npip3 install requests</code></pre></p>\n<h3 id=\"\"><a href=\"#\" class=\"headerlink\" title=\" \"></a> </h3><h2 id=\"BeautifulSoup\"><a href=\"#BeautifulSoup\" class=\"headerlink\" title=\"BeautifulSoup\"></a>BeautifulSoup</h2><p>一个用于解析HTML和XML文档的库可以方便地提取所需信息。</p>\n<h2 id=\"lxml\"><a href=\"#lxml\" class=\"headerlink\" title=\"lxml\"></a>lxml</h2><p>一个高性能的Python库用于处理XML和HTML文档。</p>\n<h2 id=\"re\"><a href=\"#re\" class=\"headerlink\" title=\"re\"></a>re</h2><p>Python内置的正则表达式库用于匹配和提取文本中的特定模式。</p>\n<h2 id=\"pymongo\"><a href=\"#pymongo\" class=\"headerlink\" title=\"pymongo\"></a>pymongo</h2><p>pymongo是Python中用来操作MongoDB的一个库。</p>\n<h2 id=\"mongoengine\"><a href=\"#mongoengine\" class=\"headerlink\" title=\"mongoengine\"></a>mongoengine</h2><p>MongoEngine是一个专为Python设计的库用于操作MongoDB数据库。</p>\n<h2 id=\"redis\"><a href=\"#redis\" class=\"headerlink\" title=\"redis\"></a>redis</h2><h2 id=\"pymysql\"><a href=\"#pymysql\" class=\"headerlink\" title=\"pymysql\"></a>pymysql</h2><h1 id=\"总结\"><a href=\"#总结\" class=\"headerlink\" title=\"总结\"></a>总结</h1><p>Python静态爬虫是一种简单易用的网络爬虫技术可以帮助我们快速地从互联网上抓取网页内容。通过学习Python静态爬虫的基本概念、实现方法和常用库初学者可以轻松入门Python静态爬虫为进一步深入学习网络爬虫打下坚实的基础。</p>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"Windows系统下设置程序开机自启WinSW","slug":"windowsxi-tong-xia-she-zhi-cheng-xu-kai-ji-zi-qi-winsw","date":"2023-10-17T09:54:01.000Z","updated":"2023-12-07T00:41:28.139Z","comments":true,"path":"/post/windowsxi-tong-xia-she-zhi-cheng-xu-kai-ji-zi-qi-winsw/","link":"","excerpt":"","content":"<h1 id=\"介绍\"><a href=\"#介绍\" class=\"headerlink\" title=\"介绍\"></a>介绍</h1><p>WinSW可以将Windows上的任何程序作为系统服务进行管理已达到开机自启的效果。</p>\n<h1 id=\"支持的平台\"><a href=\"#支持的平台\" class=\"headerlink\" title=\"支持的平台\"></a>支持的平台</h1><p>WinSW需要运行在拥有.NET Framework 4.6.1或者更新版本的Windows平台下</p>\n<h1 id=\"下载\"><a href=\"#下载\" class=\"headerlink\" title=\"下载\"></a>下载</h1><ul>\n<li><p>github <a href=\"https://github.com/winsw/winsw/releases\">下载地址</a></p>\n</li>\n<li><p>百度网盘v2.12.0<a href=\"https://pan.baidu.com/s/1mCdn2cLyKkA6BSuYtvA-1A?pwd=ktt7\">WinSW-x86</a> <a href=\"https://pan.baidu.com/s/1suXVU4I7v3mHApy5UQSO9g?pwd=f3i1\">WinSW-x64</a></p>\n</li>\n</ul>\n<h1 id=\"使用说明\"><a href=\"#使用说明\" class=\"headerlink\" title=\"使用说明\"></a>使用说明</h1><h2 id=\"全局应用\"><a href=\"#全局应用\" class=\"headerlink\" title=\"全局应用\"></a>全局应用</h2><ol>\n<li>获取<code>WinSW.exe</code>文件</li>\n<li>编写<em>myapp.xml</em>文件(详细内容看<a href=\"# XML配置文件\">XML配置文件</a></li>\n<li>运行<code>winsw install myapp.xml [options]</code>安装服务,使其写入系统服务中</li>\n<li>运行<code>winsw start myapp.xml</code> 开启服务</li>\n<li>运行<code>winsw status myapp.xml</code> 查看服务的运行状态</li>\n</ol>\n<h2 id=\"单一应用\"><a href=\"#单一应用\" class=\"headerlink\" title=\"单一应用\"></a>单一应用</h2><ol>\n<li>获取<code>WinSW.exe</code>文件并将其更名为你的服务名(例如<em>myapp.exe</em>).</li>\n<li>编写<em>myapp.xml</em>文件</li>\n<li>请确保前面两个文件在同一目录</li>\n<li>运行<code>myapp.exe install [options]</code>安装服务,使其写入系统服务中</li>\n<li>运行<code>myapp.exe start</code>开启服务</li>\n<li>运行<code>myapp status myapp.xml</code> 查看服务的运行状态</li>\n</ol>\n<h1 id=\"命令\"><a href=\"#命令\" class=\"headerlink\" title=\"命令\"></a>命令</h1><p>除了使用说明中的<code>install</code>、<code>start</code>、<code>status</code>三个命令外WinSW还提供了其他的命令具体命令及说明如下</p>\n<ul>\n<li><p>install安装服务</p>\n</li>\n<li><p>uninstall卸载服务</p>\n</li>\n<li><p>start启动服务</p>\n</li>\n<li><p>stop停止服务</p>\n</li>\n<li><p>restart重启服务</p>\n</li>\n<li><p>status检查服务状态</p>\n</li>\n<li><p>refresh刷新服务属性</p>\n</li>\n<li><p>customize自定义包装器可执行文件</p>\n</li>\n<li><p>dev扩展命令具体看下方</p>\n</li>\n</ul>\n<p>扩展命令:</p>\n<ul>\n<li><p>dev ps绘制与服务相关的进程树</p>\n</li>\n<li><p>dev kill如果服务停止响应则终止该服务</p>\n</li>\n<li><p>dev list列出当前可执行文件管理的服务</p>\n</li>\n</ul>\n<h1 id=\"XML配置文件\"><a href=\"#XML配置文件\" class=\"headerlink\" title=\"XML配置文件\"></a>XML配置文件</h1><h2 id=\"文件结构\"><a href=\"#文件结构\" class=\"headerlink\" title=\"文件结构\"></a>文件结构</h2><p>xml文件的根元素必须是 <code>&lt;service&gt;</code>, 并支持以下的子元素</p>\n<p>例子:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;service&gt;\n &lt;id&gt;jenkins&lt;&#x2F;id&gt;\n &lt;name&gt;Jenkins&lt;&#x2F;name&gt;\n &lt;description&gt;This service runs Jenkins continuous integration system.&lt;&#x2F;description&gt;\n &lt;env name&#x3D;&quot;JENKINS_HOME&quot; value&#x3D;&quot;%BASE%&quot;&#x2F;&gt;\n &lt;executable&gt;java&lt;&#x2F;executable&gt;\n &lt;arguments&gt;-Xrs -Xmx256m -jar &quot;%BASE%\\jenkins.war&quot; --httpPort&#x3D;8080&lt;&#x2F;arguments&gt;\n &lt;log mode&#x3D;&quot;roll&quot;&gt;&lt;&#x2F;log&gt;\n&lt;&#x2F;service&gt;</code></pre>\n<h2 id=\"环境变量扩展\"><a href=\"#环境变量扩展\" class=\"headerlink\" title=\"环境变量扩展\"></a>环境变量扩展</h2><p>配置 XML 文件可以包含 %Name% 形式的环境变量扩展。如果发现这种情况,将自动用变量的实际值替换。如果引用了未定义的环境变量,则不会进行替换。</p>\n<p>此外,服务包装器还会自行设置环境变量 BASE该变量指向包含重命名后的 WinSW.exe 的目录。这对引用同一目录中的其他文件非常有用。由于这本身就是一个环境变量,因此也可以从服务包装器启动的子进程中访问该值。</p>\n<h2 id=\"配置条目\"><a href=\"#配置条目\" class=\"headerlink\" title=\"配置条目\"></a>配置条目</h2><h3 id=\"id\"><a href=\"#id\" class=\"headerlink\" title=\"id\"></a>id</h3><p>必填 指定 Windows 内部用于标识服务的 ID。在系统中安装的所有服务中该 ID 必须是唯一的,且应完全由字母数字字符组成。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;id&gt;jenkins&lt;&#x2F;id&gt;</code></pre>\n<h3 id=\"executable\"><a href=\"#executable\" class=\"headerlink\" title=\"executable\"></a>executable</h3><p>必填 该元素指定要启动的可执行文件。它可以是绝对路径,也可以直接指定可执行文件的名称,然后从 PATH 中搜索(但要注意的是,服务通常以不同的用户账户运行,因此它的 PATH 可能与 shell 不同)。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;executable&gt;java&lt;&#x2F;executable&gt;</code></pre>\n<h3 id=\"name\"><a href=\"#name\" class=\"headerlink\" title=\"name\"></a>name</h3><p>可选项 服务的简短显示名称,可以包含空格和其他字符。该名称不能太长,如 <id>,而且在给定系统的所有服务中也必须是唯一的。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;name&gt;Jenkins&lt;&#x2F;name&gt;</code></pre>\n<h3 id=\"description\"><a href=\"#description\" class=\"headerlink\" title=\"description\"></a>description</h3><p>可选 对服务的长篇可读描述。当服务被选中时,它会显示在 Windows 服务管理器中。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;description&gt;This service runs Jenkins continuous integration system.&lt;&#x2F;description&gt;</code></pre>\n<h3 id=\"startmode\"><a href=\"#startmode\" class=\"headerlink\" title=\"startmode\"></a>startmode</h3><p>可选 此元素指定 Windows 服务的启动模式。可以是以下值之一:自动或手动。有关详细信息,请参阅 <a href=\"[Win32_Service 类的 ChangeStartMode 方法 (CIMWin32 WMI 提供程序\">ChangeStartMode</a> - Win32 apps | Microsoft Learn](<a href=\"https://learn.microsoft.com/zh-cn/windows/win32/cimwin32prov/changestartmode-method-in-class-win32-service\">https://learn.microsoft.com/zh-cn/windows/win32/cimwin32prov/changestartmode-method-in-class-win32-service</a>)) 方法。默认值为自动<code>Automatic</code>。</p>\n<h3 id=\"delayedAutoStart\"><a href=\"#delayedAutoStart\" class=\"headerlink\" title=\"delayedAutoStart\"></a>delayedAutoStart</h3><p>可选 如果定义了<code>Automatic</code>模式,此布尔选项将启用延迟启动模式。更多信息,请参阅<a href=\"https://techcommunity.microsoft.com/t5/ask-the-performance-team/ws2008-startup-processes-and-delayed-automatic-start/ba-p/372692\">Startup Processes and Delayed Automatic Start</a>。</p>\n<p>请注意,该启动模式不适用于 Windows 7 和 Windows Server 2008 以上的旧版本。在这种情况下Windows 服务安装可能会失败。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;delayedAutoStart&gt;true&lt;&#x2F;delayedAutoStart&gt;</code></pre>\n<h3 id=\"depend\"><a href=\"#depend\" class=\"headerlink\" title=\"depend\"></a>depend</h3><p>可选 指定此服务依赖的其他服务的 ID。当服务 X 依赖于服务 Y 时X 只能在 Y 运行时运行。</p>\n<p>可使用多个元素指定多个依赖关系。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;depend&gt;Eventlog&lt;&#x2F;depend&gt;\n&lt;depend&gt;W32Time&lt;&#x2F;depend&gt;</code></pre>\n<h3 id=\"log\"><a href=\"#log\" class=\"headerlink\" title=\"log\"></a>log</h3><p>可选 用 <logpath> 和启动模式设置不同的日志目录append默认、reset清除日志、ignore忽略、roll移动到 *.old。</p>\n<p>更多信息,请参阅<a href=\"https://github.com/winsw/winsw/blob/v3/docs/logging-and-error-reporting.md\">Logging and error reporting</a>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;log mode&#x3D;&quot;roll&quot;&gt;&lt;&#x2F;log&gt;</code></pre>\n<h3 id=\"arguments\"><a href=\"#arguments\" class=\"headerlink\" title=\"arguments\"></a>arguments</h3><p>可选 <arguments> 元素指定要传递给可执行文件的参数。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;arguments&gt;arg1 arg2 arg3&lt;&#x2F;arguments&gt;</code></pre>\n<p>或者</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;arguments&gt;\n arg1\n arg2\n arg3\n&lt;&#x2F;arguments&gt;</code></pre>\n<h3 id=\"stopargument-stopexecutable\"><a href=\"#stopargument-stopexecutable\" class=\"headerlink\" title=\"stopargument/stopexecutable\"></a>stopargument/stopexecutable</h3><p>可选 当服务被请求停止时winsw 会简单地调用 <a href=\"https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess\">TerminateProcess function</a>立即杀死服务。但是,如果存在 <stoparguments> 元素winsw 将使用指定的参数启动另一个 <executable> 进程(或 <stopopexecutable>,如果已指定),并期望该进程启动服务进程的优雅关闭。 </p>\n<p>然后Winsw 将等待这两个进程自行退出,然后向 Windows 报告服务已终止。 </p>\n<p>使用 <stoparguments> 时,必须使用 <startarguments> 而不是 <arguments>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;executable&gt;catalina.sh&lt;&#x2F;executable&gt;\n&lt;startarguments&gt;jpda run&lt;&#x2F;startarguments&gt;\n\n&lt;stopexecutable&gt;catalina.sh&lt;&#x2F;stopexecutable&gt;\n&lt;stoparguments&gt;stop&lt;&#x2F;stoparguments&gt;</code></pre>\n<h3 id=\"Additional-commands\"><a href=\"#Additional-commands\" class=\"headerlink\" title=\"Additional commands\"></a>Additional commands</h3><p>扩展命令包括<code>prestart</code>,<code>poststart</code>,<code>prestop</code>,<code>poststop</code>四个,以<code>prestart</code>为例写法如下:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;prestart&gt;\n &lt;executable&gt;&lt;&#x2F;executable&gt;\n &lt;arguments&gt;&lt;&#x2F;arguments&gt;\n &lt;stdoutPath&gt;&lt;&#x2F;stdoutPath&gt;\n &lt;stderrPath&gt;&lt;&#x2F;stderrPath&gt;\n&lt;&#x2F;prestart&gt;</code></pre>\n<ul>\n<li><p>prestart在服务启动时、主进程启动前执行</p>\n</li>\n<li><p>poststart在服务启动时和主程序启动后执行</p>\n</li>\n<li><p>prestop在服务停止时、主进程停止前执行</p>\n</li>\n<li><p>poststop在服务停止时和主进程停止后执行</p>\n</li>\n</ul>\n<p>共用的命令如下:</p>\n<ul>\n<li><p>stdoutPath指定将标准输出重定向到的路径</p>\n</li>\n<li><p>stderrPath指定将标准错误输出重定向到的路径</p>\n</li>\n</ul>\n<p>在 stdoutPath 或 stderrPath 中指定 NUL 可处理相应的数据流</p>\n<h3 id=\"preshutdown\"><a href=\"#preshutdown\" class=\"headerlink\" title=\"preshutdown\"></a>preshutdown</h3><p>当系统关闭时,让服务有更多时间停止。</p>\n<p>系统默认的预关机超时时间为三分钟。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;preshutdown&gt;false&lt;&#x2F;preshutdown&gt;\n&lt;preshutdownTimeout&gt;3 min&lt;&#x2F;preshutdown&gt;</code></pre>\n<h3 id=\"stoptimeout\"><a href=\"#stoptimeout\" class=\"headerlink\" title=\"stoptimeout\"></a>stoptimeout</h3><p>当服务被请求停止时winsw 会首先尝试向控制台应用程序发送 Ctrl+C 信号,或向 Windows 应用程序发布关闭消息,然后等待长达 15 秒的时间让进程自己优雅地退出。如果超时或无法发送信号或消息winsw 就会立即终止服务。 </p>\n<p>通过这个可选元素,您可以更改 “15 秒 “的值,这样就可以控制 winsw 让服务自行关闭的时间。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;stoptimeout&gt;10sec&lt;&#x2F;stoptimeout&gt;</code></pre>\n<h3 id=\"Environment\"><a href=\"#Environment\" class=\"headerlink\" title=\"Environment\"></a>Environment</h3><p>如有必要,可多次指定该可选元素,以指定要为子进程设置的环境变量。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;env name&#x3D;&quot;HOME&quot; value&#x3D;&quot;c:\\abc&quot; &#x2F;&gt;</code></pre>\n<h3 id=\"interactive\"><a href=\"#interactive\" class=\"headerlink\" title=\"interactive\"></a>interactive</h3><p>如果指定了此可选元素,则允许服务与桌面交互,如显示新窗口和对话框。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;interactive&gt;true&lt;&#x2F;interactive&gt;</code></pre>\n<p>请注意,自引入 UACWindows Vista 及以后版本)以来,服务已不再真正允许与桌面交互。在这些操作系统中,这样做的目的只是让用户切换到一个单独的窗口站来与服务交互。</p>\n<h3 id=\"beeponshutdown\"><a href=\"#beeponshutdown\" class=\"headerlink\" title=\"beeponshutdown\"></a>beeponshutdown</h3><p>该可选元素用于在服务关闭时发出<a href=\"https://docs.microsoft.com/windows/win32/api/utilapiset/nf-utilapiset-beep\">simple tones</a>。此功能只能用于调试,因为某些操作系统和硬件不支持此功能。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;beeponshutdown&gt;true&lt;&#x2F;beeponshutdown&gt;</code></pre>\n<h3 id=\"download\"><a href=\"#download\" class=\"headerlink\" title=\"download\"></a>download</h3><p>可以多次指定这个可选元素,以便让服务包装器从 URL 获取资源并将其作为文件放到本地。此操作在服务启动时,即 <code>&lt;executable&gt;</code> 指定的应用程序启动前运行。</p>\n<p>对于需要身份验证的服务器,必须根据身份验证类型指定一些参数。只有基本身份验证需要额外的子参数。支持的身份验证类型有</p>\n<ul>\n<li><p>none默认值不得指定</p>\n</li>\n<li><p>sspiWindows <a href=\"https://docs.microsoft.com/windows/win32/secauthn/sspi\">Security Support Provider Interface</a>,包括 Kerberos、NTLM 等。</p>\n</li>\n<li><p>basic基本身份验证子参数</p>\n<ul>\n<li><p>user=”UserName” 用户名</p>\n</li>\n<li><p>password=”Passw0rd”</p>\n</li>\n<li><p>unsecureAuth=”true”: 默认值=”false”</p>\n</li>\n</ul>\n</li>\n</ul>\n<p>参数 unsecureAuth 仅在传输协议为 HTTP未加密数据传输时有效。这是一个安全漏洞因为凭据是以明文发送的对于 SSPI 身份验证来说,这并不重要,因为身份验证令牌是加密的。</p>\n<p>对于使用 HTTPS 传输协议的目标服务器来说,颁发服务器证书的 CA 必须得到客户端的信任。当服务器位于互联网上时,通常会出现这种情况。当一个组织在内部网中使用自行签发的 CA 时,情况可能并非如此。在这种情况下,有必要将 CA 导入 Windows 客户端的证书 MMC。请参阅 “<a href=\"https://docs.microsoft.com/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc754841(v=ws.11\">Manage Trusted Root Certificates</a>)”中的说明。必须将自行签发的 CA 导入计算机的可信根证书颁发机构。</p>\n<p>默认情况下,如果操作失败(如从不可用),下载命令不会导致服务启动失败。为了在这种情况下强制下载失败,可以指定 failOnError 布尔属性。</p>\n<p>要指定自定义代理,请使用参数 proxy格式如下</p>\n<ul>\n<li><p>有凭据:<a href=\"http://USERNAME:PASSWORD@HOST:PORT/。\">http://USERNAME:PASSWORD@HOST:PORT/。</a></p>\n</li>\n<li><p>无凭据: <a href=\"http://HOST:PORT/。\">http://HOST:PORT/。</a></p>\n</li>\n</ul>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; failOnError&#x3D;&quot;true&quot;&#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; proxy&#x3D;&quot;http:&#x2F;&#x2F;192.168.1.5:80&#x2F;&quot;&#x2F;&gt;\n\n&lt;download from&#x3D;&quot;https:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; auth&#x3D;&quot;sspi&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;https:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; failOnError&#x3D;&quot;true&quot;\n auth&#x3D;&quot;basic&quot; user&#x3D;&quot;aUser&quot; password&#x3D;&quot;aPassw0rd&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot;\n proxy&#x3D;&quot;http:&#x2F;&#x2F;aUser:aPassw0rd@192.168.1.5:80&#x2F;&quot;\n auth&#x3D;&quot;basic&quot; unsecureAuth&#x3D;&quot;true&quot;\n user&#x3D;&quot;aUser&quot; password&#x3D;&quot;aPassw0rd&quot; &#x2F;&gt;</code></pre>\n<p>这是开发自我更新服务的另一个有用的组成部分。</p>\n<p>自 2.7 版起如果目标文件存在WinSW 将在 If-Modified-Since 标头中发送其最后写入时间,如果收到 304 Not Modified则跳过下载。</p>\n<h3 id=\"onfailure\"><a href=\"#onfailure\" class=\"headerlink\" title=\"onfailure\"></a>onfailure</h3><p>当 winsw 启动的进程失败(即以非零退出代码退出)时,这个可选的可重复元素将控制其行为。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;onfailure action&#x3D;&quot;restart&quot; delay&#x3D;&quot;10 sec&quot;&#x2F;&gt;\n&lt;onfailure action&#x3D;&quot;restart&quot; delay&#x3D;&quot;20 sec&quot;&#x2F;&gt;\n&lt;onfailure action&#x3D;&quot;reboot&quot; &#x2F;&gt;</code></pre>\n<p>例如,上述配置会导致服务在第一次故障后 10 秒内重新启动,在第二次故障后 20 秒内重新启动然后如果服务再次发生故障Windows 将重新启动。</p>\n<p>每个元素都包含一个强制的 action 属性和可选的 delay 属性,前者用于控制 Windows SCM 将采取的行动后者用于控制采取该行动前的延迟时间。action 的合法值为</p>\n<ul>\n<li><p>restart重新启动服务</p>\n</li>\n<li><p>reboot重新启动 Windows。将显示带有 <a href=\"https://docs.microsoft.com/windows-hardware/drivers/debugger/bug-check-0xef--critical-process-died\">CRITICAL_PROCESS_DIED</a> 错误检查代码的蓝色屏幕</p>\n</li>\n<li><p>none不执行任何操作让服务停止延迟属性的可能后缀为秒/秒/分钟/分钟/小时/小时/天/天。如果缺少,延迟属性默认为 0。</p>\n</li>\n</ul>\n<p>延迟属性的后缀可能是秒/秒/分/分/小时/小时/天/天。如果缺少,延迟属性默认为 0。</p>\n<p>如果服务不断发生故障,并且超过了配置的 <code>&lt;onfailure&gt;</code>次数,则会重复上次的操作。因此,如果只想始终自动重启服务,只需像这样指定一个 <code>&lt;onfailure&gt;</code> 元素即可:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;onfailure action&#x3D;&quot;restart&quot; &#x2F;&gt;</code></pre>\n<h3 id=\"resetfailure\"><a href=\"#resetfailure\" class=\"headerlink\" title=\"resetfailure\"></a>resetfailure</h3><p>此可选元素控制 Windows SCM 重置故障计数的时间。例如,如果您指定 <resetfailure>1 小时</resetfailure>,而服务持续运行的时间超过一小时,那么故障计数将重置为零。</p>\n<p>换句话说,这是您认为服务成功运行的持续时间。默认为 1 天。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;resetfailure&gt;1 hour&lt;&#x2F;resetfailure&gt;</code></pre>\n<h3 id=\"Security-descriptor\"><a href=\"#Security-descriptor\" class=\"headerlink\" title=\"Security descriptor\"></a>Security descriptor</h3><p>SDDL 格式的服务安全描述符字符串。</p>\n<p>有关详细信息,请参阅<a href=\"https://learn.microsoft.com/zh-cn/windows/win32/secauthz/security-descriptor-definition-language\">安全描述符定义语言</a>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;securityDescriptor&gt;&lt;&#x2F;securityDescriptor&gt;</code></pre>\n<h3 id=\"Service-account\"><a href=\"#Service-account\" class=\"headerlink\" title=\"Service account\"></a>Service account</h3><p>服务默认安装为 <a href=\"https://docs.microsoft.com/windows/win32/services/localsystem-account\">LocalSystem 账户</a>。如果您的服务不需要很高的权限级别,可以考虑使用 <a href=\"https://docs.microsoft.com/windows/win32/services/localservice-account\">LocalService 账户</a>、<a href=\"https://docs.microsoft.com/windows/win32/services/networkservice-account\">NetworkService 帐户</a>或用户账户。</p>\n<p>要使用用户账户,请像这样指定 <code>&lt;serviceaccount&gt;</code> 元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;DomainName\\UserName&lt;&#x2F;username&gt;\n &lt;password&gt;Pa55w0rd&lt;&#x2F;password&gt;\n &lt;allowservicelogon&gt;true&lt;&#x2F;allowservicelogon&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p><code>&lt;username&gt;</code>的格式为 DomainName\\UserName 或 UserName@DomainName。如果账户属于内置域则可以指定 .\\UserName。</p>\n<p><code>&lt;allowservicelogon&gt;</code> 是可选项。如果设置为 true将自动为列出的账户设置 “允许以服务身份登录 “的权限。</p>\n<p>要使用<a href=\"https://docs.microsoft.com/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview\">Group Managed Service Accounts Overview</a>,请在账户名后追加 $ 并删除 <code>&lt;password&gt;</code> 元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;DomainName\\GmsaUserName$&lt;&#x2F;username&gt;\n &lt;allowservicelogon&gt;true&lt;&#x2F;allowservicelogon&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<h4 id=\"LocalSystem-account\"><a href=\"#LocalSystem-account\" class=\"headerlink\" title=\"LocalSystem account\"></a>LocalSystem account</h4><p>要明确使用<a href=\"https://docs.microsoft.com/windows/win32/services/localsystem-account\">LocalSystem 帐户</a> ,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;LocalSystem&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"LocalService-account\"><a href=\"#LocalService-account\" class=\"headerlink\" title=\"LocalService account\"></a>LocalService account</h4><p>要使用 <a href=\"https://docs.microsoft.com/windows/win32/services/localservice-account\">LocalService 帐户</a>,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;NT AUTHORITY\\LocalService&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"NetworkService-account\"><a href=\"#NetworkService-account\" class=\"headerlink\" title=\"NetworkService account\"></a>NetworkService account</h4><p>要使用 <a href=\"https://docs.microsoft.com/windows/win32/services/networkservice-account\">NetworkService 帐户</a>,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;NT AUTHORITY\\NetworkService&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"prompt\"><a href=\"#prompt\" class=\"headerlink\" title=\"prompt\"></a>prompt</h4><p>可选。提示输入用户名和密码。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;prompt&gt;dialog|console&lt;&#x2F;prompt&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<ul>\n<li><p>话框:使用对话框进行提示。</p>\n</li>\n<li><p>控制台:在控制台进行提示。</p>\n</li>\n</ul>\n<h3 id=\"Working-directory\"><a href=\"#Working-directory\" class=\"headerlink\" title=\"Working directory\"></a>Working directory</h3><p>某些服务在运行时需要指定工作目录。为此,请像这样指定<code>&lt;workingdirectory&gt;</code>元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;workingdirectory&gt;C:\\application&lt;&#x2F;workingdirectory&gt;</code></pre>\n<h3 id=\"Priority\"><a href=\"#Priority\" class=\"headerlink\" title=\"Priority\"></a>Priority</h3><p>可选择指定服务进程的调度优先级(相当于 Unix nice可选值包括<code>idle</code>, <code>belownormal</code>, <code>normal</code>, <code>abovenormal</code>, <code>high</code>, <code>realtime</code>(不区分大小写)。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;priority&gt;idle&lt;&#x2F;priority&gt;</code></pre>\n<p>指定高于正常值的优先级会产生意想不到的后果。有关详细信息,请参阅 .NET 文档中的 <a href=\"https://docs.microsoft.com/dotnet/api/system.diagnostics.processpriorityclass\">ProcessPriorityClass 枚举</a>。此功能的主要目的是以较低的优先级启动进程,以免干扰计算机的交互式使用。</p>\n<h3 id=\"Auto-refresh\"><a href=\"#Auto-refresh\" class=\"headerlink\" title=\"Auto refresh\"></a>Auto refresh</h3><pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;autoRefresh&gt;true&lt;&#x2F;autoRefresh&gt;</code></pre>\n<p>当服务启动或执行以下命令时,自动刷新服务属性:</p>\n<ul>\n<li>start</li>\n<li>stop</li>\n<li>restart</li>\n</ul>\n<p>默认值为 true。</p>\n<h3 id=\"sharedDirectoryMapping\"><a href=\"#sharedDirectoryMapping\" class=\"headerlink\" title=\"sharedDirectoryMapping\"></a>sharedDirectoryMapping</h3><p>默认情况下,即使在 Windows 服务配置文件中进行了配置Windows 也不会为服务建立共享驱动器映射。由于域策略的原因,有时无法解决这个问题。</p>\n<p>这样就可以在启动可执行文件之前映射外部共享目录。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;sharedDirectoryMapping&gt;\n &lt;map label&#x3D;&quot;N:&quot; uncpath&#x3D;&quot;\\\\UNC&quot; &#x2F;&gt;\n &lt;map label&#x3D;&quot;M:&quot; uncpath&#x3D;&quot;\\\\UNC2&quot; &#x2F;&gt;\n&lt;&#x2F;sharedDirectoryMapping&gt;</code></pre>","categories":[{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/categories/%E5%B7%A5%E5%85%B7/"}],"tags":[{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/tags/%E5%B7%A5%E5%85%B7/"}]},{"title":"Windows系统下设置程序开机自启WinSW","slug":"winsw","date":"2023-10-13T00:45:13.000Z","updated":"2023-10-17T08:51:33.918Z","comments":true,"path":"/post/winsw/","link":"","excerpt":"","content":"<h1 id=\"介绍\"><a href=\"#介绍\" class=\"headerlink\" title=\"介绍\"></a>介绍</h1><p>WinSW可以将Windows上的任何程序作为系统服务进行管理已达到开机自启的效果。</p>\n<h1 id=\"支持的平台\"><a href=\"#支持的平台\" class=\"headerlink\" title=\"支持的平台\"></a>支持的平台</h1><p>WinSW需要运行在拥有.NET Framework 4.6.1或者更新版本的Windows平台下</p>\n<h1 id=\"下载\"><a href=\"#下载\" class=\"headerlink\" title=\"下载\"></a>下载</h1><ul>\n<li><p>github <a href=\"https://github.com/winsw/winsw/releases\">下载地址</a></p>\n</li>\n<li><p>百度网盘v2.12.0<a href=\"https://pan.baidu.com/s/1mCdn2cLyKkA6BSuYtvA-1A?pwd=ktt7\">WinSW-x86</a> <a href=\"https://pan.baidu.com/s/1suXVU4I7v3mHApy5UQSO9g?pwd=f3i1\">WinSW-x64</a></p>\n</li>\n</ul>\n<h1 id=\"使用说明\"><a href=\"#使用说明\" class=\"headerlink\" title=\"使用说明\"></a>使用说明</h1><h2 id=\"全局应用\"><a href=\"#全局应用\" class=\"headerlink\" title=\"全局应用\"></a>全局应用</h2><ol>\n<li>获取<code>WinSW.exe</code>文件</li>\n<li>编写<em>myapp.xml</em>文件(详细内容看<a href=\"# XML配置文件\">XML配置文件</a></li>\n<li>运行<code>winsw install myapp.xml [options]</code>安装服务,使其写入系统服务中</li>\n<li>运行<code>winsw start myapp.xml</code> 开启服务</li>\n<li>运行<code>winsw status myapp.xml</code> 查看服务的运行状态</li>\n</ol>\n<h2 id=\"单一应用\"><a href=\"#单一应用\" class=\"headerlink\" title=\"单一应用\"></a>单一应用</h2><ol>\n<li>获取<code>WinSW.exe</code>文件并将其更名为你的服务名(例如<em>myapp.exe</em>).</li>\n<li>编写<em>myapp.xml</em>文件</li>\n<li>请确保前面两个文件在同一目录</li>\n<li>运行<code>myapp.exe install [options]</code>安装服务,使其写入系统服务中</li>\n<li>运行<code>myapp.exe start</code>开启服务</li>\n<li>运行<code>myapp status myapp.xml</code> 查看服务的运行状态</li>\n</ol>\n<h1 id=\"命令\"><a href=\"#命令\" class=\"headerlink\" title=\"命令\"></a>命令</h1><p>除了使用说明中的<code>install</code>、<code>start</code>、<code>status</code>三个命令外WinSW还提供了其他的命令具体命令及说明如下</p>\n<ul>\n<li><p>install安装服务</p>\n</li>\n<li><p>uninstall卸载服务</p>\n</li>\n<li><p>start启动服务</p>\n</li>\n<li><p>stop停止服务</p>\n</li>\n<li><p>restart重启服务</p>\n</li>\n<li><p>status检查服务状态</p>\n</li>\n<li><p>refresh刷新服务属性</p>\n</li>\n<li><p>customize自定义包装器可执行文件</p>\n</li>\n<li><p>dev扩展命令具体看下方</p>\n</li>\n</ul>\n<p>扩展命令:</p>\n<ul>\n<li><p>dev ps绘制与服务相关的进程树</p>\n</li>\n<li><p>dev kill如果服务停止响应则终止该服务</p>\n</li>\n<li><p>dev list列出当前可执行文件管理的服务</p>\n</li>\n</ul>\n<h1 id=\"XML配置文件\"><a href=\"#XML配置文件\" class=\"headerlink\" title=\"XML配置文件\"></a>XML配置文件</h1><h2 id=\"文件结构\"><a href=\"#文件结构\" class=\"headerlink\" title=\"文件结构\"></a>文件结构</h2><p>xml文件的根元素必须是 <code>&lt;service&gt;</code>, 并支持以下的子元素</p>\n<p>例子:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;service&gt;\n &lt;id&gt;jenkins&lt;&#x2F;id&gt;\n &lt;name&gt;Jenkins&lt;&#x2F;name&gt;\n &lt;description&gt;This service runs Jenkins continuous integration system.&lt;&#x2F;description&gt;\n &lt;env name&#x3D;&quot;JENKINS_HOME&quot; value&#x3D;&quot;%BASE%&quot;&#x2F;&gt;\n &lt;executable&gt;java&lt;&#x2F;executable&gt;\n &lt;arguments&gt;-Xrs -Xmx256m -jar &quot;%BASE%\\jenkins.war&quot; --httpPort&#x3D;8080&lt;&#x2F;arguments&gt;\n &lt;log mode&#x3D;&quot;roll&quot;&gt;&lt;&#x2F;log&gt;\n&lt;&#x2F;service&gt;</code></pre>\n<h2 id=\"环境变量扩展\"><a href=\"#环境变量扩展\" class=\"headerlink\" title=\"环境变量扩展\"></a>环境变量扩展</h2><p>配置 XML 文件可以包含 %Name% 形式的环境变量扩展。如果发现这种情况,将自动用变量的实际值替换。如果引用了未定义的环境变量,则不会进行替换。</p>\n<p>此外,服务包装器还会自行设置环境变量 BASE该变量指向包含重命名后的 WinSW.exe 的目录。这对引用同一目录中的其他文件非常有用。由于这本身就是一个环境变量,因此也可以从服务包装器启动的子进程中访问该值。</p>\n<h2 id=\"配置条目\"><a href=\"#配置条目\" class=\"headerlink\" title=\"配置条目\"></a>配置条目</h2><h3 id=\"id\"><a href=\"#id\" class=\"headerlink\" title=\"id\"></a>id</h3><p>必填 指定 Windows 内部用于标识服务的 ID。在系统中安装的所有服务中该 ID 必须是唯一的,且应完全由字母数字字符组成。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;id&gt;jenkins&lt;&#x2F;id&gt;</code></pre>\n<h3 id=\"executable\"><a href=\"#executable\" class=\"headerlink\" title=\"executable\"></a>executable</h3><p>必填 该元素指定要启动的可执行文件。它可以是绝对路径,也可以直接指定可执行文件的名称,然后从 PATH 中搜索(但要注意的是,服务通常以不同的用户账户运行,因此它的 PATH 可能与 shell 不同)。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;executable&gt;java&lt;&#x2F;executable&gt;</code></pre>\n<h3 id=\"name\"><a href=\"#name\" class=\"headerlink\" title=\"name\"></a>name</h3><p>可选项 服务的简短显示名称,可以包含空格和其他字符。该名称不能太长,如 <id>,而且在给定系统的所有服务中也必须是唯一的。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;name&gt;Jenkins&lt;&#x2F;name&gt;</code></pre>\n<h3 id=\"description\"><a href=\"#description\" class=\"headerlink\" title=\"description\"></a>description</h3><p>可选 对服务的长篇可读描述。当服务被选中时,它会显示在 Windows 服务管理器中。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;description&gt;This service runs Jenkins continuous integration system.&lt;&#x2F;description&gt;</code></pre>\n<h3 id=\"startmode\"><a href=\"#startmode\" class=\"headerlink\" title=\"startmode\"></a>startmode</h3><p>可选 此元素指定 Windows 服务的启动模式。可以是以下值之一:自动或手动。有关详细信息,请参阅 <a href=\"[Win32_Service 类的 ChangeStartMode 方法 (CIMWin32 WMI 提供程序\">ChangeStartMode</a> - Win32 apps | Microsoft Learn](<a href=\"https://learn.microsoft.com/zh-cn/windows/win32/cimwin32prov/changestartmode-method-in-class-win32-service\">https://learn.microsoft.com/zh-cn/windows/win32/cimwin32prov/changestartmode-method-in-class-win32-service</a>)) 方法。默认值为自动<code>Automatic</code>。</p>\n<h3 id=\"delayedAutoStart\"><a href=\"#delayedAutoStart\" class=\"headerlink\" title=\"delayedAutoStart\"></a>delayedAutoStart</h3><p>可选 如果定义了<code>Automatic</code>模式,此布尔选项将启用延迟启动模式。更多信息,请参阅<a href=\"https://techcommunity.microsoft.com/t5/ask-the-performance-team/ws2008-startup-processes-and-delayed-automatic-start/ba-p/372692\">Startup Processes and Delayed Automatic Start</a>。</p>\n<p>请注意,该启动模式不适用于 Windows 7 和 Windows Server 2008 以上的旧版本。在这种情况下Windows 服务安装可能会失败。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;delayedAutoStart&gt;true&lt;&#x2F;delayedAutoStart&gt;</code></pre>\n<h3 id=\"depend\"><a href=\"#depend\" class=\"headerlink\" title=\"depend\"></a>depend</h3><p>可选 指定此服务依赖的其他服务的 ID。当服务 X 依赖于服务 Y 时X 只能在 Y 运行时运行。</p>\n<p>可使用多个元素指定多个依赖关系。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;depend&gt;Eventlog&lt;&#x2F;depend&gt;\n&lt;depend&gt;W32Time&lt;&#x2F;depend&gt;</code></pre>\n<h3 id=\"log\"><a href=\"#log\" class=\"headerlink\" title=\"log\"></a>log</h3><p>可选 用 <logpath> 和启动模式设置不同的日志目录append默认、reset清除日志、ignore忽略、roll移动到 *.old。</p>\n<p>更多信息,请参阅<a href=\"https://github.com/winsw/winsw/blob/v3/docs/logging-and-error-reporting.md\">Logging and error reporting</a>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;log mode&#x3D;&quot;roll&quot;&gt;&lt;&#x2F;log&gt;</code></pre>\n<h3 id=\"arguments\"><a href=\"#arguments\" class=\"headerlink\" title=\"arguments\"></a>arguments</h3><p>可选 <arguments> 元素指定要传递给可执行文件的参数。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;arguments&gt;arg1 arg2 arg3&lt;&#x2F;arguments&gt;</code></pre>\n<p>或者</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;arguments&gt;\n arg1\n arg2\n arg3\n&lt;&#x2F;arguments&gt;</code></pre>\n<h3 id=\"stopargument-stopexecutable\"><a href=\"#stopargument-stopexecutable\" class=\"headerlink\" title=\"stopargument/stopexecutable\"></a>stopargument/stopexecutable</h3><p>可选 当服务被请求停止时winsw 会简单地调用 <a href=\"https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess\">TerminateProcess function</a>立即杀死服务。但是,如果存在 <stoparguments> 元素winsw 将使用指定的参数启动另一个 <executable> 进程(或 <stopopexecutable>,如果已指定),并期望该进程启动服务进程的优雅关闭。 </p>\n<p>然后Winsw 将等待这两个进程自行退出,然后向 Windows 报告服务已终止。 </p>\n<p>使用 <stoparguments> 时,必须使用 <startarguments> 而不是 <arguments>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;executable&gt;catalina.sh&lt;&#x2F;executable&gt;\n&lt;startarguments&gt;jpda run&lt;&#x2F;startarguments&gt;\n\n&lt;stopexecutable&gt;catalina.sh&lt;&#x2F;stopexecutable&gt;\n&lt;stoparguments&gt;stop&lt;&#x2F;stoparguments&gt;</code></pre>\n<h3 id=\"Additional-commands\"><a href=\"#Additional-commands\" class=\"headerlink\" title=\"Additional commands\"></a>Additional commands</h3><p>扩展命令包括<code>prestart</code>,<code>poststart</code>,<code>prestop</code>,<code>poststop</code>四个,以<code>prestart</code>为例写法如下:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;prestart&gt;\n &lt;executable&gt;&lt;&#x2F;executable&gt;\n &lt;arguments&gt;&lt;&#x2F;arguments&gt;\n &lt;stdoutPath&gt;&lt;&#x2F;stdoutPath&gt;\n &lt;stderrPath&gt;&lt;&#x2F;stderrPath&gt;\n&lt;&#x2F;prestart&gt;</code></pre>\n<ul>\n<li><p>prestart在服务启动时、主进程启动前执行</p>\n</li>\n<li><p>poststart在服务启动时和主程序启动后执行</p>\n</li>\n<li><p>prestop在服务停止时、主进程停止前执行</p>\n</li>\n<li><p>poststop在服务停止时和主进程停止后执行</p>\n</li>\n</ul>\n<p>共用的命令如下:</p>\n<ul>\n<li><p>stdoutPath指定将标准输出重定向到的路径</p>\n</li>\n<li><p>stderrPath指定将标准错误输出重定向到的路径</p>\n</li>\n</ul>\n<p>在 stdoutPath 或 stderrPath 中指定 NUL 可处理相应的数据流</p>\n<h3 id=\"preshutdown\"><a href=\"#preshutdown\" class=\"headerlink\" title=\"preshutdown\"></a>preshutdown</h3><p>当系统关闭时,让服务有更多时间停止。</p>\n<p>系统默认的预关机超时时间为三分钟。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;preshutdown&gt;false&lt;&#x2F;preshutdown&gt;\n&lt;preshutdownTimeout&gt;3 min&lt;&#x2F;preshutdown&gt;</code></pre>\n<h3 id=\"stoptimeout\"><a href=\"#stoptimeout\" class=\"headerlink\" title=\"stoptimeout\"></a>stoptimeout</h3><p>当服务被请求停止时winsw 会首先尝试向控制台应用程序发送 Ctrl+C 信号,或向 Windows 应用程序发布关闭消息,然后等待长达 15 秒的时间让进程自己优雅地退出。如果超时或无法发送信号或消息winsw 就会立即终止服务。 </p>\n<p>通过这个可选元素,您可以更改 “15 秒 “的值,这样就可以控制 winsw 让服务自行关闭的时间。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;stoptimeout&gt;10sec&lt;&#x2F;stoptimeout&gt;</code></pre>\n<h3 id=\"Environment\"><a href=\"#Environment\" class=\"headerlink\" title=\"Environment\"></a>Environment</h3><p>如有必要,可多次指定该可选元素,以指定要为子进程设置的环境变量。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;env name&#x3D;&quot;HOME&quot; value&#x3D;&quot;c:\\abc&quot; &#x2F;&gt;</code></pre>\n<h3 id=\"interactive\"><a href=\"#interactive\" class=\"headerlink\" title=\"interactive\"></a>interactive</h3><p>如果指定了此可选元素,则允许服务与桌面交互,如显示新窗口和对话框。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;interactive&gt;true&lt;&#x2F;interactive&gt;</code></pre>\n<p>请注意,自引入 UACWindows Vista 及以后版本)以来,服务已不再真正允许与桌面交互。在这些操作系统中,这样做的目的只是让用户切换到一个单独的窗口站来与服务交互。</p>\n<h3 id=\"beeponshutdown\"><a href=\"#beeponshutdown\" class=\"headerlink\" title=\"beeponshutdown\"></a>beeponshutdown</h3><p>该可选元素用于在服务关闭时发出<a href=\"https://docs.microsoft.com/windows/win32/api/utilapiset/nf-utilapiset-beep\">simple tones</a>。此功能只能用于调试,因为某些操作系统和硬件不支持此功能。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;beeponshutdown&gt;true&lt;&#x2F;beeponshutdown&gt;</code></pre>\n<h3 id=\"download\"><a href=\"#download\" class=\"headerlink\" title=\"download\"></a>download</h3><p>可以多次指定这个可选元素,以便让服务包装器从 URL 获取资源并将其作为文件放到本地。此操作在服务启动时,即 <code>&lt;executable&gt;</code> 指定的应用程序启动前运行。</p>\n<p>对于需要身份验证的服务器,必须根据身份验证类型指定一些参数。只有基本身份验证需要额外的子参数。支持的身份验证类型有</p>\n<ul>\n<li><p>none默认值不得指定</p>\n</li>\n<li><p>sspiWindows <a href=\"https://docs.microsoft.com/windows/win32/secauthn/sspi\">Security Support Provider Interface</a>,包括 Kerberos、NTLM 等。</p>\n</li>\n<li><p>basic基本身份验证子参数</p>\n<ul>\n<li><p>user=”UserName” 用户名</p>\n</li>\n<li><p>password=”Passw0rd”</p>\n</li>\n<li><p>unsecureAuth=”true”: 默认值=”false”</p>\n</li>\n</ul>\n</li>\n</ul>\n<p>参数 unsecureAuth 仅在传输协议为 HTTP未加密数据传输时有效。这是一个安全漏洞因为凭据是以明文发送的对于 SSPI 身份验证来说,这并不重要,因为身份验证令牌是加密的。</p>\n<p>对于使用 HTTPS 传输协议的目标服务器来说,颁发服务器证书的 CA 必须得到客户端的信任。当服务器位于互联网上时,通常会出现这种情况。当一个组织在内部网中使用自行签发的 CA 时,情况可能并非如此。在这种情况下,有必要将 CA 导入 Windows 客户端的证书 MMC。请参阅 “<a href=\"https://docs.microsoft.com/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc754841(v=ws.11\">Manage Trusted Root Certificates</a>)”中的说明。必须将自行签发的 CA 导入计算机的可信根证书颁发机构。</p>\n<p>默认情况下,如果操作失败(如从不可用),下载命令不会导致服务启动失败。为了在这种情况下强制下载失败,可以指定 failOnError 布尔属性。</p>\n<p>要指定自定义代理,请使用参数 proxy格式如下</p>\n<ul>\n<li><p>有凭据:<a href=\"http://USERNAME:PASSWORD@HOST:PORT/。\">http://USERNAME:PASSWORD@HOST:PORT/。</a></p>\n</li>\n<li><p>无凭据: <a href=\"http://HOST:PORT/。\">http://HOST:PORT/。</a></p>\n</li>\n</ul>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; failOnError&#x3D;&quot;true&quot;&#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; proxy&#x3D;&quot;http:&#x2F;&#x2F;192.168.1.5:80&#x2F;&quot;&#x2F;&gt;\n\n&lt;download from&#x3D;&quot;https:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; auth&#x3D;&quot;sspi&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;https:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot; failOnError&#x3D;&quot;true&quot;\n auth&#x3D;&quot;basic&quot; user&#x3D;&quot;aUser&quot; password&#x3D;&quot;aPassw0rd&quot; &#x2F;&gt;\n\n&lt;download from&#x3D;&quot;http:&#x2F;&#x2F;example.com&#x2F;some.dat&quot; to&#x3D;&quot;%BASE%\\some.dat&quot;\n proxy&#x3D;&quot;http:&#x2F;&#x2F;aUser:aPassw0rd@192.168.1.5:80&#x2F;&quot;\n auth&#x3D;&quot;basic&quot; unsecureAuth&#x3D;&quot;true&quot;\n user&#x3D;&quot;aUser&quot; password&#x3D;&quot;aPassw0rd&quot; &#x2F;&gt;</code></pre>\n<p>这是开发自我更新服务的另一个有用的组成部分。</p>\n<p>自 2.7 版起如果目标文件存在WinSW 将在 If-Modified-Since 标头中发送其最后写入时间,如果收到 304 Not Modified则跳过下载。</p>\n<h3 id=\"onfailure\"><a href=\"#onfailure\" class=\"headerlink\" title=\"onfailure\"></a>onfailure</h3><p>当 winsw 启动的进程失败(即以非零退出代码退出)时,这个可选的可重复元素将控制其行为。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;onfailure action&#x3D;&quot;restart&quot; delay&#x3D;&quot;10 sec&quot;&#x2F;&gt;\n&lt;onfailure action&#x3D;&quot;restart&quot; delay&#x3D;&quot;20 sec&quot;&#x2F;&gt;\n&lt;onfailure action&#x3D;&quot;reboot&quot; &#x2F;&gt;</code></pre>\n<p>例如,上述配置会导致服务在第一次故障后 10 秒内重新启动,在第二次故障后 20 秒内重新启动然后如果服务再次发生故障Windows 将重新启动。</p>\n<p>每个元素都包含一个强制的 action 属性和可选的 delay 属性,前者用于控制 Windows SCM 将采取的行动后者用于控制采取该行动前的延迟时间。action 的合法值为</p>\n<ul>\n<li><p>restart重新启动服务</p>\n</li>\n<li><p>reboot重新启动 Windows。将显示带有 <a href=\"https://docs.microsoft.com/windows-hardware/drivers/debugger/bug-check-0xef--critical-process-died\">CRITICAL_PROCESS_DIED</a> 错误检查代码的蓝色屏幕</p>\n</li>\n<li><p>none不执行任何操作让服务停止延迟属性的可能后缀为秒/秒/分钟/分钟/小时/小时/天/天。如果缺少,延迟属性默认为 0。</p>\n</li>\n</ul>\n<p>延迟属性的后缀可能是秒/秒/分/分/小时/小时/天/天。如果缺少,延迟属性默认为 0。</p>\n<p>如果服务不断发生故障,并且超过了配置的 <code>&lt;onfailure&gt;</code>次数,则会重复上次的操作。因此,如果只想始终自动重启服务,只需像这样指定一个 <code>&lt;onfailure&gt;</code> 元素即可:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;onfailure action&#x3D;&quot;restart&quot; &#x2F;&gt;</code></pre>\n<h3 id=\"resetfailure\"><a href=\"#resetfailure\" class=\"headerlink\" title=\"resetfailure\"></a>resetfailure</h3><p>此可选元素控制 Windows SCM 重置故障计数的时间。例如,如果您指定 <resetfailure>1 小时</resetfailure>,而服务持续运行的时间超过一小时,那么故障计数将重置为零。</p>\n<p>换句话说,这是您认为服务成功运行的持续时间。默认为 1 天。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;resetfailure&gt;1 hour&lt;&#x2F;resetfailure&gt;</code></pre>\n<h3 id=\"Security-descriptor\"><a href=\"#Security-descriptor\" class=\"headerlink\" title=\"Security descriptor\"></a>Security descriptor</h3><p>SDDL 格式的服务安全描述符字符串。</p>\n<p>有关详细信息,请参阅<a href=\"https://learn.microsoft.com/zh-cn/windows/win32/secauthz/security-descriptor-definition-language\">安全描述符定义语言</a>。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;securityDescriptor&gt;&lt;&#x2F;securityDescriptor&gt;</code></pre>\n<h3 id=\"Service-account\"><a href=\"#Service-account\" class=\"headerlink\" title=\"Service account\"></a>Service account</h3><p>服务默认安装为 <a href=\"https://docs.microsoft.com/windows/win32/services/localsystem-account\">LocalSystem 账户</a>。如果您的服务不需要很高的权限级别,可以考虑使用 <a href=\"https://docs.microsoft.com/windows/win32/services/localservice-account\">LocalService 账户</a>、<a href=\"https://docs.microsoft.com/windows/win32/services/networkservice-account\">NetworkService 帐户</a>或用户账户。</p>\n<p>要使用用户账户,请像这样指定 <code>&lt;serviceaccount&gt;</code> 元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;DomainName\\UserName&lt;&#x2F;username&gt;\n &lt;password&gt;Pa55w0rd&lt;&#x2F;password&gt;\n &lt;allowservicelogon&gt;true&lt;&#x2F;allowservicelogon&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p><code>&lt;username&gt;</code>的格式为 DomainName\\UserName 或 UserName@DomainName。如果账户属于内置域则可以指定 .\\UserName。</p>\n<p><code>&lt;allowservicelogon&gt;</code> 是可选项。如果设置为 true将自动为列出的账户设置 “允许以服务身份登录 “的权限。</p>\n<p>要使用<a href=\"https://docs.microsoft.com/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview\">Group Managed Service Accounts Overview</a>,请在账户名后追加 $ 并删除 <code>&lt;password&gt;</code> 元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;DomainName\\GmsaUserName$&lt;&#x2F;username&gt;\n &lt;allowservicelogon&gt;true&lt;&#x2F;allowservicelogon&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<h4 id=\"LocalSystem-account\"><a href=\"#LocalSystem-account\" class=\"headerlink\" title=\"LocalSystem account\"></a>LocalSystem account</h4><p>要明确使用<a href=\"https://docs.microsoft.com/windows/win32/services/localsystem-account\">LocalSystem 帐户</a> ,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;LocalSystem&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"LocalService-account\"><a href=\"#LocalService-account\" class=\"headerlink\" title=\"LocalService account\"></a>LocalService account</h4><p>要使用 <a href=\"https://docs.microsoft.com/windows/win32/services/localservice-account\">LocalService 帐户</a>,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;NT AUTHORITY\\LocalService&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"NetworkService-account\"><a href=\"#NetworkService-account\" class=\"headerlink\" title=\"NetworkService account\"></a>NetworkService account</h4><p>要使用 <a href=\"https://docs.microsoft.com/windows/win32/services/networkservice-account\">NetworkService 帐户</a>,请指定以下内容:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;username&gt;NT AUTHORITY\\NetworkService&lt;&#x2F;username&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<p>请注意,该账户没有密码,因此提供的任何密码都将被忽略。</p>\n<h4 id=\"prompt\"><a href=\"#prompt\" class=\"headerlink\" title=\"prompt\"></a>prompt</h4><p>可选。提示输入用户名和密码。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;serviceaccount&gt;\n &lt;prompt&gt;dialog|console&lt;&#x2F;prompt&gt;\n&lt;&#x2F;serviceaccount&gt;</code></pre>\n<ul>\n<li><p>话框:使用对话框进行提示。</p>\n</li>\n<li><p>控制台:在控制台进行提示。</p>\n</li>\n</ul>\n<h3 id=\"Working-directory\"><a href=\"#Working-directory\" class=\"headerlink\" title=\"Working directory\"></a>Working directory</h3><p>某些服务在运行时需要指定工作目录。为此,请像这样指定<code>&lt;workingdirectory&gt;</code>元素:</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;workingdirectory&gt;C:\\application&lt;&#x2F;workingdirectory&gt;</code></pre>\n<h3 id=\"Priority\"><a href=\"#Priority\" class=\"headerlink\" title=\"Priority\"></a>Priority</h3><p>可选择指定服务进程的调度优先级(相当于 Unix nice可选值包括<code>idle</code>, <code>belownormal</code>, <code>normal</code>, <code>abovenormal</code>, <code>high</code>, <code>realtime</code>(不区分大小写)。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;priority&gt;idle&lt;&#x2F;priority&gt;</code></pre>\n<p>指定高于正常值的优先级会产生意想不到的后果。有关详细信息,请参阅 .NET 文档中的 <a href=\"https://docs.microsoft.com/dotnet/api/system.diagnostics.processpriorityclass\">ProcessPriorityClass 枚举</a>。此功能的主要目的是以较低的优先级启动进程,以免干扰计算机的交互式使用。</p>\n<h3 id=\"Auto-refresh\"><a href=\"#Auto-refresh\" class=\"headerlink\" title=\"Auto refresh\"></a>Auto refresh</h3><pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;autoRefresh&gt;true&lt;&#x2F;autoRefresh&gt;</code></pre>\n<p>当服务启动或执行以下命令时,自动刷新服务属性:</p>\n<ul>\n<li>start</li>\n<li>stop</li>\n<li>restart</li>\n</ul>\n<p>默认值为 true。</p>\n<h3 id=\"sharedDirectoryMapping\"><a href=\"#sharedDirectoryMapping\" class=\"headerlink\" title=\"sharedDirectoryMapping\"></a>sharedDirectoryMapping</h3><p>默认情况下,即使在 Windows 服务配置文件中进行了配置Windows 也不会为服务建立共享驱动器映射。由于域策略的原因,有时无法解决这个问题。</p>\n<p>这样就可以在启动可执行文件之前映射外部共享目录。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;sharedDirectoryMapping&gt;\n &lt;map label&#x3D;&quot;N:&quot; uncpath&#x3D;&quot;\\\\UNC&quot; &#x2F;&gt;\n &lt;map label&#x3D;&quot;M:&quot; uncpath&#x3D;&quot;\\\\UNC2&quot; &#x2F;&gt;\n&lt;&#x2F;sharedDirectoryMapping&gt;</code></pre>","categories":[{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/categories/%E5%B7%A5%E5%85%B7/"}],"tags":[{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/tags/%E5%B7%A5%E5%85%B7/"}]},{"title":"解决Java应用中的字符编码问题深入理解JVM编码格式","slug":"jvm-encoding","date":"2023-10-10T07:30:36.000Z","updated":"2023-10-10T08:19:09.329Z","comments":true,"path":"/post/jvm-encoding/","link":"","excerpt":"","content":"<h1 id=\"导言\"><a href=\"#导言\" class=\"headerlink\" title=\"导言\"></a>导言</h1><p>在Java应用程序开发中字符编码问题是一个常见的挑战。正确处理字符编码对于数据的完整性至关重要。本文将深入探讨JVMJava虚拟机编码格式的相关内容包括如何查询、设置和修改以及如何应对字符编码问题。</p>\n<h1 id=\"1、JVM编码格式简介\"><a href=\"#1、JVM编码格式简介\" class=\"headerlink\" title=\"1、JVM编码格式简介\"></a>1、JVM编码格式简介</h1><p>JVMJava虚拟机是运行Java程序的核心组件它负责将Java字节码转换为机器指令。在Java应用程序中正确的编码设置非常重要因为它直接影响到字符串的处理和输出。了解JVM的编码格式以及如何设置和管理它们对于开发可靠和可移植的Java应用程序至关重要。</p>\n<h1 id=\"2、查询JVM的编码格式\"><a href=\"#2、查询JVM的编码格式\" class=\"headerlink\" title=\"2、查询JVM的编码格式\"></a>2、查询JVM的编码格式</h1><p>有多种方法可以查询JVM的编码格式。其中一种方法是使用Java代码来查询。通过调用<code>System.getProperty(&quot;file.encoding&quot;)</code>方法可以获取JVM当前的默认编码格式。另一种方法是使用命令行工具查看JVM的编码设置。可以使用以下命令来查看JVM参数</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">java -XX:+PrintFlagsFinal -version | grep -iE &#39;Default Charset&#39;</code></pre>\n<h1 id=\"3、设置JVM的编码格式\"><a href=\"#3、设置JVM的编码格式\" class=\"headerlink\" title=\"3、设置JVM的编码格式\"></a>3、设置JVM的编码格式</h1><p>有两种主要方法可以配置JVM的编码格式。第一种是通过启动参数配置。在启动Java应用程序时可以在命令行或脚本中添加特定的启动参数来设置JVM的编码格式。例如使用以下命令来设置UTF-8编码</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">java -Dfile.encoding&#x3D;UTF-8 YourApplication</code></pre>\n<p>第二种方法是使用Java代码修改系统属性以设置JVM编码。可以通过调用<code>System.setProperty(&quot;file.encoding&quot;, &quot;UTF-8&quot;)</code>方法来实现。确保在应用程序的适当位置执行此操作以确保编码在整个生命周期中保持一致。</p>\n<h1 id=\"4、改JVM的默认编码格式\"><a href=\"#4、改JVM的默认编码格式\" class=\"headerlink\" title=\"4、改JVM的默认编码格式\"></a>4、改JVM的默认编码格式</h1><ul>\n<li>编辑启动脚本以调整JVM编码设置。找到启动Java应用程序的脚本文件如<code>startup.sh</code>或<code>startup.bat</code>并添加适当的启动参数来指定所需的编码格式。例如使用以下命令来设置UTF-8编码</li>\n</ul>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">export JAVA_OPTS&#x3D;&quot;-Dfile.encoding&#x3D;UTF-8&quot;</code></pre>\n<p>然后重新启动应用程序,新的编码设置将生效。</p>\n<ul>\n<li>如果使用的是IDE集成开发环境可以在项目设置或运行配置中添加相应的启动参数来修改JVM的默认编码格式。</li>\n<li>如果应用程序已经部署在服务器上,可以通过修改服务器配置文件或环境变量来更改默认编码格式。这通常涉及到对操作系统的环境变量进行设置或更新相关的服务配置。</li>\n</ul>\n<h1 id=\"5、注意事项和最佳实践\"><a href=\"#5、注意事项和最佳实践\" class=\"headerlink\" title=\"5、注意事项和最佳实践\"></a>5、注意事项和最佳实践</h1><p>在选择和设置JVM的编码格式时需要注意以下几点</p>\n<ul>\n<li>确保选择与应用程序需求相匹配的编码格式。不同的字符集适用于不同的场景,如处理文本数据、网络通信等。根据具体的应用场景选择合适的编码格式可以提高程序的效率和正确性。</li>\n<li>理解特定应用程序的字符编码要求。某些应用程序可能有特定的字符编码要求如XML解析器可能要求使用特定的字符集。在设计和开发应用程序时要仔细考虑这些要求并相应地设置JVM的编码格式。</li>\n<li>注意跨平台兼容性。不同的操作系统和Java版本可能支持不同的字符集。在进行跨平台开发时要测试和验证所选的编码</li>\n</ul>\n<h1 id=\"结论\"><a href=\"#结论\" class=\"headerlink\" title=\"结论\"></a>结论</h1><p>正确设置JVM编码格式对于Java应用程序至关重要因为它直接影响字符数据的传输和处理。通过本文提供的详细指南您可以解决字符编码问题确保应用程序在各种情况下都能正确运行。不要低估字符编码的重要性因为它可能对您的应用程序的可靠性产生深远影响。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"深入了解 Cron 时间字段:定时任务的精确控制","slug":"linuxCron","date":"2023-09-14T07:24:10.000Z","updated":"2023-09-15T02:48:59.913Z","comments":true,"path":"/post/linuxCron/","link":"","excerpt":"","content":"<p>在 Linux 和 Unix 系统中cron 是一个强大的工具用于执行预定时间的任务。Cron 允许用户自动化各种重复性任务,如备份、系统监控、日志清理等。在<br>cron 中,时间的设定是至关重要的,它使用一些特殊的时间字段来确定任务的执行时机。本文将深入探讨常见的 cron 时间字段及其用途。</p>\n<h1 id=\"1、常规-Cron-时间字段\"><a href=\"#1、常规-Cron-时间字段\" class=\"headerlink\" title=\"1、常规 Cron 时间字段\"></a>1、常规 Cron 时间字段</h1><p>常规 Cron 时间字段:精确控制任务执行时间</p>\n<p>在常规 cron 时间字段中,您可以通过分钟、小时、日期等来精确控制任务的执行时间。以下是一些示例:</p>\n<h2 id=\"1-1、每天凌晨执行备份任务\"><a href=\"#1-1、每天凌晨执行备份任务\" class=\"headerlink\" title=\"1.1、每天凌晨执行备份任务\"></a>1.1、每天凌晨执行备份任务</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">0 0 * * * &#x2F;usr&#x2F;local&#x2F;bin&#x2F;backup.sh</code></pre>\n<h2 id=\"1-2、每小时执行系统监控任务\"><a href=\"#1-2、每小时执行系统监控任务\" class=\"headerlink\" title=\"1.2、每小时执行系统监控任务\"></a>1.2、每小时执行系统监控任务</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">0 * * * * &#x2F;usr&#x2F;local&#x2F;bin&#x2F;system_monitor.sh</code></pre>\n<h2 id=\"1-3、每周执行日志清理任务\"><a href=\"#1-3、每周执行日志清理任务\" class=\"headerlink\" title=\"1.3、每周执行日志清理任务:\"></a>1.3、每周执行日志清理任务:</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">0 2 * * 6 &#x2F;usr&#x2F;local&#x2F;bin&#x2F;clean_logs.sh</code></pre>\n<h2 id=\"1-4、每月执行系统更新任务\"><a href=\"#1-4、每月执行系统更新任务\" class=\"headerlink\" title=\"1.4、每月执行系统更新任务:\"></a>1.4、每月执行系统更新任务:</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">0 3 1 * * &#x2F;usr&#x2F;bin&#x2F;apt-get update &amp;&amp; &#x2F;usr&#x2F;bin&#x2F;apt-get upgrade -y</code></pre>\n<h2 id=\"1-5、每隔-15-分钟执行检查网站可用性任务:\"><a href=\"#1-5、每隔-15-分钟执行检查网站可用性任务:\" class=\"headerlink\" title=\"1.5、每隔 15 分钟执行检查网站可用性任务:\"></a>1.5、每隔 15 分钟执行检查网站可用性任务:</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">*&#x2F;15 * * * * &#x2F;usr&#x2F;local&#x2F;bin&#x2F;check_website.sh</code></pre>\n<p>这些常规的 cron 时间字段允许您按照特定的时间表来安排任务的执行,非常适用于各种自动化需求。</p>\n<h1 id=\"2、特殊-Cron-时间字段:简化时间设定\"><a href=\"#2、特殊-Cron-时间字段:简化时间设定\" class=\"headerlink\" title=\"2、特殊 Cron 时间字段:简化时间设定\"></a>2、特殊 Cron 时间字段:简化时间设定</h1><p>除了常规的时间字段外,还有一些特殊的时间字段,如 @reboot、@yearly、@monthly 等,它们可以更方便地设置任务的执行时间,通常用于特殊场景。示例:</p>\n<h2 id=\"2-1、-reboot系统启动时执行任务\"><a href=\"#2-1、-reboot系统启动时执行任务\" class=\"headerlink\" title=\"2.1、@reboot系统启动时执行任务\"></a>2.1、@reboot系统启动时执行任务</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@reboot &#x2F;usr&#x2F;local&#x2F;bin&#x2F;startup_script.sh</code></pre>\n<h2 id=\"2-2、-yearly-或-annually每年执行一次\"><a href=\"#2-2、-yearly-或-annually每年执行一次\" class=\"headerlink\" title=\"2.2、@yearly 或 @annually每年执行一次\"></a>2.2、@yearly 或 @annually每年执行一次</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@yearly &#x2F;usr&#x2F;local&#x2F;bin&#x2F;yearly_task.sh</code></pre>\n<h2 id=\"2-3、-monthly每月执行一次\"><a href=\"#2-3、-monthly每月执行一次\" class=\"headerlink\" title=\"2.3、@monthly每月执行一次\"></a>2.3、@monthly每月执行一次</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@monthly &#x2F;usr&#x2F;local&#x2F;bin&#x2F;monthly_task.sh</code></pre>\n<h2 id=\"2-4、-weekly每周执行一次\"><a href=\"#2-4、-weekly每周执行一次\" class=\"headerlink\" title=\"2.4、@weekly每周执行一次\"></a>2.4、@weekly每周执行一次</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@weekly &#x2F;usr&#x2F;local&#x2F;bin&#x2F;weekly_task.sh</code></pre>\n<h2 id=\"2-5、-daily-或-midnight每天执行一次\"><a href=\"#2-5、-daily-或-midnight每天执行一次\" class=\"headerlink\" title=\"2.5、@daily 或 @midnight每天执行一次\"></a>2.5、@daily 或 @midnight每天执行一次</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@daily &#x2F;usr&#x2F;local&#x2F;bin&#x2F;daily_task.sh</code></pre>\n<h2 id=\"2-6、-hourly每小时执行一次\"><a href=\"#2-6、-hourly每小时执行一次\" class=\"headerlink\" title=\"2.6、@hourly每小时执行一次\"></a>2.6、@hourly每小时执行一次</h2><pre class=\"line-numbers language-none\"><code class=\"language-none\">@hourly &#x2F;usr&#x2F;local&#x2F;bin&#x2F;hourly_task.sh</code></pre>\n<p>这些特殊的时间字段使得在 crontab 中定义定时任务更加方便您可以根据任务的周期性要求选择适当的时间字段。它们使时间设定更加直观和易读而不需要编写复杂的时间表。通过合理利用cron 时间字段,您可以轻松自动化各种系统维护和管理任务,提高系统的效率和可靠性。</p>\n","categories":[{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/categories/Linux/"}],"tags":[{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/tags/Linux/"}]},{"title":"解决图片不刷新问题:浏览器缓存与缓存控制头的终极对决","slug":"vueImages","date":"2023-09-12T02:07:57.000Z","updated":"2023-09-12T05:37:33.993Z","comments":true,"path":"/post/vueImages/","link":"","excerpt":"","content":"<p>在现代Web开发中许多开发者都曾经遇到过一个令人困扰的问题当图片URL没有变化但图片内容却发生了变化时浏览器似乎不会主动刷新图片从而导致显示旧的内容。这个问题在网站和应用中的图片更新时尤为突出可能会影响用户体验和页面正确性。</p>\n<p>在这篇博客文章中,我们将探讨这个问题,并提供多种解决方案,其中包括添加时间戳或随机参数以绕过浏览器缓存以及配置缓存控制头来告诉浏览器如何处理这些图片。我们将深入了解这些解决方案的实现方式以及它们在不同服务器和框架中的应用。</p>\n<h1 id=\"问题的根源\"><a href=\"#问题的根源\" class=\"headerlink\" title=\"问题的根源\"></a>问题的根源</h1><p>问题的根本在于浏览器的缓存机制。浏览器会根据图片的URL来决定是否重新请求图片或者使用缓存中的版本。当图片的URL保持不变时浏览器会倾向于使用已经缓存的旧版本而不会去服务器重新获取新的图片内容。</p>\n<h1 id=\"解决方案一:添加时间戳或随机参数\"><a href=\"#解决方案一:添加时间戳或随机参数\" class=\"headerlink\" title=\"解决方案一:添加时间戳或随机参数\"></a>解决方案一:添加时间戳或随机参数</h1><p>为了绕过浏览器的缓存机制最简单的方法之一是在图片的URL上添加一个时间戳或随机参数。这将使每次请求都看起来像一个不同的URL从而迫使浏览器重新加载图片。</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;img :src&#x3D;&quot;&#39;your-image-url.jpg?&#39; + Date.now()&quot;&gt;</code></pre>\n<p>或者使用JavaScript生成随机参数</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;img :src&#x3D;&quot;&#39;your-image-url.jpg?&#39; + Math.random()&quot;&gt;</code></pre>\n<p>这种方法适用于各种Web开发环境并且非常容易实现。</p>\n<h1 id=\"解决方案二:配置缓存控制头\"><a href=\"#解决方案二:配置缓存控制头\" class=\"headerlink\" title=\"解决方案二:配置缓存控制头\"></a>解决方案二:配置缓存控制头</h1><p>另一种更强大的方法是在服务器端配置缓存控制头。不同的服务器和框架有不同的配置方式,以下是一些示例:</p>\n<h2 id=\"Apache\"><a href=\"#Apache\" class=\"headerlink\" title=\"Apache\"></a>Apache</h2><p>在Apache服务器上您可以通过<code>.htaccess</code>文件来配置缓存控制头,告诉浏览器不要缓存特定类型的图片。</p>\n<pre class=\"line-numbers language-apacheconf\" data-language=\"apacheconf\"><code class=\"language-apacheconf\">&lt;IfModule mod_headers.c&gt;\n # 禁止缓存指定文件类型的图片,例如 .jpg 和 .png\n &lt;FilesMatch &quot;\\.(jpg|png)$&quot;&gt;\n Header set Cache-Control &quot;no-cache, no-store, must-revalidate&quot;\n Header set Pragma &quot;no-cache&quot;\n Header set Expires 0\n &lt;&#x2F;FilesMatch&gt;\n&lt;&#x2F;IfModule&gt;</code></pre>\n<h2 id=\"Nginx\"><a href=\"#Nginx\" class=\"headerlink\" title=\"Nginx\"></a>Nginx</h2><p>如果使用Nginx作为服务器可以在Nginx配置文件中添加以下配置来实现缓存控制</p>\n<pre class=\"line-numbers language-nginx\" data-language=\"nginx\"><code class=\"language-nginx\">location ~* \\.(jpg|png)$ &#123;\n expires -1;\n add_header Cache-Control &quot;no-store, no-cache, must-revalidate, max-age&#x3D;0&quot;;\n add_header Pragma &quot;no-cache&quot;;\n&#125;</code></pre>\n<h2 id=\"Node-jsExpress框架\"><a href=\"#Node-jsExpress框架\" class=\"headerlink\" title=\"Node.jsExpress框架\"></a>Node.jsExpress框架</h2><p>在Node.js中使用Express框架您可以创建一个中间件来设置缓存控制头以确保浏览器不会缓存特定类型的图片。</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">const express &#x3D; require(&#39;express&#39;);\nconst app &#x3D; express();\n\n&#x2F;&#x2F; 禁止缓存指定文件类型的图片,例如 .jpg 和 .png\napp.use((req, res, next) &#x3D;&gt; &#123;\n if (req.url.endsWith(&#39;.jpg&#39;) || req.url.endsWith(&#39;.png&#39;)) &#123;\n res.setHeader(&#39;Cache-Control&#39;, &#39;no-store, no-cache, must-revalidate, max-age&#x3D;0&#39;);\n res.setHeader(&#39;Pragma&#39;, &#39;no-cache&#39;);\n &#125;\n next();\n&#125;);\n\n&#x2F;&#x2F; 其他路由和中间件设置\n\napp.listen(3000, () &#x3D;&gt; &#123;\n console.log(&#39;Server is running on port 3000&#39;);\n&#125;);</code></pre>\n<h1 id=\"结论\"><a href=\"#结论\" class=\"headerlink\" title=\"结论\"></a>结论</h1><p>无论您选择哪种方法,解决图片不刷新的问题都是可能的。添加时间戳或随机参数是最简单的方法之一,但它可能需要在多个地方修改代码。配置缓存控制头则可以更全面地控制缓存行为,但需要在服务器端进行配置。</p>\n<p>根据您的项目需求和服务器环境,选择适合您的方法,并确保您的用户可以始终看到最新的图片内容,以提供更好的用户体验。希望本文对您有所帮助,解决了这个常见的开发问题。</p>\n","categories":[{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/categories/vue/"}],"tags":[{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/tags/vue/"}]},{"title":"选择合适的帧率和分辨率优化RTSP流视频抓取","slug":"rtsp","date":"2023-09-06T02:24:03.000Z","updated":"2023-09-12T02:39:13.883Z","comments":true,"path":"/post/rtsp/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>在实时视频流应用中选择适当的帧率和分辨率对于确保视频流的顺畅播放和图像质量至关重要。本文将向您介绍如何使用Java和JavaCV库中的FFmpegFrameGrabber来从RTSP流中抓取图像并在抓取时设置帧率和分辨率。</p>\n<h1 id=\"一、配置开发环境\"><a href=\"#一、配置开发环境\" class=\"headerlink\" title=\"一、配置开发环境\"></a>一、配置开发环境</h1><p>首先确保您的Java项目中包含JavaCV库的依赖。您可以在Maven项目中添加以下依赖</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;dependency&gt;\n &lt;groupId&gt;org.bytedeco&lt;&#x2F;groupId&gt;\n &lt;artifactId&gt;javacv-platform&lt;&#x2F;artifactId&gt;\n &lt;version&gt;1.5.1&lt;&#x2F;version&gt; &lt;!-- 请检查最新版本 --&gt;\n&lt;&#x2F;dependency&gt;</code></pre>\n<h1 id=\"二、使用Java代码抓取RTSP流图像\"><a href=\"#二、使用Java代码抓取RTSP流图像\" class=\"headerlink\" title=\"二、使用Java代码抓取RTSP流图像\"></a>二、使用Java代码抓取RTSP流图像</h1><p>下面是一个示例Java代码演示了如何使用FFmpegFrameGrabber从RTSP流中抓取图像并将其保存为JPEG格式的图像文件。</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import org.bytedeco.javacv.FFmpegFrameGrabber;\nimport org.bytedeco.javacv.Frame;\nimport org.bytedeco.javacv.Java2DFrameConverter;\n\nimport javax.imageio.ImageIO;\nimport java.awt.image.BufferedImage;\nimport java.io.File;\n\npublic class RTSPImageCapture &#123;\n public static void main(String[] args) &#123;\n String rtsp &#x3D; &quot;YOUR_RTSP_URL_HERE&quot;; &#x2F;&#x2F; 替换为实际的RTSP URL\n String imgSrc &#x3D; &quot;&quot;; &#x2F;&#x2F; 图像保存路径\n String linuxImg &#x3D; &quot;&#x2F;path&#x2F;to&#x2F;linux&#x2F;img&#x2F;&quot;; &#x2F;&#x2F; Linux系统下的保存路径\n String winImg &#x3D; &quot;C:\\\\path\\\\to\\\\windows\\\\img\\\\&quot;; &#x2F;&#x2F; Windows系统下的保存路径\n\n try &#123;\n FFmpegFrameGrabber grabber &#x3D; new FFmpegFrameGrabber(rtsp);\n &#x2F;&#x2F; 使用tcp的方式不然会丢包很严重\n grabber.setOption(&quot;rtsp_transport&quot;, &quot;tcp&quot;);\n grabber.start();\n Frame frame &#x3D; grabber.grabImage();\n if (frame !&#x3D; null) &#123;\n if (imgSrc &#x3D;&#x3D; null || imgSrc.isEmpty()) &#123;\n String path &#x3D; &quot;&quot;;\n if (SystemUtils.isLinux()) &#123;\n path &#x3D; linuxImg;\n &#125; else if (SystemUtils.isWindows()) &#123;\n path &#x3D; winImg;\n &#125;\n imgSrc &#x3D; path + &quot;video.jpg&quot;;\n &#125;\n File file &#x3D; new File(imgSrc);\n file.createNewFile();\n Java2DFrameConverter converter &#x3D; new Java2DFrameConverter();\n BufferedImage bufferedImage &#x3D; converter.getBufferedImage(frame);\n ImageIO.write(bufferedImage, &quot;jpg&quot;, file);\n &#125;\n grabber.stop();\n &#125; catch (Exception e) &#123;\n e.printStackTrace();\n &#125;\n &#125;\n&#125;</code></pre>\n<p>确保将上述代码中的<code>YOUR_RTSP_URL_HERE</code>替换为实际的RTSP流URL并设置正确的图像保存路径。</p>\n<h1 id=\"三、帧率的选择\"><a href=\"#三、帧率的选择\" class=\"headerlink\" title=\"三、帧率的选择\"></a>三、帧率的选择</h1><h2 id=\"1、实时性要求\"><a href=\"#1、实时性要求\" class=\"headerlink\" title=\"1、实时性要求\"></a>1、实时性要求</h2><ul>\n<li>帧率定义了每秒显示的图像数量通常以”帧每秒”fps表示。</li>\n<li>实时或接近实时的应用如视频监控通常需要较高的帧率建议使用30fps或更高。</li>\n</ul>\n<h2 id=\"2、考虑资源限制\"><a href=\"#2、考虑资源限制\" class=\"headerlink\" title=\"2、考虑资源限制\"></a>2、考虑资源限制</h2><ul>\n<li>高帧率需要更多的带宽和计算资源。</li>\n<li>确保您的设备和网络能够支持所选的帧率,以避免性能问题。</li>\n</ul>\n<h2 id=\"3、应用场景\"><a href=\"#3、应用场景\" class=\"headerlink\" title=\"3、应用场景\"></a>3、应用场景</h2><ul>\n<li>不同应用场景可能需要不同的帧率。</li>\n<li>视频播放应用可以使用较低的帧率,而要求高质量图像的应用则可能需要更高的帧率。</li>\n</ul>\n<h2 id=\"4、存储需求\"><a href=\"#4、存储需求\" class=\"headerlink\" title=\"4、存储需求\"></a>4、存储需求</h2><ul>\n<li>高帧率会导致更多的视频数据,需要更多的存储空间。</li>\n<li>考虑存储需求,特别是如果需要保存视频流供后续分析或回放。</li>\n</ul>\n<h1 id=\"四、分辨率的选择\"><a href=\"#四、分辨率的选择\" class=\"headerlink\" title=\"四、分辨率的选择\"></a>四、分辨率的选择</h1><h2 id=\"1、显示设备和屏幕大小\"><a href=\"#1、显示设备和屏幕大小\" class=\"headerlink\" title=\"1、显示设备和屏幕大小\"></a>1、显示设备和屏幕大小</h2><ul>\n<li>分辨率应适合最终显示图像的设备或屏幕大小。</li>\n<li>高分辨率适合大型屏幕,低分辨率适合小型设备。</li>\n</ul>\n<h2 id=\"2、带宽和性能\"><a href=\"#2、带宽和性能\" class=\"headerlink\" title=\"2、带宽和性能\"></a>2、带宽和性能</h2><ul>\n<li>高分辨率图像通常需要更多带宽和计算资源。</li>\n<li>在有限的带宽或性能条件下,选择适度的分辨率以确保流畅的抓取和显示。</li>\n</ul>\n<h2 id=\"3、应用场景-1\"><a href=\"#3、应用场景-1\" class=\"headerlink\" title=\"3、应用场景\"></a>3、应用场景</h2><ul>\n<li>根据应用需求选择合适的分辨率。</li>\n<li>720p1280x720像素或1080p1920x1080像素通常适合大多数实时监控应用。</li>\n</ul>\n<h2 id=\"4、存储需求-1\"><a href=\"#4、存储需求-1\" class=\"headerlink\" title=\"4、存储需求\"></a>4、存储需求</h2><ul>\n<li>高分辨率图像需要更多的存储空间。</li>\n<li>考虑存储需求,特别是如果需要保存抓取的图像或视频流。</li>\n</ul>\n<h1 id=\"五、设置帧率和分辨率的实际操作\"><a href=\"#五、设置帧率和分辨率的实际操作\" class=\"headerlink\" title=\"五、设置帧率和分辨率的实际操作\"></a>五、设置帧率和分辨率的实际操作</h1><p>要设置帧率和分辨率,您可以使用相应的方法来配置<code>FFmpegFrameGrabber</code></p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;&#x2F; 设置所需的帧率\ngrabber.setFrameRate(desiredFrameRate);\n\n&#x2F;&#x2F; 设置所需的分辨率\ngrabber.setImageWidth(desiredWidth);\ngrabber.setImageHeight(desiredHeight);</code></pre>\n<p>确保在调用<code>grabber.start();</code>之前进行这些设置,以确保配置在抓取开始之前生效。</p>\n<p>选择合适的帧率和分辨率是优化RTSP流视频抓取的关键步骤可以提供良好的图像质量和实时性同时考虑资源限制和存储需求。根据您的应用需求选择最佳的参数设置以获得最佳的用户体验。</p>\n<h1 id=\"六、实时性和流畅性的权衡\"><a href=\"#六、实时性和流畅性的权衡\" class=\"headerlink\" title=\"六、实时性和流畅性的权衡\"></a>六、实时性和流畅性的权衡</h1><p>在选择帧率和分辨率时,需要平衡实时性和流畅性。以下是一些有关权衡的考虑:</p>\n<ul>\n<li><p><strong>实时性</strong>:较高的帧率和分辨率可以提供更好的实时性,但可能需要更多的带宽和处理能力。在需要快速响应和高质量图像的应用中,实时性至关重要。</p>\n</li>\n<li><p><strong>流畅性</strong>:较高的帧率通常会导致更平滑的视频播放,但也需要更多的带宽。较低的帧率可能会导致视频看起来不够流畅,但在有限的带宽条件下可能是唯一可行的选择。</p>\n</li>\n<li><p><strong>网络条件</strong>:网络速度和稳定性对帧率和分辨率的选择至关重要。在不稳定的网络条件下,较低的帧率和分辨率可能更可取,以减少视频中断或缓冲。</p>\n</li>\n</ul>\n<h1 id=\"七、动态调整\"><a href=\"#七、动态调整\" class=\"headerlink\" title=\"七、动态调整\"></a>七、动态调整</h1><p>有些应用可能需要根据情况动态调整帧率和分辨率。例如,当网络带宽下降时,可以降低帧率和分辨率以适应当前条件,从而保持视频的流畅性。</p>\n<h1 id=\"结论\"><a href=\"#结论\" class=\"headerlink\" title=\"结论\"></a>结论</h1><p>选择合适的帧率和分辨率是优化RTSP流视频抓取的关键决策。根据应用的实时性要求、资源限制、显示设备、存储需求和网络条件您可以调整这些参数以获得最佳的用户体验。实时性和流畅性之间的权衡是一个关键考虑因素可以根据需要进行调整以适应不同的应用场景。</p>\n<p>最终了解您的应用需求并进行测试是选择合适的帧率和分辨率的关键。通过仔细权衡这些因素您可以确保您的RTSP流视频抓取应用提供了所需的性能和图像质量。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"沈阳盖章计划","slug":"sealSY","date":"2023-08-31T11:10:28.000Z","updated":"2023-09-01T01:29:48.302Z","comments":true,"path":"/post/sealSY/","link":"","excerpt":"","content":"<h1 id=\"沈阳盖章计划\"><a href=\"#沈阳盖章计划\" class=\"headerlink\" title=\"沈阳盖章计划\"></a>沈阳盖章计划</h1><h2 id=\"和平区\"><a href=\"#和平区\" class=\"headerlink\" title=\"和平区\"></a>和平区</h2><ul>\n<li>[ ] 中共满洲省委门口服务站2个</li>\n<li>[ ] 歌德书店1个蓝色章</li>\n<li>[ ] 沈阳集邮门市部38个章</li>\n<li><p>[ ] 沈阳东北大学成立100周年东大风味食堂进去科学馆1923咖啡馆28个章</p>\n</li>\n<li><p>[ ] 老北市6号门文创雪糕8个章12.8元雪糕)</p>\n</li>\n<li>[ ] 老北市1号门服务台免费4个消费39有34个章</li>\n<li>[ ] 老北市汉字主题书房28个38元</li>\n<li><p>[ ] 刘少奇旧居纪念馆(满洲省委旧址)</p>\n</li>\n<li><p>[ ] 西西弗书店太原街万达F22个</p>\n</li>\n<li>[ ] 西西弗书店万象城bl2个</li>\n<li>[ ] 西西弗书店长白万象汇F22个</li>\n<li>[ ] 宋玉桂艺术馆5个</li>\n<li>[ ] 雷锋主题邮局4个砂阳路邮局</li>\n<li>[ ] 茶话弄(沈阳太原街万达店)</li>\n<li>[ ] 太原街中兴魔方小镇2个</li>\n<li>[ ] 盛京邮局2个</li>\n<li>[ ] 阳光荟购物中心魔方小镇2个</li>\n</ul>\n<h2 id=\"铁西区\"><a href=\"#铁西区\" class=\"headerlink\" title=\"铁西区\"></a>铁西区</h2><ul>\n<li>[ ] 红梅文创园服务中心(1个章)</li>\n<li>[ ] 西西弗书店万象汇F2(1个章)</li>\n<li>[ ] 铁西工业博物馆免费</li>\n<li>[ ] 铁西1905文化创意园3楼小芝社(27个章49)</li>\n<li>[ ] 铁西1905文化创意园3楼微码客(2个章任意消费建议沈阳手绘地图29</li>\n<li>[ ] 铁西1905文化创意园一楼西门服务台边上有个店进去礼貌询问店员即可免费盖</li>\n<li>[ ] 铁西1905文化创意园中间的市集一楼003摊位蜜思花园一家卖首饰的店橡皮章免费盖</li>\n<li>[ ] 铁西1905文化创意园楼一楼中间005摊位CUTECATS。任意消费可盖</li>\n<li>[ ] 铁西1905文化创意园一楼中间008摊位光之翼塔罗 免费盖</li>\n<li>[ ] 铁西1905文化创意园p6边上 @红雾动画工作室 关注小红书送扇子消费送贴纸</li>\n<li>[ ] 铁西1905文化创意园二楼右侧楼梯 旁,饰物所@daydream事务所</li>\n</ul>\n<h1 id=\"沈河区\"><a href=\"#沈河区\" class=\"headerlink\" title=\"沈河区\"></a>沈河区</h1><ul>\n<li>[ ] 沈阳城市规划展示馆(1个章)</li>\n<li>[ ] 小芝社故宫店(8个章+3个隐藏章最低需消费30元)</li>\n<li>[ ] 西西弗书店中街大悦城店F2(2个章)</li>\n<li>[ ] 沈阳故宫.莊啡(18个章)</li>\n<li>[ ] 沈阳故宫文创大政殿旁(12个章通关文牒25)还有一个15元地图</li>\n<li>[ ] 沈阳故宫出口处旁(17个章)</li>\n<li>[ ] 沈阳故宫戏台旁边长滩(6个章17元明 信片)</li>\n<li>[ ] 西西弗书店中街恒隆店F2(2个章)</li>\n<li>[ ] 东三省总督府(1个章)</li>\n<li>[ ] 张氏帅府外面文创(120个章49元盖章本)可拿文创本进帅府里面还有30枚印章(48门票)</li>\n<li>[ ] 张氏帅府游客中心(3个章)</li>\n<li>[ ] 沈阳博物馆(12个章39元盖章本)</li>\n<li>[ ] 大悦城魔方小镇前台咖啡处北方书城(2个)免费(9月份才有)</li>\n<li>[ ] 神马艺术商店中街HK01流行馆六楼(25个任意消费)</li>\n<li>[ ] 沈阳美术馆(1枚)</li>\n<li>[ ] 沈阳中街HK01流行馆六楼”是是是集”(2个)</li>\n<li>[ ] 沈阳中街Hk01流行馆六楼”Crunch冻春”(抵消20)(章数20+)</li>\n<li>[ ] 沈阳迦大文创设计廊(7个)抵消30</li>\n</ul>\n<h1 id=\"浑南区\"><a href=\"#浑南区\" class=\"headerlink\" title=\"浑南区\"></a>浑南区</h1><ul>\n<li>[ ] 世博园(1个待确认)</li>\n<li>[ ] 西西弗书店全运路万达F1(2个章)</li>\n<li>[ ] 辽宁科技馆(4个章)</li>\n<li>[x] 辽宁博物馆(19个章)</li>\n<li>[ ] 东陵公园(1个章)</li>\n</ul>\n<h1 id=\"皇姑区\"><a href=\"#皇姑区\" class=\"headerlink\" title=\"皇姑区\"></a>皇姑区</h1><ul>\n<li>[ ] 北陵公园(1个章)</li>\n<li>[ ] 新乐遗址(1个章)</li>\n<li>[ ] 抗美援朝烈士纪念馆(1个章)</li>\n<li>[ ] 西西弗书店皇姑万象汇(2个章)</li>\n<li>[ ] 辽宁古生物博物馆(2个章)</li>\n<li>[ ] 皇姑屯事件博物馆</li>\n<li>[ ] 审判日本战犯军事法庭(1个章)</li>\n<li>[ ] 沈飞航空博览园(1个章)</li>\n</ul>\n<h1 id=\"大东区\"><a href=\"#大东区\" class=\"headerlink\" title=\"大东区\"></a>大东区</h1><ul>\n<li>[ ] 北大营旧址(1个章)</li>\n<li>[ ] 二战盟军战俘营陈列馆(1个章)</li>\n<li>[ ] 大悦城咖啡主题邮局(63个章)没有了</li>\n<li>[ ] 沈阳大学自然博物馆(1个章)暑假不开</li>\n<li>[ ] 九一八邮局(15个章)</li>\n<li>[ ] 九一八文创(8个章)</li>\n<li>[ ] 周恩来少年读书旧址(1个章)周六日对散客</li>\n<li>[ ] 呈展稻米节</li>\n</ul>\n<h1 id=\"沈北区\"><a href=\"#沈北区\" class=\"headerlink\" title=\"沈北区\"></a>沈北区</h1><ul>\n<li>[ ] 锡伯族博物馆服务台和文创店(1+10)</li>\n</ul>\n","categories":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/categories/%E7%9B%96%E7%AB%A0/"}],"tags":[{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/tags/%E7%9B%96%E7%AB%A0/"}]},{"title":"vue实现打印功能","slug":"vuePrint","date":"2023-08-17T01:49:58.000Z","updated":"2023-08-17T02:06:00.985Z","comments":true,"path":"/post/vuePrint/","link":"","excerpt":"","content":"<p>在Vue应用中调用打印机功能可以使用<code>JavaScript</code>的<code>window.print()</code>方法。这个方法会打开打印对话框,然后让我们选择打印设置并打印文档,但是尼这种方法依赖于浏览器的打印功能。</p>\n<p>以下是一个简单的示例演示如何在Vue组件中调用打印功能</p>\n<ol>\n<li>在Vue组件中将需要打印的内容放入一个具有唯一ID的元素中。例如你可以使用<code>&lt;div id=&quot;printable-content&quot;&gt;&lt;/div&gt;</code>来包裹打印内容。</li>\n</ol>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;template&gt;\n &lt;div&gt;\n &lt;button @click&#x3D;&quot;print&quot;&gt;打印&lt;&#x2F;button&gt;\n &lt;div id&#x3D;&quot;printable-content&quot;&gt;\n &lt;!-- 待打印的内容 --&gt;\n &lt;&#x2F;div&gt;\n &lt;&#x2F;div&gt;\n&lt;&#x2F;template&gt;</code></pre>\n<ol>\n<li>在Vue组件的<code>methods</code>中定义<code>print</code>方法,该方法将获取打印内容并调用<code>window.print()</code>方法打开打印对话框。</li>\n</ol>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">&lt;script&gt;\nexport default &#123;\n methods: &#123;\n print() &#123;\n &#x2F;&#x2F; 获取待打印的内容\n let printableContent &#x3D; document.getElementById(&#39;printable-content&#39;).innerHTML;\n \n &#x2F;&#x2F; 创建一个新的窗口并加载打印内容\n let printWindow &#x3D; window.open(&#39;&#39;, &#39;_blank&#39;);\n printWindow.document.write(&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;打印内容&lt;&#x2F;title&gt;&lt;&#x2F;head&gt;&lt;body&gt;&#39; + printableContent + &#39;&lt;&#x2F;body&gt;&lt;&#x2F;html&gt;&#39;);\n \n &#x2F;&#x2F; 执行打印操作\n printWindow.document.close();\n printWindow.print();\n &#125;\n &#125;\n&#125;\n&lt;&#x2F;script&gt;</code></pre>\n<ol>\n<li>当点击”打印”按钮时,<code>print</code>方法会被调用,从而打开打印对话框。用户可以在对话框中选择打印设置并打印文档。</li>\n</ol>\n<p>最后,再次强调,这种方法依赖于浏览器的打印功能,因此它可能无法在所有打印机上正常工作。</p>\n","categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"前端/vue","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/vue/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/tags/vue/"}]},{"title":"Java代码中对文件的操作","slug":"javaFile","date":"2023-08-15T05:56:51.000Z","updated":"2023-08-16T06:37:39.464Z","comments":true,"path":"/post/javaFile/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>这几天的项目涉及到了文件的操作,我这边做一下整理</p>\n<h1 id=\"环境说明\"><a href=\"#环境说明\" class=\"headerlink\" title=\"环境说明\"></a>环境说明</h1><p>jdk版本1.8.0_311</p>\n<h1 id=\"对文件的操作\"><a href=\"#对文件的操作\" class=\"headerlink\" title=\"对文件的操作\"></a>对文件的操作</h1><h2 id=\"1、保存文件\"><a href=\"#1、保存文件\" class=\"headerlink\" title=\"1、保存文件\"></a>1、保存文件</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 保存文件\n *\n * @param file 文件\n * @param path 文件保存目录\n * @param name 保存后的文件名字\n *&#x2F;\npublic void saveFile(MultipartFile file, String path, String name) throws Exception &#123;\n if (file &#x3D;&#x3D; null) &#123;\n throw new Exception(&quot;请上传有效文件!&quot;);\n &#125;\n &#x2F;&#x2F; 若目录不存在则创建目录\n File folder &#x3D; new File(path);\n if (!folder.exists()) &#123;\n folder.mkdirs();\n &#125;\n\n &#x2F;&#x2F; 生成文件folder为文件目录newName为文件名\n file.transferTo(new File(folder, name));\n&#125;</code></pre>\n<h2 id=\"2、删除文件\"><a href=\"#2、删除文件\" class=\"headerlink\" title=\"2、删除文件\"></a>2、删除文件</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 删除指定目录下的指定文件\n *\n * @param path 文件路径(路径结尾不带“&#x2F;”)\n * @param name 文件名称\n *&#x2F;\npublic void delFile(String path, String name) &#123;\n File file &#x3D; new File(path + &quot;&#x2F;&quot; + name);\n file.delete();\n&#125;</code></pre>\n<h2 id=\"3、删除指定的空目\"><a href=\"#3、删除指定的空目\" class=\"headerlink\" title=\"3、删除指定的空目\"></a>3、删除指定的空目</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 删除指定的空目录如果往上2层的目录也是空的则一起删除\n *\n * @param path 目录路径(路径结尾不带“&#x2F;”)\n *&#x2F;\npublic void delBlankDir(String path) &#123;\n for (int i &#x3D; 0; i &lt; 3; i++) &#123;\n File dirFile &#x3D; new File(path);\n if (dirFile.length() &#x3D;&#x3D; 0) &#123;\n dirFile.delete();\n path &#x3D; path.substring(0, path.lastIndexOf(&quot;&#x2F;&quot;));\n &#125; else &#123;\n break;\n &#125;\n &#125;\n&#125;</code></pre>\n<h2 id=\"4、验证文件是否是MP3格式\"><a href=\"#4、验证文件是否是MP3格式\" class=\"headerlink\" title=\"4、验证文件是否是MP3格式\"></a>4、验证文件是否是MP3格式</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 验证是否是MP3格式的文件\n *\n * @param multipartFile 验证的文件\n * @return true是MP3、false不是MP3\n *&#x2F;\npublic boolean isMP3File(MultipartFile multipartFile) &#123;\n try &#123;\n byte[] headerBytes &#x3D; new byte[4];\n multipartFile.getInputStream().read(headerBytes);\n if (headerBytes[0] &#x3D;&#x3D; (byte) 0x49 &amp;&amp; headerBytes[1] &#x3D;&#x3D; (byte) 0x44 &amp;&amp;\n headerBytes[2] &#x3D;&#x3D; (byte) 0x33) &#123;\n return true;\n &#125;\n &#125; catch (IOException e) &#123;\n e.printStackTrace();\n return false;\n &#125;\n return false;\n&#125;</code></pre>\n<h2 id=\"5、音频格式转换\"><a href=\"#5、音频格式转换\" class=\"headerlink\" title=\"5、音频格式转换\"></a>5、音频格式转换</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 音频文件格式转换\n *\n * @param fpath 需要转换的音频文件路径\n * @param target 转换后的音频文件路径\n *&#x2F;\npublic void transferAudioPcm(String fpath, String target) &#123;\n List&lt;String&gt; commend &#x3D; new ArrayList&lt;&gt;();\n String path &#x3D; &quot;&quot;;\n if (SystemUtils.isLinux()) &#123;\n path &#x3D; &quot;修改成Ffmpeg文件的路径&quot;;\n &#125; else if (SystemUtils.isWindows()) &#123;\n path &#x3D; &quot;修改成Ffmpeg文件的路径&quot;;\n &#125;\n commend.add(path);\n commend.add(&quot;-y&quot;);\n commend.add(&quot;-i&quot;);\n commend.add(fpath);\n commend.add(&quot;-f&quot;);\n commend.add(&quot;s16le&quot;);\n commend.add(&quot;-ar&quot;);\n commend.add(&quot;4000&quot;);\n commend.add(&quot;-ac&quot;);\n commend.add(&quot;-1&quot;);\n commend.add(target);\n try &#123;\n ProcessBuilder builder &#x3D; new ProcessBuilder();\n builder.command(commend);\n Process p &#x3D; builder.start();\n p.waitFor();\n p.destroy();\n &#125; catch (Exception e) &#123;\n e.printStackTrace();\n &#125;\n&#125;</code></pre>\n<h2 id=\"6、改变linux系统下的文件权限\"><a href=\"#6、改变linux系统下的文件权限\" class=\"headerlink\" title=\"6、改变linux系统下的文件权限\"></a>6、改变linux系统下的文件权限</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 改变linux系统下的文件权限\n *\n * @param mod 修改后的权限\n * @param path 文件路径\n *&#x2F;\npublic void changePermission(String mod, String path) throws Exception &#123;\n &#x2F;&#x2F; ProcessBuilder processBuilder &#x3D; new ProcessBuilder(&quot;chmod&quot;, &quot;775&quot;, &quot;&#x2F;data&#x2F;a.txt&quot;);\n ProcessBuilder processBuilder &#x3D; new ProcessBuilder(&quot;chmod&quot;, mod, path);\n Process process &#x3D; processBuilder.start();\n int exitCode &#x3D; process.waitFor();\n if (exitCode &#x3D;&#x3D; 0) &#123;\n System.out.println(&quot;File permission changed successfully!&quot;);\n &#125; else &#123;\n System.out.println(&quot;Failed to change file permission.&quot;);\n &#125;\n&#125;</code></pre>\n<h2 id=\"7、查询服务器磁盘空间\"><a href=\"#7、查询服务器磁盘空间\" class=\"headerlink\" title=\"7、查询服务器磁盘空间\"></a>7、查询服务器磁盘空间</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;**\n * 查询服务器磁盘空间\n *\n * @return map\n *&#x2F;\npublic Map&lt;String, String&gt; getDiskInfo() &#123;\n &#x2F;&#x2F; 总空间\n long totalSpace &#x3D; 0;\n &#x2F;&#x2F; 已用空间\n long usableSpace &#x3D; 0;\n &#x2F;&#x2F; 可用空间\n long unallocatedSpace &#x3D; 0;\n for (FileStore fileStore : FileSystems.getDefault().getFileStores()) &#123;\n try &#123;\n totalSpace +&#x3D; fileStore.getTotalSpace();\n usableSpace +&#x3D; fileStore.getUsableSpace();\n unallocatedSpace +&#x3D; fileStore.getUnallocatedSpace();\n &#125; catch (IOException e) &#123;\n throw new RuntimeException(e);\n &#125;\n &#125;\n DecimalFormat decimalFormat &#x3D; new DecimalFormat(&quot;#.00&quot;);\n Map&lt;String, String&gt; map &#x3D; new HashMap&lt;&gt;(3);\n map.put(&quot;totalSpace&quot;, decimalFormat.format(totalSpace &#x2F; (1024.0 * 1024 * 1024)));\n map.put(&quot;usableSpace&quot;, decimalFormat.format(usableSpace &#x2F; (1024.0 * 1024 * 1024)));\n map.put(&quot;unallocatedSpace&quot;, decimalFormat.format(unallocatedSpace &#x2F; (1024.0 * 1024 * 1024)));\n return map;\n&#125;</code></pre>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"canvas","slug":"canvas","date":"2023-08-10T00:58:09.000Z","updated":"2023-08-10T01:56:36.673Z","comments":true,"path":"/post/canvas/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>近期,工作中有一个功能,需要在页面上展示在图片上面绘制区域的功能,在网上找了找,发现了这个<code>canvas</code>。</p>\n<p>另外,通过资料的查询,发现这个<code>canvas</code>可以替代<code>flash</code>,常见的<code>flash</code>应用场景可以用<code>canvas</code>配合<code>audio</code>。</p>\n<h1 id=\"canvas特点\"><a href=\"#canvas特点\" class=\"headerlink\" title=\"canvas特点\"></a>canvas特点</h1><ul>\n<li>无需浏览器安装插件</li>\n<li>性能高</li>\n<li>使用JavaScript操作Canvas</li>\n<li>依赖像素,适合动态渲染和大数据量绘制</li>\n<li>更适合移动端</li>\n<li>安全性更好</li>\n</ul>\n<h1 id=\"canvas能做什么\"><a href=\"#canvas能做什么\" class=\"headerlink\" title=\"canvas能做什么\"></a>canvas能做什么</h1><ul>\n<li><b>游戏</b>游戏在HTML5领域具有举足轻重的地位。HTML5在基于Web图像显示方面比Flash更加立体、更加精巧Ohad认为运用Canvas制作的图像能够令HTML5游戏在流畅度和跨平台方面发挥更大的潜力。</li>\n<li><b>图表制作</b>图表制作时常被人们忽略但无论企业内部还是企业间交流合作都离不开图表。现在一些开发者使用HTML/CSS完成图表制作但Ohad认为大家完全可以用Canvas来实现。当然使用SVG可缩放矢量图形来完成图表制作也是非常好的方法。</li>\n<li><b>Banner广告</b>Flash曾经辉煌的时代智能手机还未曾出现。现在以及未来的智能机时代HTML5技术能够在banner广告上发挥巨大作用用Canvas实现动态的广告效果再合适不过。</li>\n<li><b>模拟器</b>Ohad认为无论从视觉效果还是核心功能方面来说模拟器产品可以完全由JavaScript来实现。</li>\n<li><b>远程计算机控制</b>,Canvas可以让开发者更好地实现基于Web的数据传输构建一个完美的可视化控制界面。</li>\n<li><b>字体设计</b>,对于字体的自定义渲染将完全可以基于Web使用HTML5技术进行实现。</li>\n<li><b>图形编辑器</b>,Ohad预测图形编辑器将能够100%基于Web实现。</li>\n<li><b>其他可嵌入网站的内容</b>,类似图表、音频、视频还有许多元素能够更好地与Web融合并且不需要任何插件。Ohad呼吁大家继续挖掘Canvas的潜力运用HTML5技术创造更多价值。</li>\n</ul>\n","categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"}]},{"title":"群晖nas为PHP配置Redis扩展","slug":"nasPhpRedis","date":"2023-07-27T02:12:03.000Z","updated":"2023-07-27T02:52:26.368Z","comments":true,"path":"/post/nasPhpRedis/","link":"","excerpt":"","content":"<p>首先,介绍下我的环境</p>\n<ul>\n<li><p>机器群晖920+</p>\n</li>\n<li><p>PHP版本7.4(套件安装的)</p>\n</li>\n<li><p>系统群晖7.2</p>\n</li>\n</ul>\n<p>接下来,进入正题</p>\n<p>首先要使用ssh进入到群晖账户要切换到root用户</p>\n<p>接下来看下目前PHP7.4有哪些扩展,根据你安装位置的硬盘不同,<code>volume1</code>可能有所区别,命令如下:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">ll &#x2F;volume1&#x2F;@appstore&#x2F;PHP7.4&#x2F;usr&#x2F;local&#x2F;lib&#x2F;php74&#x2F;modules</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nasPhpRedis/2023-07-27-10-26-27-image.png\" alt=\"\"></p>\n<p>从上图中我发现套件版的PHP7.4默认已经有了Redis扩展接下来再看看配置文件中是否配置了Redis当然我这边是没有配置</p>\n<p>打开配置文件<code>php-fpm.ini</code>,我这边喜欢用<code>vi</code>命令,当然也可以使用<code>vim</code>,具体用哪一个看你系统支持已经个人喜好了,下面的<code>volume1</code>一样有区别的自行修改</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;volume1&#x2F;@appstore&#x2F;PHP7.4&#x2F;misc&#x2F;php-fpm.ini</code></pre>\n<p>将下面的代码放到配置文件<code>php-fpm.ini</code>末尾,然后保存退出</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">[Redis]\nextension_dir &#x3D; &quot;&#x2F;volume1&#x2F;@appstore&#x2F;PHP7.4&#x2F;usr&#x2F;local&#x2F;lib&#x2F;php74&#x2F;modules&#x2F;&quot;\nextension &#x3D; redis.so</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nasPhpRedis/2023-07-27-10-46-52-image.png\" alt=\"\"></p>\n<p>扩展有了配置文件也加上了最后就是重启PHP7.4了,命令如下:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">synopkg restart PHP7.4</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nasPhpRedis/2023-07-27-10-48-36-image.png\" alt=\"\"></p>\n<p>看到重启成功了,至此,完成收工了</p>\n","categories":[{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/categories/nas/"}],"tags":[{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/tags/nas/"}]},{"title":"p5-01-set","slug":"p5-01-collection","date":"2023-07-25T06:22:23.000Z","updated":"2023-08-10T00:57:12.547Z","comments":true,"path":"/post/p5-01-collection/","link":"","excerpt":"","content":"","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"P5笔记","slug":"java/P5笔记","permalink":"https://hexo.huangge1199.cn/categories/java/P5%E7%AC%94%E8%AE%B0/"}],"tags":[{"name":"P5笔记","slug":"P5笔记","permalink":"https://hexo.huangge1199.cn/tags/P5%E7%AC%94%E8%AE%B0/"}]},{"title":"P5学习笔记01-Java核心-数据结构","slug":"p5-01-structure","date":"2023-07-25T05:33:52.000Z","updated":"2023-07-25T06:02:00.695Z","comments":true,"path":"/post/p5-01-structure/","link":"","excerpt":"","content":"<p>常用的数据结构:</p>\n<ul>\n<li><p>数组</p>\n</li>\n<li><p>链表</p>\n</li>\n<li><p>树</p>\n</li>\n</ul>\n<h1 id=\"数组\"><a href=\"#数组\" class=\"headerlink\" title=\"数组\"></a>数组</h1><p>特点:</p>\n<ul>\n<li><p>内存地址连续</p>\n</li>\n<li><p>可以通过下标的成员访问 , 下标访问的性能高</p>\n</li>\n<li><p>增删操作带来更大的性能消耗 ( 保证数据越界的问题 , 需动态扩容 )</p>\n</li>\n</ul>\n<h1 id=\"链表\"><a href=\"#链表\" class=\"headerlink\" title=\"链表\"></a>链表</h1><p>特点:</p>\n<ul>\n<li><p>灵活的空间要求,存储空间不要连续</p>\n</li>\n<li><p>不支持下标的访问,支持顺序的遍历搜索</p>\n</li>\n<li><p>针对增删操作找到对应的节点改变链表的头尾指向即可,无需移动元素存储位置</p>\n</li>\n</ul>\n<h1 id=\"树\"><a href=\"#树\" class=\"headerlink\" title=\"树\"></a>树</h1><p>包括:</p>\n<ul>\n<li><p>二叉树</p>\n</li>\n<li><p>红黑树</p>\n</li>\n</ul>\n<h2 id=\"二叉树\"><a href=\"#二叉树\" class=\"headerlink\" title=\"二叉树\"></a>二叉树</h2><p>特点:</p>\n<ul>\n<li><p>某节点的左子树节点值仅包含小于该节点值</p>\n</li>\n<li><p>某节点的右子树节点值仅包含大于该节点值</p>\n</li>\n<li><p>左右子树也必须是二叉查找树</p>\n</li>\n<li><p>顺序排列</p>\n</li>\n</ul>\n<p>不平衡二叉树:</p>\n<ul>\n<li>查询效率不高</li>\n</ul>\n<h2 id=\"红黑树\"><a href=\"#红黑树\" class=\"headerlink\" title=\"红黑树\"></a>红黑树</h2><p>是一个自平衡的二叉查找树,树上的每个节点都遵循下面的规则:</p>\n<ul>\n<li><p>每个节点要么是黑色,要么是红色</p>\n</li>\n<li><p>根节点是黑色</p>\n</li>\n<li><p>每个叶子节点是黑色</p>\n</li>\n<li><p>每个红色节点的两个子节点一定是黑色</p>\n</li>\n<li><p>任意一节点到每个叶子节点的路径都包含数量相同的黑节点</p>\n</li>\n</ul>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"P5笔记","slug":"java/P5笔记","permalink":"https://hexo.huangge1199.cn/categories/java/P5%E7%AC%94%E8%AE%B0/"}],"tags":[{"name":"P5笔记","slug":"P5笔记","permalink":"https://hexo.huangge1199.cn/tags/P5%E7%AC%94%E8%AE%B0/"}]},{"title":"deepin中steam的配置","slug":"steamByDeepin","date":"2023-06-24T05:34:05.000Z","updated":"2023-07-25T05:29:46.270Z","comments":true,"path":"/post/steamByDeepin/","link":"","excerpt":"","content":"<h1 id=\"deepin中steam的配置\"><a href=\"#deepin中steam的配置\" class=\"headerlink\" title=\"deepin中steam的配置\"></a>deepin中steam的配置</h1><p>本人的deepin系统已经更新到20.9,文章仅供参考,可能会与你的情况有所出入</p>\n<h1 id=\"下载安装\"><a href=\"#下载安装\" class=\"headerlink\" title=\"下载安装\"></a>下载安装</h1><p>在deepin的应用商店中下载安装steam</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624125037-advf2v5.png\" alt=\"image\"></p>\n<h1 id=\"中文设置\"><a href=\"#中文设置\" class=\"headerlink\" title=\"中文设置\"></a>中文设置</h1><p>我这边安装完默认是英文界面可以依次点击左上角是steam—》settings</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624125532-2i70ung.png\" alt=\"image\"></p>\n<p>在弹出的页面中点击左侧Interface右侧按照红框内容选择简体中文</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624125628-haoo17i.png\" alt=\"image\"></p>\n<p>然后在点击重启按钮即可</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624125826-24e5l7j.png\" alt=\"image\"></p>\n<p>重启后界面已经是中文的啦</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624130025-64dih9w.png\" alt=\"image\"></p>\n<h1 id=\"兼容大多数的游戏\"><a href=\"#兼容大多数的游戏\" class=\"headerlink\" title=\"兼容大多数的游戏\"></a>兼容大多数的游戏</h1><p>依次点击左上角的steam—&gt;设置(英文版setting)—&gt;弹出页面的兼容性将红框的内容都设置完在一起重启Proton那个下拉框选择最新的就好我现在是8.0-2最新也许你的并不一定是。</p>\n<p><img src=\"https://img.huangge1199.cn/blog/steamByDeepin/image-20230624130924-772dq4m.png\" alt=\"image\"></p>\n<p>重启后,你就发现之前不能玩的大多数游戏都可以玩了</p>\n","categories":[{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/categories/deepin/"},{"name":"游戏","slug":"deepin/游戏","permalink":"https://hexo.huangge1199.cn/categories/deepin/%E6%B8%B8%E6%88%8F/"}],"tags":[{"name":"游戏","slug":"游戏","permalink":"https://hexo.huangge1199.cn/tags/%E6%B8%B8%E6%88%8F/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"浏览器不走代理Proxifier问题解决","slug":"proxifier-proxy-fix","date":"2023-06-20T05:47:50.000Z","updated":"2023-06-20T07:50:18.052Z","comments":true,"path":"/post/proxifier-proxy-fix/","link":"","excerpt":"","content":"<p>环境需要用到代理软件Proxifier但配好后chrome浏览器访问对应代理的应用却不行之前还明明可以的今天就突然不行了于是乎我去排查了原因本篇文章就是我排查的记录吧最后问题是解决了。每个人的情况不同可能我的办法不一定适用于你的因此本篇文章仅做参考。</p>\n<h1 id=\"确认Proxifier设置\"><a href=\"#确认Proxifier设置\" class=\"headerlink\" title=\"确认Proxifier设置\"></a>确认Proxifier设置</h1><ol>\n<li><p>打开Proxifier选择菜单栏的“Profile” - “Proxification Rules”。</p>\n</li>\n<li><p>在“Proxification Rules”中确认走代理的应用程序包含浏览器。如果不包含可单击右键选择“Edit Selected Rule”在“Edit Rule”中设置“Any”为“Applications”后点击OK。</p>\n<h1 id=\"确认系统代理设置\"><a href=\"#确认系统代理设置\" class=\"headerlink\" title=\"确认系统代理设置\"></a>确认系统代理设置</h1><p>首先说明一下本人是Win11的系统可能会与你的有出入下面是详细步骤</p>\n</li>\n<li><p>点击电脑的开始菜单,打开设置。</p>\n</li>\n<li><p>点击左侧的“网络和Internet”再点击右侧的代理。</p>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/proxifier-proxy-fix/2023-06-20-15-45-42-image.png\" alt=\"\"></p>\n<ol>\n<li>确认页面中红框的内容全是关闭状态,如果不是,改为关闭状态</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/proxifier-proxy-fix/2023-06-20-15-46-58-image.png\" alt=\"\"></p>\n","categories":[{"name":"问题记录","slug":"问题记录","permalink":"https://hexo.huangge1199.cn/categories/%E9%97%AE%E9%A2%98%E8%AE%B0%E5%BD%95/"},{"name":"网站建设","slug":"问题记录/网站建设","permalink":"https://hexo.huangge1199.cn/categories/%E9%97%AE%E9%A2%98%E8%AE%B0%E5%BD%95/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}],"tags":[{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/tags/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}]},{"title":"使用xlsxwriter和openplxl库操作Excel文件","slug":"pyHighExcel","date":"2023-05-31T03:13:46.000Z","updated":"2023-05-31T06:08:44.414Z","comments":true,"path":"/post/pyHighExcel/","link":"","excerpt":"","content":"<p>Excel文件是一种广泛使用的电子表格格式用于存储和处理各种数据。在Python中有多个库可以用于处理Excel文件其中包括xlsxwriter和openplxl两个库。本文将介绍这两个库的使用方法以及如何使用它们来操作Excel文件。</p>\n<h1 id=\"1、xlsxwriter生成Excel文件\"><a href=\"#1、xlsxwriter生成Excel文件\" class=\"headerlink\" title=\"1、xlsxwriter生成Excel文件\"></a>1、xlsxwriter生成Excel文件</h1><p>xlsxwriter是一个用于生成Excel文件的Python库支持多种格式的Excel文件(如.xlsx、.xlsm、.xltx、.xltm等),并且支持自定义样式和格式。下面将以一个简单的示例来逐步介绍如何使用xlsxwriter库创建一个Excel文件并写入数据</p>\n<h2 id=\"1-1、导入库并创建Excel文件\"><a href=\"#1-1、导入库并创建Excel文件\" class=\"headerlink\" title=\"1.1、导入库并创建Excel文件\"></a>1.1、导入库并创建Excel文件</h2><p>Excel文件名为xlsxwriter插入数据和折线图.xlsx</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import xlsxwriter, random\n\nwb &#x3D; xlsxwriter.Workbook(&#39;xlsxwriter插入数据和折线图.xlsx&#39;)</code></pre>\n<h2 id=\"1-2、创建一个sheet页\"><a href=\"#1-2、创建一个sheet页\" class=\"headerlink\" title=\"1.2、创建一个sheet页\"></a>1.2、创建一个sheet页</h2><p>sheet标签页名字为sheet1</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">worksheet1 &#x3D; wb.add_worksheet(&#39;sheet1&#39;)</code></pre>\n<h2 id=\"1-3、按行写入数据\"><a href=\"#1-3、按行写入数据\" class=\"headerlink\" title=\"1.3、按行写入数据\"></a>1.3、按行写入数据</h2><p>这里以写入Excel的头部数据为例</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">headings &#x3D; [&#39;日期&#39;,&#39;数据1&#39;,&#39;数据2&#39;]\nworksheet1.write_row(&#39;A1&#39;,headings)</code></pre>\n<h2 id=\"1-4、按列写入数据\"><a href=\"#1-4、按列写入数据\" class=\"headerlink\" title=\"1.4、按列写入数据\"></a>1.4、按列写入数据</h2><p>有了头部数据后,该写入下面的实际数据了</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\"># 创造数据\ndata &#x3D; [\n [&#39;2019-1&#39;,&#39;2019-2&#39;,&#39;2019-3&#39;,&#39;2019-4&#39;,&#39;2019-5&#39;,&#39;2019-6&#39;,&#39;2019-7&#39;,&#39;2019-8&#39;,&#39;2019-9&#39;,&#39;2019-10&#39;,&#39;2019-11&#39;,&#39;2019-12&#39;,],\n [random.randint(1,100) for i in range(12)],\n [random.randint(1,100) for i in range(12)],\n] \n# 按列写入数据\nworksheet1.write_column(&#39;A2&#39;,data[0])\nworksheet1.write_column(&#39;B2&#39;,data[1])\nworksheet1.write_column(&#39;C2&#39;,data[2])</code></pre>\n<h2 id=\"1-5、新建图表对象\"><a href=\"#1-5、新建图表对象\" class=\"headerlink\" title=\"1.5、新建图表对象\"></a>1.5、新建图表对象</h2><p>折线图表的定义:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">chart_col &#x3D; wb.add_chart(&#123;&#39;type&#39;:&#39;line&#39;&#125;)</code></pre>\n<h2 id=\"1-6、图表数据配置\"><a href=\"#1-6、图表数据配置\" class=\"headerlink\" title=\"1.6、图表数据配置\"></a>1.6、图表数据配置</h2><p>这里的数据有两条一个是数据1一个是数据2所以图表添加数据的代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">chart_col.add_series(\n &#123;\n &#39;name&#39;:&#39;&#x3D;sheet1!$B$1&#39;,\n &#39;categoies&#39;:&#39;&#x3D;sheet1!$A$2:$A$7&#39;,\n &#39;values&#39;: &#39;&#x3D;sheet1!$B$2:$B$7&#39;,\n &#39;line&#39;: &#123;&#39;color&#39;: &#39;blue&#39;&#125;,\n &#125;\n)\nchart_col.add_series(\n &#123;\n &#39;name&#39;:&#39;&#x3D;sheet1!$C$1&#39;,\n &#39;categories&#39;:&#39;&#x3D;sheet1!$A$2:$A$7&#39;,\n &#39;values&#39;: &#39;&#x3D;sheet1!$C$2:$C$7&#39;,\n &#39;line&#39;: &#123;&#39;color&#39;: &#39;green&#39;&#125;,\n &#125;\n)\n</code></pre>\n<p>有两条数据,所以添加了两次。</p>\n<p>数据有四项数据名、具体值对应的横坐标categories、具体值对应的纵坐标values、折线颜色其中取值方式直接是使用sheet的坐标形式例如name是B1和B2categories都是A2-A7值分别是B2-B7和C2-C7。</p>\n<h2 id=\"1-7、完成图表\"><a href=\"#1-7、完成图表\" class=\"headerlink\" title=\"1.7、完成图表\"></a>1.7、完成图表</h2><p>数据添加之后在设置下坐标的相关信息就是标题、x轴、y轴的名字以及图表位置和大小代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">chart_col.set_title(&#123;&#39;name&#39;:&#39;虚假数据折线图&#39;&#125;)\nchart_col.set_x_axis(&#123;&#39;name&#39;:&quot;横坐标&quot;&#125;)\nchart_col.set_y_axis(&#123;&#39;name&#39;:&#39;纵坐标&#39;&#125;)\n\nworksheet1.insert_chart(&#39;D2&#39;,chart_col,&#123;&#39;x_offset&#39;:25,&#39;y_offset&#39;:10&#125;)\n\nwb.close()</code></pre>\n<p>图表的位置和大小是根据左上角的起始表格和x和y的偏移计算的。</p>\n<p>代码中是从D2做左上角起始然后x和y分别便宜25和10个单位得到了图片的最终大小。最后关闭wb。</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pyHighExcel/2023-05-31-13-51-38-image.png\" alt=\"\"></p>\n<h1 id=\"2、openpyxl追加Excel数据\"><a href=\"#2、openpyxl追加Excel数据\" class=\"headerlink\" title=\"2、openpyxl追加Excel数据\"></a>2、openpyxl追加Excel数据</h1><p>openplxl是一个用于读取现有的Excel文件的Python库支持多种格式的Excel文件(如.xlsx、.xlsm、.xltx、.xltm等),并且支持读取单元格的数据。</p>\n<h2 id=\"2-1、打开文件\"><a href=\"#2-1、打开文件\" class=\"headerlink\" title=\"2.1、打开文件\"></a>2.1、打开文件</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import openpyxl\nfilename &#x3D; &#39;xlsxwriter插入数据和折线图.xlsx&#39;\nwb &#x3D; openpyxl.load_workbook(filename)</code></pre>\n<h2 id=\"2-2、拷贝sheet\"><a href=\"#2-2、拷贝sheet\" class=\"headerlink\" title=\"2.2、拷贝sheet\"></a>2.2、拷贝sheet</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">sheet1 &#x3D; wb[&#39;sheet1&#39;]\n# 拷贝sheet1\nsheet2 &#x3D; wb.copy_worksheet(sheet1)\n# 设置拷贝后的名称为sheet2\nsheet2.title &#x3D; &quot;sheet2&quot;</code></pre>\n<h2 id=\"2-3、追加数据内容\"><a href=\"#2-3、追加数据内容\" class=\"headerlink\" title=\"2.3、追加数据内容\"></a>2.3、追加数据内容</h2><p>在sheet2中数据1和数据2追加一年的数据代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\"># 读取最后一行\nrows &#x3D; sheet2.max_row\n# 取出时间的字符串\nprev_date_str &#x3D; sheet2.cell(row&#x3D;rows,column&#x3D;1).value\n# 时间字符串转时间对象\nprev_date &#x3D; datetime.datetime.strptime(prev_date_str, &quot;%Y-%m&quot;)\nfor i in range(1,13):\n # 月份的计算每次增加一个月就得到了第二年的12个月\n tmp_date &#x3D; prev_date + relativedelta(months&#x3D;i)\n tmp_num1 &#x3D; random.randint(1,100)\n tmp_num2 &#x3D; random.randint(1,100)\n sheet2.append([tmp_date.strftime(&quot;%Y-%m&quot;), tmp_num1, tmp_num2])</code></pre>\n<p>实现思路:</p>\n<ul>\n<li>读取出最后一行</li>\n<li>取出时间字符串,然后转换成时间对象</li>\n<li>一年12个月循环12次每次增加一个月数值可以随机的生成用random即可</li>\n<li>数据的追加,是按每行,所以将【时间, 数据1 数据2】通过append直接追加到数据最后即可</li>\n</ul>\n<h2 id=\"2-4、使用openpyxl画图表\"><a href=\"#2-4、使用openpyxl画图表\" class=\"headerlink\" title=\"2.4、使用openpyxl画图表\"></a>2.4、使用openpyxl画图表</h2><p>在sheet2中对全部数据画折线图</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from openpyxl.chart import Series,LineChart, Reference\n# 图表对象\nchart &#x3D; LineChart()\nrows &#x3D; sheet2.max_row\n\n# 创建series对象\ndata1 &#x3D; Reference(sheet2, min_col&#x3D;2, min_row&#x3D;1, max_col&#x3D;2, max_row&#x3D;rows) #涉及数据\ntitle1 &#x3D; sheet2.cell(row&#x3D;1,column&#x3D;2).value\nseriesObj1 &#x3D; Series(data1, title&#x3D;title1)\n\n# 创建series对象\ndata2 &#x3D; Reference(sheet2, min_col&#x3D;3, min_row&#x3D;1, max_col&#x3D;3, max_row&#x3D;rows) #涉及数据\ntitle2 &#x3D; sheet2.cell(row&#x3D;1,column&#x3D;3).value\nseriesObj2 &#x3D; Series(data2, title&#x3D;title2)\n\n# 添加到chart中\nchart.append(seriesObj1)\nchart.append(seriesObj2)\n\n# 将图表添加到 sheet中\nsheet2.add_chart(chart, &quot;E3&quot;)\n\n# 保存Excel\nwb.save(&#39;poenpyxl插入数据和折线图[copy xlsxwriter].xlsx&#39;)</code></pre>\n<p>导入所需的画图工具,图表初始化,然后生成数据对象:</p>\n<ul>\n<li>data1的生成因为索引从1开始所以标题是第一行第二列数据是第二行第二列一直到最后一行第二列</li>\n<li>data2的生成因为索引从1开始所以标题是第一行第三列数据是第二行第三列一直到第二行最后三列</li>\n<li>将两个数据都放到图表内</li>\n<li>然后图表的开始位置设置成E3数据在ABCE是空的3距离顶部有两格的位置</li>\n</ul>\n<p>最后文件保存,大功告成。 </p>\n<p><img src=\"https://img.huangge1199.cn/blog/pyHighExcel/2023-05-31-14-04-47-image.png\" alt=\"\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/pyHighExcel/2023-05-31-14-05-20-image.png\" alt=\"\"></p>\n<h1 id=\"3、总结\"><a href=\"#3、总结\" class=\"headerlink\" title=\"3、总结\"></a>3、总结</h1><p>本文介绍了如何使用xlsxwriter和openplxl两个库来操作Excel文件。xlsxwriter库可以用于创建新的Excel文件并写入数据而openplxl库则可以用于读取现有的Excel文件并读取单元格的数据。这些库都是Python中处理Excel文件的好工具可以帮助我们更加高效地处理各种数据。</p>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"如何使用Python操作Excel文件看这篇博客就够了","slug":"pyExcel","date":"2023-05-30T06:09:15.000Z","updated":"2023-05-30T06:23:25.121Z","comments":true,"path":"/post/pyExcel/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>如何使用Python操作Excel文件看这篇博客就够了</p>\n<p>在工作中我们经常需要处理和分析数据。而Excel作为一种广泛使用的数据分析工具被很多人所熟知。但是对于一些非技术背景的用户来说如何操作Excel却可能有些困难。这时候Python就成为了一种非常有用的工具。</p>\n<p>本文将介绍如何使用Python对Excel文件进行读写操作。首先我们将介绍Python中可以使用的第三方库<code>xlrd</code>、<code>xlwt</code>和<code>xlutils</code>,并通过示例来展示“如何使用<code>xlwt</code>库来将数据写入到Excel文件中”、“如何使用<code>xlrd</code>库来读取一个Excel文件的数据”和“如何使用三个库的配合来进行一边读取一边写入的操作”。</p>\n<p>通过本文的介绍,你将会了解到:</p>\n<ul>\n<li>如何获取单元格的值;</li>\n<li>如何遍历整个工作表;</li>\n<li>如何创建新的工作表和单元格,并将数据写入到单元格中;</li>\n<li>如何使用<code>save()</code>方法保存Excel文件到磁盘上。</li>\n</ul>\n<p>如果你想学习如何使用Python操作Excel文件那么这篇文章就是为你准备的。希望它能帮助你更好地理解和应用这个工具。</p>\n<h1 id=\"1、写入Excel文件\"><a href=\"#1、写入Excel文件\" class=\"headerlink\" title=\"1、写入Excel文件\"></a>1、写入Excel文件</h1><p>首先来学习下随机生成数据写入一个Excel文件并保存所使用到的库是xlwt安装命令<code>pip install xlwt</code> ,安装简单方便,无依赖,很快。</p>\n<h2 id=\"1-1、新建一个WorkBook对象\"><a href=\"#1-1、新建一个WorkBook对象\" class=\"headerlink\" title=\"1.1、新建一个WorkBook对象\"></a>1.1、新建一个WorkBook对象</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import xlwt\nwb &#x3D; xlwt.Workbook()</code></pre>\n<h2 id=\"1-2、新建sheet\"><a href=\"#1-2、新建sheet\" class=\"headerlink\" title=\"1.2、新建sheet\"></a>1.2、新建sheet</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">sheet &#x3D; wb.add_sheet(&#39;第一个sheet&#39;)</code></pre>\n<h2 id=\"1-3、写数据\"><a href=\"#1-3、写数据\" class=\"headerlink\" title=\"1.3、写数据\"></a>1.3、写数据</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">head_data &#x3D; [&#39;姓名&#39;,&#39;地址&#39;,&#39;手机号&#39;,&#39;城市&#39;]\nfor head in head_data:\n sheet.write(0,head_data.index(head),head)</code></pre>\n<p><code>write</code>函数写入分别是x行 x列 数据头部数据永远是第一行所以第0行。数据的列则是当前数据所在列表的索引直接使用index函数即可。</p>\n<h2 id=\"1-4、创建虚假数据\"><a href=\"#1-4、创建虚假数据\" class=\"headerlink\" title=\"1.4、创建虚假数据\"></a>1.4、创建虚假数据</h2><p>有了头部数据,现在就开始写入内容了,分别是随机姓名 随机地址 随机号码 随机城市数据的来源都是faker库一个专门创建虚假数据用来测试的库安装命令<code>pip install faker</code>。</p>\n<p>因为头部信息已经写好所以接下来是从第1行开始写数据每行四个数据准备写99个用户数据所以用循环循环99次代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import faker\nfake &#x3D; faker.Faker()\nfor i in range(1,100):\n sheet.write(i,0,fake.first_name() + &#39; &#39; + fake.last_name())\n sheet.write(i,1,fake.address())\n sheet.write(i,2,fake.phone_number())\n sheet.write(i,3,fake.city())</code></pre>\n<h2 id=\"1-5、保存成xls文件\"><a href=\"#1-5、保存成xls文件\" class=\"headerlink\" title=\"1.5、保存成xls文件\"></a>1.5、保存成xls文件</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">wb.save(&#39;虚假用户数据.xls&#39;)</code></pre>\n<p>然后找到文件使用office或者wps打开这个xls文件</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pyExcel/2023-05-30-14-15-53-image.png\" alt=\"\"></p>\n<h1 id=\"2、读取Excel文件\"><a href=\"#2、读取Excel文件\" class=\"headerlink\" title=\"2、读取Excel文件\"></a>2、读取Excel文件</h1><p>写文件已经搞定接下来就要学习下Excel的读操作读取Excel的库是xlrd对应readxlrd的安装命令<code>pip install xlrd</code></p>\n<h2 id=\"2-1、打开Excel文件\"><a href=\"#2-1、打开Excel文件\" class=\"headerlink\" title=\"2.1、打开Excel文件\"></a>2.1、打开Excel文件</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import xlrd\nwb &#x3D; xlrd.open_workbook(&#39;虚假用户数据.xls&#39;)</code></pre>\n<h2 id=\"2-2、读取Excel数据\"><a href=\"#2-2、读取Excel数据\" class=\"headerlink\" title=\"2.2、读取Excel数据\"></a>2.2、读取Excel数据</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\"># 获取文件中全部的sheet返回结构是list。\nsheets &#x3D; wb.sheets()\n# 通过索引顺序获取。\nsheet &#x3D; sheets[0]\n# 直接通过索引顺序获取。\nsheet &#x3D; wb.sheet_by_index(0)\n# 通过名称获取。\nsheet &#x3D; wb.sheet_by_name(&#39;第一个sheet&#39;)</code></pre>\n<h2 id=\"2-3、打印数据\"><a href=\"#2-3、打印数据\" class=\"headerlink\" title=\"2.3、打印数据\"></a>2.3、打印数据</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\"># 获取行数\nrows &#x3D; sheet.nrows\n# 获取列数\ncols &#x3D; sheet.ncols\nfor row in range(rows):\n for col in range(cols):\n print(sheet.cell(row,col).value,end&#x3D;&#39; , &#39;)\n print(&#39;\\n&#39;)</code></pre>\n<p>打印效果(只截取部分):</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pyExcel/2023-05-30-14-14-29-image.png\" alt=\"\"></p>\n<h1 id=\"3、在现有的Excel文件中追加内容\"><a href=\"#3、在现有的Excel文件中追加内容\" class=\"headerlink\" title=\"3、在现有的Excel文件中追加内容\"></a>3、在现有的Excel文件中追加内容</h1><p>需求:往“虚假用户数据.xls”里面追加额外的50条用户数据就是标题+数据达到150条。</p>\n<h2 id=\"3-1、导入库\"><a href=\"#3-1、导入库\" class=\"headerlink\" title=\"3.1、导入库\"></a>3.1、导入库</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import xlrd\nfrom xlutils.copy import copy</code></pre>\n<h2 id=\"3-2、使用xlrd打开文件然后xlutils赋值打开后的workbook\"><a href=\"#3-2、使用xlrd打开文件然后xlutils赋值打开后的workbook\" class=\"headerlink\" title=\"3.2、使用xlrd打开文件然后xlutils赋值打开后的workbook\"></a>3.2、使用xlrd打开文件然后xlutils赋值打开后的workbook</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">wb &#x3D; xlrd.open_workbook(&#39;虚假用户数据.xls&#39;,formatting_info&#x3D;True)\nxwb &#x3D; copy(wb)</code></pre>\n<h2 id=\"3-3、有了workbook之后就开始指定sheet并获取这个sheet的总行数\"><a href=\"#3-3、有了workbook之后就开始指定sheet并获取这个sheet的总行数\" class=\"headerlink\" title=\"3.3、有了workbook之后就开始指定sheet并获取这个sheet的总行数\"></a>3.3、有了workbook之后就开始指定sheet并获取这个sheet的总行数</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">sheet &#x3D; xwb.get_sheet(&#39;第一个sheet&#39;)\nrows &#x3D; sheet.get_rows()</code></pre>\n<p>指定名称为“第一个sheet”的sheet然后获取全部的行</p>\n<h2 id=\"3-4、有了具体的行数然后保证原有数据不变动的情况下从第101行写数据\"><a href=\"#3-4、有了具体的行数然后保证原有数据不变动的情况下从第101行写数据\" class=\"headerlink\" title=\"3.4、有了具体的行数然后保证原有数据不变动的情况下从第101行写数据\"></a>3.4、有了具体的行数然后保证原有数据不变动的情况下从第101行写数据</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import faker\nfake &#x3D; faker.Faker()\nfor i in range(len(rows),150):\n sheet.write(i,0,fake.first_name() + &#39; &#39; + fake.last_name())\n sheet.write(i,1,fake.address())\n sheet.write(i,2,fake.phone_number())\n sheet.write(i,3,fake.city())</code></pre>\n<p>range函数从len(rows)开始到150-1结束共50条。 faker库是制造虚假数据的这个在前面写数据有用过循环写入了50条。</p>\n<h2 id=\"3-5、最后保存就可以了\"><a href=\"#3-5、最后保存就可以了\" class=\"headerlink\" title=\"3.5、最后保存就可以了\"></a>3.5、最后保存就可以了</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">xwb.save(&#39;虚假用户数据.xls&#39;)</code></pre>\n<p>使用xwb也就是操作之后的workbook对象直接保存原来的文件名就可以了。</p>\n<h1 id=\"4、总结\"><a href=\"#4、总结\" class=\"headerlink\" title=\"4、总结\"></a>4、总结</h1><p>本文介绍了Python中常用的三个库xlrd、xlwt和xlutils,分别用于读取Excel文件、写入Excel文件和处理Excel文件。这些库都有各自的优点和缺点在实际使用时需要根据具体需求进行选择。</p>\n<p>同时,本文还提供了一些示例代码来演示如何使用这些库。通过这些示例代码,读者可以更好地了解这些库的使用方法和操作步骤。</p>\n<p>最后提醒读者注意在使用这些库时要仔细阅读其文档和API,以避免出现不必要的错误。</p>\n<h1 id=\"5、参考资料\"><a href=\"#5、参考资料\" class=\"headerlink\" title=\"5、参考资料\"></a>5、参考资料</h1><ul>\n<li><a href=\"https://www.w3cschool.cn/minicourse/play/pythonwork\">W3Cschool微课Python 自动化办公课程)</a></li>\n<li><a href=\"https://docs.python.org/zh-cn/3/library/xlrd.html\">Python官方文档—xlrd</a></li>\n<li><a href=\"https://docs.python.org/zh-cn/3/library/xlwt.html\">Python官方文档—xlwt</a></li>\n<li><a href=\"https://docs.python.org/zh-cn/3/library/xlutils.html\">Python官方文档—xlutils</a></li>\n</ul>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"从前端到后端:如何在 URL 参数中传递 JSON 数据","slug":"json-url-encoding","date":"2023-04-26T04:53:51.000Z","updated":"2023-04-26T04:59:20.803Z","comments":true,"path":"/post/json-url-encoding/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>在 Web 开发中,我们经常需要将数据作为 URL 参数进行传递。当我们需要传递复杂的数据结构时,如何在前端将其转换为字符串,并在后端正确地解析它呢?本文将介绍如何在前端将 JSON 数据进行 URL 编码,并在后端将其解析为相应的数据类型,同时提供 Java 语言的示例代码。</p>\n<h1 id=\"在前端使用-URL-参数传递-JSON-数据\"><a href=\"#在前端使用-URL-参数传递-JSON-数据\" class=\"headerlink\" title=\"在前端使用 URL 参数传递 JSON 数据\"></a>在前端使用 URL 参数传递 JSON 数据</h1><p>有时候我们需要在前端将 JSON 数据传递给后端,例如通过 AJAX 请求或者页面跳转。URL 参数是一种常见的传递数据的方式,但是由于 URL 参数只支持字符串类型的数据,而 JSON 数据是一种复杂的数据类型,因此需要进行编码和解码操作。</p>\n<p>在 JavaScript 中,我们可以使用 <code>JSON.stringify()</code> 方法将 JSON 对象转换为字符串,然后使用 <code>encodeURIComponent()</code> 方法对字符串进行 URL 编码。以下是一个将 JSON 数据作为 URL 参数发送 AJAX 请求的示例:</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">const data &#x3D; &#123; name: &#39;John&#39;, age: 30 &#125;;\nconst encodedData &#x3D; encodeURIComponent(JSON.stringify(data));\n\nfetch(&#96;&#x2F;api&#x2F;user?data&#x3D;$&#123;encodedData&#125;&#96;)\n .then(response &#x3D;&gt; response.json())\n .then(data &#x3D;&gt; console.log(data))\n .catch(error &#x3D;&gt; console.error(error));</code></pre>\n<p>在上面的示例中,我们首先创建了一个包含两个属性的 JSON 对象 <code>data</code>,然后将其转换为字符串并进行 URL 编码。然后我们使用 <code>fetch()</code> 方法发送一个带有 <code>data</code> 参数的 GET 请求,并在响应中使用 <code>json()</code> 方法将响应体解析为 JSON 对象。</p>\n<h1 id=\"在后端解析-URL-参数\"><a href=\"#在后端解析-URL-参数\" class=\"headerlink\" title=\"在后端解析 URL 参数\"></a>在后端解析 URL 参数</h1><p>在后端中,我们需要解析从前端发送的包含 JSON 数据的 URL 参数。不同的后端语言和框架可能有不同的解析方式,这里以 Node.js 和 Java 为例,介绍如何解析 URL 参数。</p>\n<h2 id=\"在-Node-js-中解析-URL-参数\"><a href=\"#在-Node-js-中解析-URL-参数\" class=\"headerlink\" title=\"在 Node.js 中解析 URL 参数\"></a>在 Node.js 中解析 URL 参数</h2><p>在 Node.js 中,我们可以使用内置的 <code>url</code> 模块来解析 URL 参数,使用 <code>querystring</code> 模块来解析查询字符串参数。以下是一个使用 Node.js 解析 URL 参数的示例:</p>\n<pre class=\"line-numbers language-javascript\" data-language=\"javascript\"><code class=\"language-javascript\">const http &#x3D; require(&#39;http&#39;);\nconst url &#x3D; require(&#39;url&#39;);\nconst querystring &#x3D; require(&#39;querystring&#39;);\n\nconst server &#x3D; http.createServer((req, res) &#x3D;&gt; &#123;\n const parsedUrl &#x3D; url.parse(req.url);\n const parsedQuery &#x3D; querystring.parse(parsedUrl.query);\n\n &#x2F;&#x2F; 解析包含在 &#39;data&#39; 参数中的 JSON 字符串\n const rawData &#x3D; parsedQuery.data;\n const myObject &#x3D; JSON.parse(decodeURIComponent(rawData));\n\n &#x2F;&#x2F; 执行其他操作...\n\n res.writeHead(200, &#123; &#39;Content-Type&#39;: &#39;text&#x2F;plain&#39; &#125;);\n res.end(&#39;Hello World!&#39;);\n&#125;);\n\nserver.listen(3000, () &#x3D;&gt; &#123;\n console.log(&#39;Server running on port 3000&#39;);\n&#125;);</code></pre>\n<p>在上面的示例中,我们首先使用 <code>url.parse()</code> 方法将请求 URL 解析为 URL 对象,然后使用 <code>querystring.parse()</code> 方法将查询字符串参数解析为对象。然后,我们从 <code>data</code> 参数中获取包含 JSON 字符串的原始数据,使用 <code>decodeURIComponent()</code> 解码该字符串,并使用 <code>JSON.parse()</code> 将其解析为 JavaScript 对象。</p>\n<h2 id=\"在-Java-中解析-URL-参数\"><a href=\"#在-Java-中解析-URL-参数\" class=\"headerlink\" title=\"在 Java 中解析 URL 参数\"></a>在 Java 中解析 URL 参数</h2><p>在 Java 中,我们可以使用 <code>java.net.URLDecoder</code> 类和 <code>java.util.Map</code> 接口来解析 URL 参数。以下是一个使用 Java 解析URL 参数的示例:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.io.UnsupportedEncodingException;\nimport java.net.URLDecoder;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Main &#123;\n public static void main(String[] args) throws UnsupportedEncodingException &#123;\n String urlString &#x3D; &quot;http:&#x2F;&#x2F;localhost:3000&#x2F;?data&#x3D;%7B%22name%22%3A%22John%22%2C%22age%22%3A30%7D&quot;;\n String[] urlParts &#x3D; urlString.split(&quot;\\\\?&quot;);\n String query &#x3D; urlParts.length &gt; 1 ? urlParts[1] : &quot;&quot;;\n Map&lt;String, String&gt; queryMap &#x3D; new HashMap&lt;&gt;();\n for (String param : query.split(&quot;&amp;&quot;)) &#123;\n String[] pair &#x3D; param.split(&quot;&#x3D;&quot;);\n String key &#x3D; URLDecoder.decode(pair[0], &quot;UTF-8&quot;);\n String value &#x3D; URLDecoder.decode(pair[1], &quot;UTF-8&quot;);\n queryMap.put(key, value);\n &#125;\n\n &#x2F;&#x2F; 解析包含在 &#39;data&#39; 参数中的 JSON 字符串\n String rawData &#x3D; queryMap.get(&quot;data&quot;);\n String json &#x3D; URLDecoder.decode(rawData, &quot;UTF-8&quot;);\n JSONObject myObject &#x3D; new JSONObject(json);\n\n &#x2F;&#x2F; 执行其他操作...\n &#125;\n&#125;</code></pre>\n<p>在上面的示例中,我们首先将请求 URL 分为基础部分和查询字符串部分,然后将查询字符串参数解析为一个键值对的 Map 对象。然后,我们从 <code>data</code> 参数中获取包含 URL 编码的 JSON 字符串的原始数据,使用 <code>URLDecoder.decode()</code> 解码该字符串,并使用 <code>JSONObject</code> 类将其解析为 Java 对象。</p>\n<h1 id=\"总结\"><a href=\"#总结\" class=\"headerlink\" title=\"总结\"></a>总结</h1><p>在前端使用 URL 参数传递 JSON 数据时,需要先将 JSON 数据转换为字符串并进行 URL 编码。在后端中解析 URL 参数时,需要先将 URL 编码的字符串解码为原始数据,并将其解析为相应的数据类型。不同的后端语言和框架可能有不同的解析方式,但是基本的原理都是相同的。</p>\n","categories":[{"name":"web开发","slug":"web开发","permalink":"https://hexo.huangge1199.cn/categories/web%E5%BC%80%E5%8F%91/"}],"tags":[{"name":"web开发","slug":"web开发","permalink":"https://hexo.huangge1199.cn/tags/web%E5%BC%80%E5%8F%91/"}]},{"title":"选择哪种Web服务器WebLogic vs Undertow vs Tomcat vs Nginx对比分析","slug":"web-server-analysis","date":"2023-04-07T02:41:37.000Z","updated":"2023-04-07T05:30:26.520Z","comments":true,"path":"/post/web-server-analysis/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>WebLogic、Undertow、Tomcat和Nginx是常用的Web服务器和应用程序服务器。它们具有不同的功能、应用场景、优缺点等方面的特点本文将对它们进行详细的比较。</p>\n<h1 id=\"功能比较\"><a href=\"#功能比较\" class=\"headerlink\" title=\"功能比较\"></a>功能比较</h1><p>WebLogic是一个完整的JavaEE应用程序服务器它具有强大的功能和灵活的配置。WebLogic支持分布式应用程序部署、负载均衡、高可用性、安全性等特性适用于大型企业级Java应用程序。</p>\n<p>Undertow是一个轻量级的Web服务器和应用程序服务器它具有高性能和可扩展性的特点。Undertow支持HTTP、HTTPS、AJAX、WebSockets等协议适用于构建高性能、低延迟的Web应用程序。</p>\n<p>Tomcat是一个轻量级的Web服务器和应用程序服务器它具有简单易用的特点。Tomcat支持Servlet、JSP等Java Web开发技术适用于中小型Web应用程序。</p>\n<p>Nginx是一个高性能的Web服务器和反向代理服务器它具有高并发能力、低延迟和高可靠性的特点。Nginx支持负载均衡、反向代理、HTTP缓存等特性适用于构建高性能、高并发、低延迟的Web应用程序。</p>\n<h1 id=\"应用场景比较\"><a href=\"#应用场景比较\" class=\"headerlink\" title=\"应用场景比较\"></a>应用场景比较</h1><p>WebLogic适用于大型企业级Java应用程序例如电子商务、金融服务、电信等行业的应用程序。WebLogic具有出色的可扩展性、高可靠性和安全性适用于对性能、可靠性和安全性有严格要求的应用程序。</p>\n<p>Undertow适用于构建高性能、低延迟的Web应用程序例如在线游戏、金融交易等需要快速响应的应用程序。Undertow具有轻量级、高性能和可扩展性的特点适用于对性能有严格要求的应用程序。</p>\n<p>Tomcat适用于中小型Web应用程序例如博客、社交网络、企业内部应用程序等。Tomcat具有轻量级、易于使用和配置的特点适用于对性能要求不是特别高的应用程序。</p>\n<p>Nginx适用于构建高性能、高并发、低延迟的Web应用程序例如电子商务、社交网络等需要支持大量并发用户访问的应用程序。Nginx具有高性能、高可靠性和可扩展性的特点适用于对性能和可靠性有严格要求的应用程序。</p>\n<h1 id=\"优缺点比较\"><a href=\"#优缺点比较\" class=\"headerlink\" title=\"优缺点比较\"></a>优缺点比较</h1><p>WebLogic的优点是具有出色的可扩展性、高可靠性和安全性。它支持JavaEE规范可以满足大型企业级应用程序的需求。缺点是相对于其他服务器而言比较复杂需要一定的学习成本和配置成本同时也需要更多的硬件资源支持。</p>\n<p>Undertow的优点是轻量级、高性能和可扩展性。它支持多种协议适用于构建高性能、低延迟的Web应用程序。缺点是不支持JavaEE规范无法满足大型企业级应用程序的需求同时也缺乏成熟的生态系统和工具支持。</p>\n<p>Tomcat的优点是轻量级、易于使用和配置。它支持Servlet、JSP等Java Web开发技术适用于中小型Web应用程序。缺点是相对于其他服务器而言功能较为简单不能满足大型企业级应用程序的需求。</p>\n<p>Nginx的优点是高性能、高可靠性和可扩展性。它支持负载均衡、反向代理、HTTP缓存等特性适用于构建高性能、高并发、低延迟的Web应用程序。缺点是不支持JavaEE规范不能直接运行Java应用程序需要结合其他服务器使用。</p>\n<h1 id=\"支持的平台\"><a href=\"#支持的平台\" class=\"headerlink\" title=\"支持的平台\"></a>支持的平台</h1><ul>\n<li>WebLogic支持Windows、Linux、Solaris等平台。</li>\n<li>Undertow支持Windows、Linux、Mac OS X等平台。</li>\n<li>Tomcat支持Windows、Linux、Mac OS X等平台。</li>\n<li>Nginx支持Windows、Linux、Unix等平台。</li>\n</ul>\n<h1 id=\"支持的编程语言\"><a href=\"#支持的编程语言\" class=\"headerlink\" title=\"支持的编程语言\"></a>支持的编程语言</h1><ul>\n<li>WebLogic支持Java。</li>\n<li>Undertow支持Java。</li>\n<li>Tomcat支持Java。</li>\n<li>Nginx支持C、C++、Perl、Python等编程语言。</li>\n</ul>\n<h1 id=\"管理和监控\"><a href=\"#管理和监控\" class=\"headerlink\" title=\"管理和监控\"></a>管理和监控</h1><ul>\n<li>WebLogic具有完整的Web控制台和管理API可以轻松管理和监控Web应用程序。</li>\n<li>Undertow提供JMX API和可配置的管理端点但没有Web控制台。</li>\n<li>Tomcat提供管理和监控工具例如Web控制台、管理界面和JMX API。</li>\n<li>Nginx提供基本的管理和监控工具例如ngx_http_status_module和ngx_http_stub_status_module模块。</li>\n</ul>\n<h1 id=\"性能\"><a href=\"#性能\" class=\"headerlink\" title=\"性能\"></a>性能</h1><ul>\n<li>WebLogic具有较高的性能但相对较慢适用于大型企业级应用程序。</li>\n<li>Undertow具有极高的性能和低延迟适用于高性能Web应用程序。</li>\n<li>Tomcat具有较高的性能和低延迟适用于中小型Web应用程序。</li>\n<li>Nginx具有极高的性能、低延迟和高并发能力适用于大型Web应用程序。</li>\n</ul>\n<h1 id=\"总结\"><a href=\"#总结\" class=\"headerlink\" title=\"总结\"></a>总结</h1><p>WebLogic、Undertow、Tomcat和Nginx都是常用的Web服务器和应用程序服务器。它们具有不同的功能、应用场景、优缺点等方面的特点选择合适的服务器需要根据具体的需求来决定。</p>\n<p>如果需要构建大型企业级Java应用程序可以选择WebLogic如果需要构建高性能、低延迟的Web应用程序可以选择Undertow如果需要构建中小型Web应用程序可以选择Tomcat如果需要构建高性能、高并发、低延迟的Web应用程序可以选择Nginx。</p>\n<p>总之,选择合适的服务器可以提高应用程序的性能、可靠性和安全性,为用户提供更好的体验。</p>\n","categories":[{"name":"服务器","slug":"服务器","permalink":"https://hexo.huangge1199.cn/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/"}],"tags":[{"name":"服务器","slug":"服务器","permalink":"https://hexo.huangge1199.cn/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/"}]},{"title":"Firewall vs iptables什么是最好的Linux防火墙工具","slug":"fireWallTool","date":"2023-03-27T14:40:30.000Z","updated":"2023-03-28T07:34:58.477Z","comments":true,"path":"/post/fireWallTool/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>作为一名Linux管理员保护服务器免受网络攻击是最重要的任务之一。Linux操作系统提供了许多防火墙工具其中最常用的是iptables和Firewall。本文将比较Firewall和iptables之间的不同之处并探讨哪个防火墙工具更适合您的需求。</p>\n<h1 id=\"Firewall和iptables是什么\"><a href=\"#Firewall和iptables是什么\" class=\"headerlink\" title=\"Firewall和iptables是什么\"></a>Firewall和iptables是什么</h1><p>iptables是一个Linux防火墙工具它通过对网络数据包进行过滤和修改来控制网络访问。Firewall是新一代的Linux动态防火墙它基于D-Bus消息系统采用了Zone和Service的概念来管理网络访问。</p>\n<h1 id=\"iptables使用命令\"><a href=\"#iptables使用命令\" class=\"headerlink\" title=\"iptables使用命令\"></a>iptables使用命令</h1><ul>\n<li>查看当前的iptables规则iptables -L</li>\n<li>清除当前的iptables规则iptables -F</li>\n<li>允许指定端口的流量通过iptables -A INPUT -p tcp —dport [端口号] -j ACCEPT</li>\n<li>阻止指定端口的流量通过iptables -A INPUT -p tcp —dport [端口号] -j DROP</li>\n<li>允许某个IP地址的流量通过iptables -A INPUT -s [IP地址] -j ACCEPT</li>\n<li>阻止某个IP地址的流量通过iptables -A INPUT -s [IP地址] -j DROP</li>\n</ul>\n<h1 id=\"Firewall使用命令\"><a href=\"#Firewall使用命令\" class=\"headerlink\" title=\"Firewall使用命令\"></a>Firewall使用命令</h1><ul>\n<li>查看Firewall状态firewall-cmd —state</li>\n<li>查看当前的Firewall规则firewall-cmd —list-all</li>\n<li>允许指定端口的流量通过firewall-cmd —zone=public —add-port=[端口号]/tcp —permanent</li>\n<li>阻止指定端口的流量通过firewall-cmd —zone=public —remove-port=[端口号]/tcp —permanent</li>\n<li>允许某个IP地址的流量通过firewall-cmd —zone=public —add-source=[IP地址] —permanent</li>\n<li>阻止某个IP地址的流量通过firewall-cmd —zone=public —remove-source=[IP地址] —permanent</li>\n</ul>\n<h1 id=\"比较iptables和Firewall\"><a href=\"#比较iptables和Firewall\" class=\"headerlink\" title=\"比较iptables和Firewall\"></a>比较iptables和Firewall</h1><h2 id=\"语法和规则\"><a href=\"#语法和规则\" class=\"headerlink\" title=\"语法和规则\"></a>语法和规则</h2><p>iptables使用基于命令行的语法可以直接使用iptables命令来添加、修改和删除防火墙规则。而Firewall使用XML或JSON格式的配置文件可以使用firewall-cmd命令行工具或图形界面进行管理。</p>\n<h2 id=\"实现方式\"><a href=\"#实现方式\" class=\"headerlink\" title=\"实现方式\"></a>实现方式</h2><p>iptables是传统的Linux防火墙工具而Firewall是新一代的动态防火墙。Firewall允许在运行时添加和删除规则而不需要重启防火墙服务。</p>\n<h2 id=\"管理和配置\"><a href=\"#管理和配置\" class=\"headerlink\" title=\"管理和配置\"></a>管理和配置</h2><p>iptables可以通过编辑配置文件来管理和配置规则也可以通过调用命令行工具来实现。而Firewall是一种动态防火墙它允许在运行时添加和删除规则而不需要重启防火墙服务。</p>\n<h2 id=\"性能和效率\"><a href=\"#性能和效率\" class=\"headerlink\" title=\"性能和效率\"></a>性能和效率</h2><p>iptables具有更高的性能和效率可以处理更高的网络流量和更复杂的防火墙规则。而Firewall虽然具有动态性和易用性等优点但其性能和效率不如iptables。</p>\n<h1 id=\"iptables和Firewall的生效规则\"><a href=\"#iptables和Firewall的生效规则\" class=\"headerlink\" title=\"iptables和Firewall的生效规则\"></a>iptables和Firewall的生效规则</h1><p>对于iptables当您添加或删除规则时这些规则会立即生效并在运行iptables -L命令时显示出来。但是这些规则不会在系统重启后自动生效。为了保证规则在系统重启后仍然生效您需要将这些规则保存到文件中并确保在启动时加载该文件。您可以使用以下命令将当前iptables规则保存到文件中</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">iptables-save &gt; &#x2F;etc&#x2F;sysconfig&#x2F;iptables</code></pre>\n<p>在系统重启后,可以使用以下命令加载保存的规则:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">iptables-restore &lt; &#x2F;etc&#x2F;sysconfig&#x2F;iptables</code></pre>\n<p>对于Firewall添加或删除规则时这些规则不会立即生效您需要运行以下命令使其生效</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">firewall-cmd --reload</code></pre>\n<p>此命令会重新加载Firewall的规则并应用任何更改。但是请注意如果您没有使用—permanent选项将规则永久保存则在系统重启后这些规则将被清除。为了确保规则在系统重启后仍然生效您需要使用以下命令将规则永久保存</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">firewall-cmd --zone&#x3D;public --add-port&#x3D;8080&#x2F;tcp --permanent</code></pre>\n<p>此命令将添加一个允许端口8080的永久规则。在系统重启后此规则将自动加载。</p>\n<p>综上所述无论您使用iptables或Firewall哪一个修改防火墙规则时请注意保存规则并确保它们在系统重启后仍然生效。</p>\n<h1 id=\"哪个防火墙工具更适合您的需求?\"><a href=\"#哪个防火墙工具更适合您的需求?\" class=\"headerlink\" title=\"哪个防火墙工具更适合您的需求?\"></a>哪个防火墙工具更适合您的需求?</h1><p>如果您需要处理高流量和复杂规则的环境则使用iptables是一个很好的选择。iptables具有更高的性能和效率并且可以处理更复杂的防火墙规则。</p>\n<p>如果您需要简单、易用和动态防火墙则Firewall是一个很好的选择。Firewall具有动态性和易用性等优点并允许在运行时添加和删除规则而不需要重启防火墙服务。</p>\n<h1 id=\"结论\"><a href=\"#结论\" class=\"headerlink\" title=\"结论\"></a>结论</h1><p>防火墙是保护服务器安全的关键。iptables和Firewall是Linux操作系统上最常用的防火墙工具它们之间有许多不同之处。选择哪种防火墙工具取决于您的具体需求和偏好。无论您选择使用哪种工具都需要确保您的服务器受到良好的保护以免受到网络攻击。</p>\n","categories":[{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/categories/Linux/"}],"tags":[{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/tags/Linux/"}]},{"title":"Nacos1.0 vs. 2.0,你需要选择哪个版本来管理你的微服务?","slug":"nacosVerson","date":"2023-03-17T03:07:25.000Z","updated":"2023-03-17T03:12:13.485Z","comments":true,"path":"/post/nacosVerson/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>Nacos是一个开源的分布式配置中心和服务发现平台它可以帮助开发者轻松管理微服务架构中的配置和服务注册。在Nacos的不断发展中1.0版本和2.0版本都是非常重要的版本,本篇博客将对这两个版本进行介绍和比较。</p>\n<h1 id=\"一、Nacos-1-0版本\"><a href=\"#一、Nacos-1-0版本\" class=\"headerlink\" title=\"一、Nacos 1.0版本\"></a>一、Nacos 1.0版本</h1><p>Nacos 1.0版本于2019年3月发布它是Nacos的第一个正式版本也是经过多次测试和优化后的稳定版本。相较于之前的beta版本Nacos 1.0版本有了很大的改进和优化,主要包括以下几个方面:</p>\n<h2 id=\"1-功能完善\"><a href=\"#1-功能完善\" class=\"headerlink\" title=\"1. 功能完善\"></a>1. 功能完善</h2><p>Nacos 1.0版本在功能上相对完善包括了配置中心、服务注册与发现、命名空间、健康检查等核心功能。此外Nacos 1.0版本还增加了可插拔的扩展能力,可以方便地扩展各种插件,例如自定义的服务发现协议。</p>\n<h2 id=\"2-性能提升\"><a href=\"#2-性能提升\" class=\"headerlink\" title=\"2. 性能提升\"></a>2. 性能提升</h2><p>Nacos 1.0版本在性能上也有很大的提升,通过优化网络通信协议和数据存储方式,大大提高了系统的并发处理能力和吞吐量,可以满足更高的性能需求。</p>\n<h2 id=\"3-稳定性改进\"><a href=\"#3-稳定性改进\" class=\"headerlink\" title=\"3. 稳定性改进\"></a>3. 稳定性改进</h2><p>Nacos 1.0版本在稳定性方面也进行了不少改进,通过增加监控和自动修复机制,可以更快地检测和修复系统故障,从而提高了系统的稳定性和可靠性。</p>\n<h1 id=\"二、Nacos-2-0版本\"><a href=\"#二、Nacos-2-0版本\" class=\"headerlink\" title=\"二、Nacos 2.0版本\"></a>二、Nacos 2.0版本</h1><p>Nacos 2.0版本于2020年9月发布相对于1.0版本,它的改进和优化更加突出,主要体现在以下几个方面:</p>\n<h2 id=\"1-分布式一致性\"><a href=\"#1-分布式一致性\" class=\"headerlink\" title=\"1. 分布式一致性\"></a>1. 分布式一致性</h2><p>Nacos 2.0版本引入了Raft算法实现了分布式一致性从而保证了集群环境下数据的强一致性和高可用性。</p>\n<h2 id=\"2-更多的功能支持\"><a href=\"#2-更多的功能支持\" class=\"headerlink\" title=\"2. 更多的功能支持\"></a>2. 更多的功能支持</h2><p>Nacos 2.0版本增加了更多的功能支持例如DNS解析、动态配置刷新、访问控制等为用户提供了更加全面的服务治理和配置管理能力。</p>\n<h2 id=\"3-更高的性能和扩展性\"><a href=\"#3-更高的性能和扩展性\" class=\"headerlink\" title=\"3. 更高的性能和扩展性\"></a>3. 更高的性能和扩展性</h2><p>Nacos 2.0版本在性能和扩展性方面也有很大的提升采用异步I/O、内存池等技术大大提高了系统的处理能力和吞吐量。此外Nacos 2.0版本还提供了更加灵活的插件机制,方便用户进行个性化定制和扩展。</p>\n<h1 id=\"总结\"><a href=\"#总结\" class=\"headerlink\" title=\"总结\"></a>总结</h1><p>Nacos 1.0版本和2.0版本都是非常重要的版本它们分别在不同的方面进行了优化和改进为用户提供了更加全面和稳定的服务治理和配置管理能力。如果您是初次接触Nacos建议选择最新版本2.0以便获得更好的性能和更多的功能支持。但如果您的应用已经在Nacos 1.0版本上运行良好,也可以继续使用该版本,因为它已经经过多次测试和优化,具有很高的稳定性和可靠性。不管选择哪个版本,都需要根据实际业务场景和需求来进行选择和配置,以获得最佳的服务治理和配置管理效果。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"nacos","slug":"java/nacos","permalink":"https://hexo.huangge1199.cn/categories/java/nacos/"}],"tags":[{"name":"nacos","slug":"nacos","permalink":"https://hexo.huangge1199.cn/tags/nacos/"}]},{"title":"当数据遇上响应式编程Java应用中如何使用R2DBC访问关系型数据库","slug":"r2dbc","date":"2023-03-16T05:53:53.000Z","updated":"2023-03-16T06:23:52.212Z","comments":true,"path":"/post/r2dbc/","link":"","excerpt":"","content":"<p>在当今的大数据时代关系型数据库仍然是最常用的数据存储方式之一。Java是一种广泛使用的编程语言也是访问关系型数据库的主要语言之一。在Java应用程序中通常使用JDBCJava Database ConnectivityAPI来访问数据库。但是JDBC使用的同步/阻塞模型在处理高并发和大数据量的情况下可能会成为瓶颈因此R2DBCReactive Relational Database Connectivity在此时显得更加合适。</p>\n<p>R2DBC是Java应用程序访问关系型数据库的一种新方式它采用了响应式编程的思想提供了异步、非阻塞的API能够提高Java应用程序在高并发场景下的性能和可伸缩性。</p>\n<p>在本文中我们将介绍R2DBC的基本概念和原理并提供一些使用R2DBC的示例。</p>\n<h1 id=\"R2DBC的基本概念和原理\"><a href=\"#R2DBC的基本概念和原理\" class=\"headerlink\" title=\"R2DBC的基本概念和原理\"></a>R2DBC的基本概念和原理</h1><p>R2DBCReactive Relational Database Connectivity是一种基于异步、响应式编程模型的标准化关系型数据库连接API。R2DBC允许您使用响应式编程模型访问关系型数据库这种编程模型通常用于处理大量并发请求、高吞吐量和低延迟场景。</p>\n<p>R2DBC的主要设计目标是提供一种简单的异步、响应式编程模型以及一种统一的方式来连接不同类型的关系型数据库。与传统的JDBC API不同R2DBC使用反应流作为响应式编程模型的基础提供一组异步操作符以便您可以使用流式编程模型来执行数据库操作。</p>\n<p>目前R2DBC支持多种关系型数据库包括MySQL、PostgreSQL、Microsoft SQL Server和H2数据库。在使用R2DBC时您需要为您的数据库选择适当的R2DBC驱动程序并按照驱动程序的要求进行配置。</p>\n<h1 id=\"R2DBC提供了以下主要特性\"><a href=\"#R2DBC提供了以下主要特性\" class=\"headerlink\" title=\"R2DBC提供了以下主要特性\"></a>R2DBC提供了以下主要特性</h1><ul>\n<li><p>异步执行R2DBC使用异步编程模型可以处理大量并发请求提供高吞吐量和低延迟。</p>\n</li>\n<li><p>响应式编程模型R2DBC基于反应流Reactive Streams标准提供了一组异步操作符可以使用流式编程模型来执行数据库操作。</p>\n</li>\n<li><p>标准化APIR2DBC提供了一种标准化的关系型数据库连接API可以使用相同的API连接不同类型的关系型数据库。</p>\n</li>\n<li><p>轻量级R2DBC是一个轻量级的API它没有复杂的ORM框架或其他繁重的依赖。</p>\n</li>\n<li><p>无阻塞式I/OR2DBC使用无阻塞式I/O操作可以处理大量并发请求并提供高吞吐量和低延迟。</p>\n</li>\n</ul>\n<h1 id=\"使用R2DBC的示例\"><a href=\"#使用R2DBC的示例\" class=\"headerlink\" title=\"使用R2DBC的示例\"></a>使用R2DBC的示例</h1><p>使用R2DBC来连接MySQL数据库您需要执行以下步骤</p>\n<h2 id=\"步骤1添加依赖项\"><a href=\"#步骤1添加依赖项\" class=\"headerlink\" title=\"步骤1添加依赖项\"></a>步骤1添加依赖项</h2><p>要在Java应用程序中使用R2DBC来访问MySQL数据库首先需要将R2DBC MySQL依赖项添加到项目中。我们可以通过以下Maven依赖项将R2DBC MySQL引入我们的项目中</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;dependency&gt;\n &lt;groupId&gt;dev.miku&lt;&#x2F;groupId&gt;\n &lt;artifactId&gt;r2dbc-mysql&lt;&#x2F;artifactId&gt;\n &lt;version&gt;0.8.8.RELEASE&lt;&#x2F;version&gt;\n&lt;&#x2F;dependency&gt;</code></pre>\n<h2 id=\"步骤2配置数据库连接\"><a href=\"#步骤2配置数据库连接\" class=\"headerlink\" title=\"步骤2配置数据库连接\"></a>步骤2配置数据库连接</h2><p>在使用R2DBC访问MySQL数据库之前我们需要先配置数据库连接。下面是一个示例配置</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Configuration\npublic class R2dbcConfiguration &#123;\n\n @Bean\n public ConnectionFactory connectionFactory() &#123;\n return new MysqlConnectionFactory(\n ConnectionFactoryOptions.builder()\n .option(DRIVER, &quot;mysql&quot;)\n .option(HOST, &quot;localhost&quot;)\n .option(USER, &quot;username&quot;)\n .option(PASSWORD, &quot;password&quot;)\n .option(DATABASE, &quot;database&quot;)\n .build()\n );\n &#125;\n&#125;</code></pre>\n<p>在上面的示例中,我们使用<code>MysqlConnectionFactory</code>类创建MySQL连接工厂。同时我们使用<code>ConnectionFactoryOptions</code>类配置了连接选项,包括数据库驱动程序、主机、用户名、密码和数据库名称等。</p>\n<h2 id=\"步骤3使用连接工厂创建连接\"><a href=\"#步骤3使用连接工厂创建连接\" class=\"headerlink\" title=\"步骤3使用连接工厂创建连接\"></a>步骤3使用连接工厂创建连接</h2><p>一旦我们已经配置好了数据库连接,我们可以使用连接工厂创建一个新的数据库连接。以下是一个示例:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class UserRepository &#123;\n\n private final ConnectionFactory connectionFactory;\n\n public UserRepository(ConnectionFactory connectionFactory) &#123;\n this.connectionFactory &#x3D; connectionFactory;\n &#125;\n\n public Flux&lt;User&gt; findAll() &#123;\n return Mono.from(connectionFactory.create())\n .flatMapMany(connection -&gt;\n Flux.from(connection.createStatement(&quot;SELECT * FROM users&quot;).execute())\n .flatMap(result -&gt; result.map((row, rowMetadata) -&gt;\n new User(row.get(&quot;id&quot;, Long.class), row.get(&quot;name&quot;, String.class))\n ))\n .doFinally((signalType) -&gt; Mono.from(connection.close()).subscribe())\n );\n &#125;\n&#125;</code></pre>\n<p>在上面的示例中,我们创建了一个<code>UserRepository</code>类,并使用<code>MysqlConnectionFactory</code>类创建MySQL连接工厂。我们使用<code>Mono.from(connectionFactory.create())</code>方法创建一个新的数据库连接。接下来,我们使用<code>Flux.from(connection.createStatement(&quot;SELECT * FROM users&quot;).execute())</code>方法创建一个Flux该Flux将使用SQL查询语句从数据库中检索所有用户记录。我们使用<code>flatMap()</code>方法将结果转换为我们的<code>User</code>对象,并将其作为<code>Flux</code>对象返回。最后,我们使用<code>doFinally()</code>方法关闭数据库连接。</p>\n<h2 id=\"步骤4使用R2DBC在Java应用程序中访问MySQL数据库\"><a href=\"#步骤4使用R2DBC在Java应用程序中访问MySQL数据库\" class=\"headerlink\" title=\"步骤4使用R2DBC在Java应用程序中访问MySQL数据库\"></a>步骤4使用R2DBC在Java应用程序中访问MySQL数据库</h2><p>我们现在已经配置了数据库连接,并创建了一个用于访问数据库的<code>UserRepository</code>类。我们可以在Java应用程序中使用此类来访问MySQL数据库。以下是一个示例</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class Application &#123;\n\n public static void main(String[] args) &#123;\n ApplicationContext context &#x3D; new AnnotationConfigApplicationContext(R2dbcConfiguration.class);\n UserRepository userRepository &#x3D; context.getBean(UserRepository.class);\n\n userRepository.findAll()\n .subscribe(user -&gt; System.out.println(&quot;User: &quot; + user));\n &#125;\n&#125;</code></pre>\n<p>在上面的示例中,我们创建了一个<code>Application</code>类,并在其中创建了一个<code>UserRepository</code>实例。我们调用<code>userRepository.findAll()</code>方法来检索所有用户记录,并在控制台上打印每个用户的名称。最后,我们使用<code>subscribe()</code>方法订阅<code>Flux</code>对象。</p>\n<h1 id=\"总结\"><a href=\"#总结\" class=\"headerlink\" title=\"总结\"></a>总结</h1><p>R2DBC是一种基于响应式编程的数据库访问API它可以提高Java应用程序在高并发场景下的性能和可伸缩性。使用R2DBC可以让程序员使用异步、非阻塞的API访问关系型数据库从而充分发挥计算机的CPU和内存资源。</p>\n<p>在使用R2DBC时需要遵循基本步骤包括添加R2DBC依赖项、配置数据库连接、使用连接工厂创建连接以及执行查询或更新等操作。通过这些步骤程序员可以编写高效、可伸缩的Java应用程序从而更好地应对大规模数据处理和高并发访问的场景。</p>\n<p>总的来说R2DBC是Java应用程序中非常有用的工具可以帮助开发者提高程序的性能和可伸缩性。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"},{"name":"R2DBC","slug":"R2DBC","permalink":"https://hexo.huangge1199.cn/tags/R2DBC/"}]},{"title":"当分布式遇上一致性Raft、SofaJRaft和Distro协议大比拼","slug":"raftProtocol","date":"2023-03-15T03:23:28.000Z","updated":"2023-03-15T06:21:45.787Z","comments":true,"path":"/post/raftProtocol/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>今天我学习nacos的源码看到了distro协议于是本篇博客就由此而来了通过网上查找的资料我大体整理了下下面是整理后的结果。</p>\n<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>分布式系统是由多个计算机节点组成的系统这些节点通过网络相互连接并协同工作来实现一个共同的目标。在分布式系统中数据的一致性是一个非常重要的问题。分布式一致性算法可以帮助我们解决这个问题。本文将介绍三种分布式一致性算法distro协议、sofajraft协议、raft协议并讨论它们的适用场景和特点。</p>\n<h1 id=\"Raft协议\"><a href=\"#Raft协议\" class=\"headerlink\" title=\"Raft协议\"></a>Raft协议</h1><p>Raft是一种分布式一致性算法由Stanford大学的Diego Ongaro和John Ousterhout于2013年提出。Raft算法的主要目标是提供一种易于理解和实现的分布式一致性算法。Raft算法具有良好的可读性和易于理解的特点使得它容易被人们理解和实现。Raft算法通过领导选举、日志复制、一致性检查点等基础功能保证了分布式系统中数据的一致性。</p>\n<h1 id=\"SofaJRaft协议\"><a href=\"#SofaJRaft协议\" class=\"headerlink\" title=\"SofaJRaft协议\"></a>SofaJRaft协议</h1><p>SofaJRaft是一种基于Raft协议的改进版本。SofaJRaft在Raft协议的基础上增加了一些特性例如动态配置、快照等以适应更加复杂的场景需求。SofaJRaft算法的设计目标是提供一个高性能、高可用、易于扩展的分布式一致性算法。SofaJRaft算法在性能和可扩展性方面优于Raft协议适用于更为复杂的分布式系统例如分布式存储、分布式数据库等。</p>\n<h1 id=\"Distro协议\"><a href=\"#Distro协议\" class=\"headerlink\" title=\"Distro协议\"></a>Distro协议</h1><p>Distro协议是基于SofaJRaft协议的一种改进版本。Distro协议在SofaJRaft协议的基础上进一步优化例如增加了故障转移功能提高了容错性能。Distro协议的设计目标是提供一个高可靠、高性能、易于扩展的分布式一致性算法。Distro协议适用于更加严苛的分布式系统环境例如金融、电信等领域的应用。</p>\n<h1 id=\"三种协议比较\"><a href=\"#三种协议比较\" class=\"headerlink\" title=\"三种协议比较\"></a>三种协议比较</h1><p>Raft协议、SofaJRaft协议和Distro协议都是分布式一致性算法它们之间有以下的不同和优势</p>\n<ol>\n<li><p>Raft协议的可读性和易于理解性更好适用于一些小规模的分布式系统。</p>\n</li>\n<li><p>SofaJRaft协议增加了一些特性例如动态配置、快照等适用于更为复杂的分布式系统例如分布式存储、分布式数据库等。</p>\n</li>\n<li><p>Distro协议在SofaJRaft协议的基础上增加了故障转移功能提高了容错性能适用于更加严苛的分布式系统环境例如金融、电信等领域的应用。</p>\n</li>\n</ol>\n<h1 id=\"共性\"><a href=\"#共性\" class=\"headerlink\" title=\"共性\"></a>共性</h1><ol>\n<li><p>都使用领导者选举机制,通过选举一个领导者来管理整个系统。</p>\n</li>\n<li><p>都使用日志复制机制,通过复制日志来实现数据的一致性。</p>\n</li>\n<li><p>都可以实现线性一致性。</p>\n</li>\n<li><p>都可以扩展到多个节点。</p>\n</li>\n</ol>\n<p>总之,选择合适的分布式一致性算法需要综合考虑系统规模、复杂度、容错性要求等因素。同时,需要注意算法的实现、性能、可维护性等方面的问题。</p>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"详细的Python Flask的操作","slug":"pythonFlask","date":"2023-02-14T07:47:27.000Z","updated":"2023-02-15T09:53:58.012Z","comments":true,"path":"/post/pythonFlask/","link":"","excerpt":"","content":"<p>本篇文章是<a href=\"https://www.w3cschool.cn/minicourse/play/pyflask\">Python Flask 建站框架入门课程_编程实战微课_w3cschool</a>微课的学习笔记,根据课程整理而来,本人使用版本如下:</p>\n<div class=\"table-container\">\n<table>\n<thead>\n<tr>\n<th>Python</th>\n<th>3.10.0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Flask</td>\n<td>2.2.2</td>\n</tr>\n</tbody>\n</table>\n</div>\n<h1 id=\"简介\"><a href=\"#简介\" class=\"headerlink\" title=\"简介\"></a>简介</h1><ul>\n<li><p>Flask是一个轻量级的可定制的web框架</p>\n</li>\n<li><p>Flask 可以很好地结合MVC模式进行开发</p>\n</li>\n<li><p>Flask还有很强的很强的扩展性和兼容性</p>\n</li>\n</ul>\n<h1 id=\"核心函数库\"><a href=\"#核心函数库\" class=\"headerlink\" title=\"核心函数库\"></a>核心函数库</h1><p>Flask主要包括Werkzeug和Jinja2两个核心函数库它们分别负责业务处理和安全方面的功能这些基础函数为web项目开发过程提供了丰富的基础组件。</p>\n<h2 id=\"Werkzeug\"><a href=\"#Werkzeug\" class=\"headerlink\" title=\"Werkzeug\"></a>Werkzeug</h2><p>Werkzeug库十分强大功能比较完善支持URL路由请求集成一次可以响应多个用户的访问请求</p>\n<p>支持Cookie和会话管理通过身份缓存数据建立长久连接关系并提高用户访问速度支持交互式Javascript调试提高用户体验</p>\n<p>可以处理HTTP基本事务快速响应客户端推送过来的访问请求。</p>\n<h2 id=\"Jinja2\"><a href=\"#Jinja2\" class=\"headerlink\" title=\"Jinja2\"></a>Jinja2</h2><p>Jinja2库支持自动HTML转移功能能够很好控制外部黑客的脚本攻击</p>\n<p>系统运行速度很快页面加载过程会将源码进行编译形成python字节码从而实现模板的高效运行</p>\n<p>模板继承机制可以对模板内容进行修改和维护,为不同需求的用户提供相应的模板。</p>\n<h1 id=\"安装\"><a href=\"#安装\" class=\"headerlink\" title=\"安装\"></a>安装</h1><p>通过pip安装即可</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">pip install Flask\n# pip3\npip3 install Flask</code></pre>\n<h1 id=\"目录结构\"><a href=\"#目录结构\" class=\"headerlink\" title=\"目录结构\"></a>目录结构</h1><h2 id=\"新项目创建后的结构\"><a href=\"#新项目创建后的结构\" class=\"headerlink\" title=\"新项目创建后的结构\"></a>新项目创建后的结构</h2><p><img src=\"https://img.huangge1199.cn/blog/pythonFlask/2023-02-14-17-10-32-image.png\" alt=\"\"></p>\n<p>static文件夹存放静态文件比如css、js、图片等</p>\n<p>templates文件夹模板文件目录</p>\n<p>app.py应用启动程序</p>\n<h1 id=\"获取URL参数\"><a href=\"#获取URL参数\" class=\"headerlink\" title=\"获取URL参数\"></a>获取URL参数</h1><h2 id=\"列出所有URL参数\"><a href=\"#列出所有URL参数\" class=\"headerlink\" title=\"列出所有URL参数\"></a>列出所有URL参数</h2><p><code>request.args.__str__()</code></p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef hello_world(): # put application&#39;s code here\n return request.args.__str__()\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>在浏览器中访问<code>http://127.0.0.1:5000/?name=Loen&amp;age&amp;app=ios&amp;app=android</code>,将显示:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">ImmutableMultiDict([(&#39;name&#39;, &#39;Loen&#39;), (&#39;age&#39;, &#39;&#39;), (&#39;app&#39;, &#39;ios&#39;), (&#39;app&#39;, &#39;android&#39;)])</code></pre>\n<h2 id=\"列出浏览器传给我们的Flask服务的数据\"><a href=\"#列出浏览器传给我们的Flask服务的数据\" class=\"headerlink\" title=\"列出浏览器传给我们的Flask服务的数据\"></a>列出浏览器传给我们的Flask服务的数据</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef hello_world(): # put application&#39;s code here\n\n # 列出访问地址\n print(request.path)\n\n # 列出访问地址及参数\n print(request.full_path)\n\n return request.args.__str__()\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>在浏览器中访问<code>http://127.0.0.1:5000/?name=Loen&amp;age&amp;app=ios&amp;app=android</code>,控制台中显示</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">&#x2F;\n&#x2F;?name&#x3D;Loen&amp;age&amp;app&#x3D;ios&amp;app&#x3D;android</code></pre>\n<h2 id=\"获取指定的参数值\"><a href=\"#获取指定的参数值\" class=\"headerlink\" title=\"获取指定的参数值\"></a>获取指定的参数值</h2><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef hello_world(): # put application&#39;s code here\n\n return request.args.get(&#39;name&#39;)\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>在浏览器中访问<code>http://127.0.0.1:5000/?name=Loen&amp;age&amp;app=ios&amp;app=android</code>,将显示:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">Loen</code></pre>\n<h2 id=\"处理多值\"><a href=\"#处理多值\" class=\"headerlink\" title=\"处理多值\"></a>处理多值</h2><pre class=\"line-numbers language-pythoon\" data-language=\"pythoon\"><code class=\"language-pythoon\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef hello_world(): # put application&#39;s code here\n r &#x3D; request.args.getlist(&#39;app&#39;) # 返回一个list\n return r\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>在浏览器中访问<code>http://127.0.0.1:5000/?name=Loen&amp;age&amp;app=ios&amp;app=android</code>,将显示:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">[\n &quot;ios&quot;,\n &quot;android&quot;\n]</code></pre>\n<h1 id=\"获取POST方法传送的数据\"><a href=\"#获取POST方法传送的数据\" class=\"headerlink\" title=\"获取POST方法传送的数据\"></a>获取POST方法传送的数据</h1><p>作为一种HTTP请求方法POST用于向指定的资源提交要被处理的数据。</p>\n<p>我们在某些时候不适合将数据放到URL参数中密或者数据太多浏览器不一定支持太长长度的URL。这时一般使用POST方法。</p>\n<p>本文章使用python的requests库模拟浏览器。</p>\n<p>安装命令:</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">pip install requests</code></pre>\n<h2 id=\"看POST数据内容\"><a href=\"#看POST数据内容\" class=\"headerlink\" title=\"看POST数据内容\"></a>看POST数据内容</h2><p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;register&#39;, methods&#x3D;[&#39;POST&#39;])\ndef register():\n print(request.headers)\n print(request.stream.read())\n return &#39;welcome&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>register.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import requests\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n user_info &#x3D; &#123;&#39;name&#39;: &#39;Loen&#39;, &#39;password&#39;: &#39;loveyou&#39;&#125;\n r &#x3D; requests.post(&quot;http:&#x2F;&#x2F;127.0.0.1:5000&#x2F;register&quot;, data&#x3D;user_info)\n print(r.text)</code></pre>\n<p>运行<code>app.py</code>,然后运行<code>register.py</code>。</p>\n<p><code>register.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">welcome</code></pre>\n<p><code>app.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">Host: 127.0.0.1:5000\nUser-Agent: python-requests&#x2F;2.28.2\nAccept-Encoding: gzip, deflate\nAccept: *&#x2F;*\nConnection: keep-alive\nContent-Length: 26\nContent-Type: application&#x2F;x-www-form-urlencoded\n\n\nb&#39;name&#x3D;Loen&amp;password&#x3D;loveyou&#39;\n127.0.0.1 - - [14&#x2F;Feb&#x2F;2023 21:12:17] &quot;POST &#x2F;register HTTP&#x2F;1.1&quot; 200 -</code></pre>\n<h2 id=\"解析POST数据\"><a href=\"#解析POST数据\" class=\"headerlink\" title=\"解析POST数据\"></a>解析POST数据</h2><p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;register&#39;, methods&#x3D;[&#39;POST&#39;])\ndef register():\n # print(request.stream.read()) # 不要用否则下面的form取不到数据\n print(request.form)\n print(request.form[&#39;name&#39;])\n print(request.form.get(&#39;name&#39;))\n print(request.form.getlist(&#39;name&#39;))\n print(request.form.get(&#39;nickname&#39;, default&#x3D;&#39;little apple&#39;))\n return &#39;welcome&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run(port&#x3D;5000, debug&#x3D;True)</code></pre>\n<p>register.py代码不变运行<code>app.py</code>,然后运行<code>register.py</code>。</p>\n<p><code>register.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">welcome</code></pre>\n<p><code>app.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">ImmutableMultiDict([(&#39;name&#39;, &#39;Loen&#39;), (&#39;password&#39;, &#39;loveyou&#39;)])\nLoen\nLoen\n[&#39;Loen&#39;]\nlittle apple</code></pre>\n<p>request.form会自动解析数据。</p>\n<p>request.form[name]和request.form.get(name)都可以获取name对应的值。</p>\n<p>request.form.get()可以为参数default指定值以作为默认值。</p>\n<h2 id=\"获取POST中的列表数据\"><a href=\"#获取POST中的列表数据\" class=\"headerlink\" title=\"获取POST中的列表数据\"></a>获取POST中的列表数据</h2><p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;register&#39;, methods&#x3D;[&#39;POST&#39;])\ndef register():\n # print(request.stream.read()) # 不要用否则下面的form取不到数据\n print(request.form.getlist(&#39;name&#39;))\n return &#39;welcome&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run(port&#x3D;5000, debug&#x3D;True)</code></pre>\n<p>register.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import requests\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n user_info &#x3D; &#123;&#39;name&#39;: [&#39;Loen&#39;, &#39;Alan&#39;], &#39;password&#39;: &#39;loveyou&#39;&#125;\n r &#x3D; requests.post(&quot;http:&#x2F;&#x2F;127.0.0.1:5000&#x2F;register&quot;, data&#x3D;user_info)\n print(r.text)</code></pre>\n<p>运行<code>app.py</code>,然后运行<code>register.py</code>。</p>\n<p><code>register.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">welcome</code></pre>\n<p><code>app.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">[&#39;Loen&#39;, &#39;Alan&#39;]</code></pre>\n<h1 id=\"处理和响应JSON数据\"><a href=\"#处理和响应JSON数据\" class=\"headerlink\" title=\"处理和响应JSON数据\"></a>处理和响应JSON数据</h1><h2 id=\"处理JSON数据\"><a href=\"#处理JSON数据\" class=\"headerlink\" title=\"处理JSON数据\"></a>处理JSON数据</h2><p>如果POST的数据是JSON格式request.json会自动将json数据转换成Python类型字典或者列表。</p>\n<p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;add&#39;, methods&#x3D;[&#39;POST&#39;])\ndef add():\n print(type(request.json))\n print(request.json)\n result &#x3D; request.json[&#39;n1&#39;] + request.json[&#39;n2&#39;]\n return str(result)\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run(port&#x3D;5000, debug&#x3D;True)</code></pre>\n<p>register.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import requests\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n json_data &#x3D; &#123;&#39;n1&#39;: 5, &#39;n2&#39;: 3&#125;\n r &#x3D; requests.post(&quot;http:&#x2F;&#x2F;127.0.0.1:5000&#x2F;add&quot;, json&#x3D;json_data)\n print(r.text)</code></pre>\n<p>运行<code>app.py</code>,然后运行<code>register.py</code>。</p>\n<p><code>register.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">8</code></pre>\n<p><code>app.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">&lt;class &#39;dict&#39;&gt;\n&#123;&#39;n1&#39;: 5, &#39;n2&#39;: 3&#125;</code></pre>\n<h2 id=\"响应JSON数据Response\"><a href=\"#响应JSON数据Response\" class=\"headerlink\" title=\"响应JSON数据Response\"></a>响应JSON数据Response</h2><p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import json\n\nfrom flask import Flask, request, Response\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;add&#39;, methods&#x3D;[&#39;POST&#39;])\ndef add():\n result &#x3D; &#123;&#39;sum&#39;: request.json[&#39;n1&#39;] + request.json[&#39;n2&#39;]&#125;\n return Response(json.dumps(result), mimetype&#x3D;&#39;application&#x2F;json&#39;)\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run(port&#x3D;5000, debug&#x3D;True)</code></pre>\n<p>register.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import requests\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n json_data &#x3D; &#123;&#39;n1&#39;: 5, &#39;n2&#39;: 3&#125;\n r &#x3D; requests.post(&quot;http:&#x2F;&#x2F;127.0.0.1:5000&#x2F;add&quot;, json&#x3D;json_data)\n print(r.headers)\n print(r.text)</code></pre>\n<p>运行<code>app.py</code>,然后运行<code>register.py</code>。</p>\n<p><code>register.py</code>将输出:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">&#x2F;home&#x2F;huangge1199&#x2F;PycharmProjects&#x2F;flaskProject&#x2F;venv&#x2F;bin&#x2F;python &#x2F;home&#x2F;huangge1199&#x2F;PycharmProjects&#x2F;flaskProject&#x2F;register.py \n&#123;&#39;Server&#39;: &#39;Werkzeug&#x2F;2.2.2 Python&#x2F;3.7.3&#39;, &#39;Date&#39;: &#39;Tue, 14 Feb 2023 13:37:49 GMT&#39;, &#39;Content-Type&#39;: &#39;application&#x2F;json&#39;, &#39;Content-Length&#39;: &#39;10&#39;, &#39;Connection&#39;: &#39;close&#39;&#125;\n&#123;&quot;sum&quot;: 8&#125;</code></pre>\n<h2 id=\"响应JSON数据jsonify\"><a href=\"#响应JSON数据jsonify\" class=\"headerlink\" title=\"响应JSON数据jsonify\"></a>响应JSON数据jsonify</h2><p>app.py中app()返回时使用下面的内容,效果同之前一样</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">return jsonify(result)</code></pre>\n<h1 id=\"上传表单\"><a href=\"#上传表单\" class=\"headerlink\" title=\"上传表单\"></a>上传表单</h1><p>用 Flask 处理文件上传很简单,只要确保你没忘记在 HTML 表单中设置 enctype=”multipart/form-data” 属性,不然你的浏览器根本不会发送文件。</p>\n<p>安装响应的库<code>werkzeug</code></p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">pip install werkzeug</code></pre>\n<p>目录结构:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pythonFlask/2023-02-15-15-10-19-image.png\" alt=\"\"></p>\n<p>app.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, request\nfrom werkzeug.utils import secure_filename\nimport os\n\napp &#x3D; Flask(__name__)\n\n# 文件上传目录\napp.config[&#39;UPLOAD_FOLDER&#39;] &#x3D; &#39;static&#x2F;uploads&#x2F;&#39;\n# 支持的文件格式\napp.config[&#39;ALLOWED_EXTENSIONS&#39;] &#x3D; &#123;&#39;png&#39;, &#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;&#125; # 集合类型\n\n\n# 判断文件名是否是我们支持的格式\ndef allowed_file(filename):\n return &#39;.&#39; in filename and \\\n filename.rsplit(&#39;.&#39;, 1)[1] in app.config[&#39;ALLOWED_EXTENSIONS&#39;]\n\n\n@app.route(&#39;&#x2F;upload&#39;, methods&#x3D;[&#39;POST&#39;])\ndef upload():\n upload_file &#x3D; request.files[&#39;image&#39;]\n if upload_file and allowed_file(upload_file.filename): # 上传前文件在客户端的文件名\n filename &#x3D; secure_filename(upload_file.filename)\n # 将文件保存到 static&#x2F;uploads 目录,文件名同上传时使用的文件名\n upload_file.save(os.path.join(app.root_path, app.config[&#39;UPLOAD_FOLDER&#39;], filename))\n return &#39;info is &#39; + request.form.get(&#39;info&#39;, &#39;&#39;) + &#39;. success&#39;\n else:\n return &#39;failed&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>register.py代码如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import requests\n\nif __name__ &#x3D;&#x3D; &quot;__main__&quot;:\n file_data &#x3D; &#123;&#39;image&#39;: open(&#39;flask.png&#39;, &#39;rb&#39;)&#125;\n user_info &#x3D; &#123;&#39;info&#39;: &#39;flask&#39;&#125;\n r &#x3D; requests.post(&quot;http:&#x2F;&#x2F;127.0.0.1:5000&#x2F;upload&quot;, data&#x3D;user_info, files&#x3D;file_data)\n print(r.text)</code></pre>\n<p>运行<code>app.py</code>,然后运行<code>register.py</code>,这时候文件已经上传到了指定目录中</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pythonFlask/2023-02-15-15-11-43-image.png\" alt=\"\"></p>\n<p>要控制上产文件的大小,可以设置请求实体的大小,代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">app.config[&#39;MAX_CONTENT_LENGTH&#39;] &#x3D; 16 * 1024 * 1024 #16MB</code></pre>\n<p>获取上传文件的内容,代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">file_content &#x3D; request.files[&#39;image&#39;].stream.read()</code></pre>\n<h1 id=\"Restful-URL\"><a href=\"#Restful-URL\" class=\"headerlink\" title=\"Restful URL\"></a>Restful URL</h1><p>Restful URL可以看做是对 URL 参数的替代</p>\n<h2 id=\"变量规则\"><a href=\"#变量规则\" class=\"headerlink\" title=\"变量规则\"></a>变量规则</h2><p>写法如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">@app.route(&#39;&#x2F;user&#x2F;&lt;username&gt;&#x2F;friends&#39;)</code></pre>\n<h2 id=\"转换类型\"><a href=\"#转换类型\" class=\"headerlink\" title=\"转换类型\"></a>转换类型</h2><p>使用 Restful URL 得到的变量默认为str对象。我们可以用flask内置的转换机制即在route中指定转换类型写法如下</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">@app.route(&#39;&#x2F;page&#x2F;&lt;int:num&gt;&#39;)</code></pre>\n<p>有3个默认的转换器</p>\n<ul>\n<li><p>int接受整数</p>\n</li>\n<li><p>float同 int ,但是接受浮点数</p>\n</li>\n<li><p>path和默认的相似但也接受斜线</p>\n</li>\n</ul>\n<h2 id=\"自定义转换器\"><a href=\"#自定义转换器\" class=\"headerlink\" title=\"自定义转换器\"></a>自定义转换器</h2><p>自定义的转换器是一个继承werkzeug.routing.BaseConverter的类修改to_python和to_url方法即可。</p>\n<p>to_python方法用于将url中的变量转换后供被<code>@app.route</code>包装的函数使用to_url方法用于flask.url_for中的参数转换。</p>\n<p>下面是一个示例:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, url_for\nfrom werkzeug.routing import BaseConverter\n\n\nclass MyIntConverter(BaseConverter):\n\n def __init__(self, url_map):\n super(MyIntConverter, self).__init__(url_map)\n\n def to_python(self, value):\n return int(value)\n\n def to_url(self, value):\n return value * 2\n\n\napp &#x3D; Flask(__name__)\napp.url_map.converters[&#39;my_int&#39;] &#x3D; MyIntConverter\n\n\n@app.route(&#39;&#x2F;page&#x2F;&lt;my_int:num&gt;&#39;)\ndef page(num):\n print(num)\n print(url_for(&#39;page&#39;, num&#x3D;&#39;145&#39;)) # page 对应的是 page函数 num 对应对应&#96;&#x2F;page&#x2F;&lt;my_int:num&gt;&#96;中的num必须是str\n return &#39;hello world&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>运行<code>app.py</code>,浏览器访问<code>http://127.0.0.1:5000/page/28</code>后,<code>app.py</code>的输出信息是:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">28\n&#x2F;page&#x2F;145145</code></pre>\n<h1 id=\"使用url-for生成链接\"><a href=\"#使用url-for生成链接\" class=\"headerlink\" title=\"使用url_for生成链接\"></a>使用url_for生成链接</h1><p>工具函数<code>url_for</code>可以让你以软编码的形式生成url提供开发效率。</p>\n<p>例子<code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, url_for\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef hello_world():\n pass\n\n\n@app.route(&#39;&#x2F;user&#x2F;&lt;name&gt;&#39;)\ndef user(name):\n pass\n\n\n@app.route(&#39;&#x2F;page&#x2F;&lt;int:num&gt;&#39;)\ndef page(num):\n pass\n\n\n@app.route(&#39;&#x2F;test&#39;)\ndef test():\n print(url_for(&#39;test&#39;))\n print(url_for(&#39;user&#39;, name&#x3D;&#39;loen&#39;))\n print(url_for(&#39;page&#39;, num&#x3D;1, q&#x3D;&#39;welcome to w3c 15%2&#39;))\n print(url_for(&#39;static&#39;, filename&#x3D;&#39;uploads&#x2F;flask.png&#39;))\n return &#39;Hello&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>运行<code>app.py</code>。然后在浏览器中访问<code>http://127.0.0.1:5000/test</code><code>server.py</code>控制台将输出以下信息:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">&#x2F;test\n&#x2F;user&#x2F;loen\n&#x2F;page&#x2F;1?q&#x3D;welcome+to+w3c+15%252\n&#x2F;static&#x2F;uploads&#x2F;flask.jpg</code></pre>\n<h1 id=\"使用redirect重定向网址\"><a href=\"#使用redirect重定向网址\" class=\"headerlink\" title=\"使用redirect重定向网址\"></a>使用redirect重定向网址</h1><p>在浏览器中访问<code>http://127.0.0.1:5000/old</code>浏览器的url会变成<code>http://127.0.0.1:5000/new</code>,并显示,<code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, url_for, redirect\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;old&#39;)\ndef old():\n print(&#39;this is old&#39;)\n return redirect(url_for(&#39;new&#39;))\n\n\n@app.route(&#39;&#x2F;new&#39;)\ndef new():\n print(&#39;this is new&#39;)\n return &#39;this is new&#39;\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>运行<code>app.py</code>,然后在浏览器中访问<code>http://127.0.0.1:5000/old</code></p>\n<p>浏览器显示:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">this is new</code></pre>\n<p>控制台显示:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">this is old\nthis is new</code></pre>\n<h1 id=\"自定义404\"><a href=\"#自定义404\" class=\"headerlink\" title=\"自定义404\"></a>自定义404</h1><h2 id=\"处理HTTP错误\"><a href=\"#处理HTTP错误\" class=\"headerlink\" title=\"处理HTTP错误\"></a>处理HTTP错误</h2><p>要处理HTTP错误可以使用<code>flask.abort</code>函数。</p>\n<p><code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, abort\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;user&#39;)\ndef user():\n abort(401) # Unauthorized 未授权\n print(&#39;Unauthorized, 请先登录&#39;)\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>运行<code>app.py</code>,然后在浏览器中访问<code>http://127.0.0.1:5000/user</code></p>\n<p>浏览器显示:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pythonFlask/2023-02-15-17-26-19-image.png\" alt=\"\"></p>\n<h2 id=\"自定义错误页面\"><a href=\"#自定义错误页面\" class=\"headerlink\" title=\"自定义错误页面\"></a>自定义错误页面</h2><p>page_unauthorized 函数返回的是一个元组401 代表HTTP 响应状态码。</p>\n<p>如果省略401则响应状态码会变成默认的 200。</p>\n<p><code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, abort, render_template_string\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;user&#39;)\ndef user():\n abort(401) # Unauthorized\n\n\n@app.errorhandler(401)\ndef page_unauthorized(error):\n return render_template_string(&#39;&lt;h1&gt; Unauthorized &lt;&#x2F;h1&gt;&lt;h2&gt;&#123;&#123; error_info &#125;&#125;&lt;&#x2F;h2&gt;&#39;, error_info&#x3D;error), 401\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p>运行<code>app.py</code>,然后在浏览器中访问<code>http://127.0.0.1:5000/user</code></p>\n<p>浏览器显示:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/pythonFlask/2023-02-15-17-29-44-image.png\" alt=\"\"></p>\n<h1 id=\"用户会话\"><a href=\"#用户会话\" class=\"headerlink\" title=\"用户会话\"></a>用户会话</h1><p>session 用来记录用户的登录状态一般基于cookie实现。</p>\n<p><code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from flask import Flask, render_template_string, request, session, redirect, url_for\n\napp &#x3D; Flask(__name__)\n\napp.secret_key &#x3D; &#39;LoenDSdtj\\9bX#%@!!*(0&amp;^%)&#39;\n\n\n@app.route(&#39;&#x2F;login&#39;)\ndef login():\n page &#x3D; &#39;&#39;&#39;\n &lt;form action&#x3D;&quot;&#123;&#123; url_for(&#39;do_login&#39;) &#125;&#125;&quot; method&#x3D;&quot;post&quot;&gt;\n &lt;p&gt;name: &lt;input type&#x3D;&quot;text&quot; name&#x3D;&quot;user_name&quot; &#x2F;&gt;&lt;&#x2F;p&gt;\n &lt;input type&#x3D;&quot;submit&quot; value&#x3D;&quot;Submit&quot; &#x2F;&gt;\n &lt;&#x2F;form&gt;\n &#39;&#39;&#39;\n return render_template_string(page)\n\n\n@app.route(&#39;&#x2F;do_login&#39;, methods&#x3D;[&#39;POST&#39;])\ndef do_login():\n name &#x3D; request.form.get(&#39;user_name&#39;)\n session[&#39;user_name&#39;] &#x3D; name\n return &#39;success&#39;\n\n\n@app.route(&#39;&#x2F;show&#39;)\ndef show():\n return session[&#39;user_name&#39;]\n\n\n@app.route(&#39;&#x2F;logout&#39;)\ndef logout():\n session.pop(&#39;user_name&#39;, None)\n return redirect(url_for(&#39;login&#39;))\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()</code></pre>\n<p><strong>代码的含义</strong></p>\n<p>app.secret_key用于给session加密。</p>\n<p>在/login中将向用户展示一个表单要求输入一个名字submit后将数据以post的方式传递给/do_login/do_login将名字存放在session中。</p>\n<p>如果用户成功登录,访问/show时会显示用户的名字。此时打开调试工具选择session面板会看到有一个cookie的名称为session。</p>\n<p>/logout用于登出通过将session中的user_name字段pop即可。Flask中的session基于字典类型实现调用pop方法时会返回pop的键对应的值如果要pop的键并不存在那么返回值是pop()的第二个参数。</p>\n<p>另外使用redirect()重定向时一定要在前面加上return。</p>\n<h1 id=\"设置session的有效时间\"><a href=\"#设置session的有效时间\" class=\"headerlink\" title=\"设置session的有效时间\"></a>设置session的有效时间</h1><p>设置session的有效时间设置为5分钟。</p>\n<p>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from datetime import timedelta\nfrom flask import session, app\n\nsession.permanent &#x3D; True\napp.permanent_session_lifetime &#x3D; timedelta(minutes&#x3D;5)</code></pre>\n<h1 id=\"使用Cookie\"><a href=\"#使用Cookie\" class=\"headerlink\" title=\"使用Cookie\"></a>使用Cookie</h1><p>Cookie是存储在客户端的记录访问者状态的数据。</p>\n<p>常用的用于记录用户登录状态的session大多是基于cookie实现的。</p>\n<p>cookie可以借助flask.Response来实现。</p>\n<p>使用<code>Response.set_cookie</code>添加和删除cookie。</p>\n<p><code>expires</code>参数用来设置cookie有效时间值可以是<code>datetime</code>对象或者unix时间戳。 </p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">res.set_cookie(key&#x3D;&#39;name&#39;, value&#x3D;&#39;loen&#39;, expires&#x3D;time.time()+6*60)</code></pre>\n<p>上面的expire参数的值表示cookie在从现在开始的6分钟内都是有效的。</p>\n<p>要删除cookie将expire参数的值设为0即可</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">res.set_cookie(&#39;name&#39;, &#39;&#39;, expires&#x3D;0)</code></pre>\n<p>详细的<code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import time\n\nfrom flask import Flask, request, Response\n\napp &#x3D; Flask(__name__)\n\n\n@app.route(&#39;&#x2F;add&#39;)\ndef login():\n res &#x3D; Response(&#39;add cookies&#39;)\n res.set_cookie(key&#x3D;&#39;name&#39;, value&#x3D;&#39;loen&#39;, expires&#x3D;time.time() + 6 * 60)\n return res\n\n\n@app.route(&#39;&#x2F;show&#39;)\ndef show():\n return request.cookies.__str__()\n\n\n@app.route(&#39;&#x2F;del&#39;)\ndef del_cookie():\n res &#x3D; Response(&#39;delete cookies&#39;)\n res.set_cookie(&#39;name&#39;, &#39;&#39;, expires&#x3D;0)\n return res\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()\n</code></pre>\n<h1 id=\"闪存系统-flashing-system\"><a href=\"#闪存系统-flashing-system\" class=\"headerlink\" title=\"闪存系统 flashing system\"></a>闪存系统 flashing system</h1><p>Flask 的闪存系统flashing system用于向用户提供反馈信息这些反馈信息一般是对用户上一次操作的反馈。</p>\n<p>反馈信息是存储在服务器端的,当服务器向客户端返回反馈信息后,<strong>这些反馈信息会被服务器端删除。</strong></p>\n<p>详细的<code>app.py</code>代码如下:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import time\n\nfrom flask import Flask, get_flashed_messages, flash\n\napp &#x3D; Flask(__name__)\napp.secret_key &#x3D; &#39;some_secret&#39;\n\n\n@app.route(&#39;&#x2F;&#39;)\ndef index():\n return &#39;Hello index&#39;\n\n\n@app.route(&#39;&#x2F;gen&#39;)\ndef gen():\n info &#x3D; &#39;access at &#39; + time.time().__str__()\n flash(info)\n return info\n\n\n@app.route(&#39;&#x2F;show1&#39;)\ndef show1():\n return get_flashed_messages().__str__()\n\n\n@app.route(&#39;&#x2F;show2&#39;)\ndef show2():\n return get_flashed_messages().__str__()\n\n\nif __name__ &#x3D;&#x3D; &#39;__main__&#39;:\n app.run()\n</code></pre>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"凡人神将传游戏攻略","slug":"ftzsgl","date":"2023-02-11T09:09:51.000Z","updated":"2024-03-13T08:19:06.755Z","comments":true,"path":"/post/ftzsgl/","link":"","excerpt":"","content":"<h1 id=\"合服活动\"><a href=\"#合服活动\" class=\"headerlink\" title=\"合服活动\"></a>合服活动</h1><p><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2023-02-11-17-48-35-image.png\" alt=\"\"><br>注普通召唤券往后4000给1005000给1006000给1507000给150至此封顶</p>\n<p><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2023-02-11-17-49-07-image.png\" alt=\"\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2023-03-05-21-38-21-image.png\" alt=\"\"><br>注:幻神神魄使用情况,目前不全,欢迎留言补充<br><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2024-01-28-00-27-23-image.png\" alt=\"\"></p>\n<h1 id=\"零氪黄道神武\"><a href=\"#零氪黄道神武\" class=\"headerlink\" title=\"零氪黄道神武\"></a>零氪黄道神武</h1><p><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2023-06-26-10-00-27-image.jpg\" alt=\"\"></p>\n<h1 id=\"摘星楼、秘境、龙珠神将出现顺序\"><a href=\"#摘星楼、秘境、龙珠神将出现顺序\" class=\"headerlink\" title=\"摘星楼、秘境、龙珠神将出现顺序\"></a>摘星楼、秘境、龙珠神将出现顺序</h1><ul>\n<li>摘星楼2金灵圣女、4火神祝融、6水神共工、8敖烈、10万圣公主、12北财神赵公明、14地神后土、16龙吉公主</li>\n<li>秘境1吕玲绮、5孙尚香、9马超、13大乔</li>\n<li>龙珠3蔡文姬、7小乔、11司马懿、15黄月英</li>\n</ul>\n<h1 id=\"炼妖嘉年华\"><a href=\"#炼妖嘉年华\" class=\"headerlink\" title=\"炼妖嘉年华\"></a>炼妖嘉年华</h1><p>九星秘宝<br>50050010001500150050007500后面还有两个不知道</p>\n<h1 id=\"抽卡嘉年华\"><a href=\"#抽卡嘉年华\" class=\"headerlink\" title=\"抽卡嘉年华\"></a>抽卡嘉年华</h1><p>九星秘宝<br>50050010001500,150050007500后面还有两个不知道</p>\n<h1 id=\"归墟\"><a href=\"#归墟\" class=\"headerlink\" title=\"归墟\"></a>归墟</h1><p><img src=\"https://img.huangge1199.cn/blog/ftzsgl/2023-06-27-23-11-15-image.jpg\" alt=\"\"></p>\n<h1 id=\"财神宝轮\"><a href=\"#财神宝轮\" class=\"headerlink\" title=\"财神宝轮\"></a>财神宝轮</h1><p>根据以往经验来看,到一定次数必出对应东西,具体如下:</p>\n<ul>\n<li>40 :一万玉</li>\n<li>80 百分之2</li>\n<li>2501星龙装</li>\n<li>290百分之2</li>\n<li>3702星龙装或福运至宝</li>\n<li>3905万玉</li>\n<li>410百分之5</li>\n<li>6903星龙装<br>推荐是到410次抽一回</li>\n</ul>\n","categories":[{"name":"游戏","slug":"游戏","permalink":"https://hexo.huangge1199.cn/categories/%E6%B8%B8%E6%88%8F/"}],"tags":[{"name":"游戏","slug":"游戏","permalink":"https://hexo.huangge1199.cn/tags/%E6%B8%B8%E6%88%8F/"}]},{"title":"docker镜像构建以及宿主机和容器间的相互拷贝","slug":"dockerBuilder","date":"2023-02-08T07:36:29.000Z","updated":"2023-02-08T08:45:03.169Z","comments":true,"path":"/post/dockerBuilder/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>主要学习docker的相关操作构建镜像、docker容器运行、从容器内往外拷贝文件向容器内拷贝文件进入容器</p>\n<h1 id=\"docker构建镜像\"><a href=\"#docker构建镜像\" class=\"headerlink\" title=\"docker构建镜像\"></a>docker构建镜像</h1><p>编写Dockerfile文件</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi Dockerfile</code></pre>\n<p>文件内输入</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">from nginx</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-15-47-05-image.png\" alt=\"\"></p>\n<p>在同目录执行构建命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker build -t my-nginx .</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-15-48-33-image.png\" alt=\"\"></p>\n<h1 id=\"docker容器运行\"><a href=\"#docker容器运行\" class=\"headerlink\" title=\"docker容器运行\"></a>docker容器运行</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 运行命令\ndocker run --name my-nginx -d -p 40080:80 my-nginx\n# 查看所有容器信息\ndocker ps -a</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-15-54-23-image.png\" alt=\"\"></p>\n<p>浏览器输入<code>IP:40080</code>显示默认nginx页面</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-02-20-image.png\" alt=\"\"></p>\n<h1 id=\"从容器内往外拷贝文件\"><a href=\"#从容器内往外拷贝文件\" class=\"headerlink\" title=\"从容器内往外拷贝文件\"></a>从容器内往外拷贝文件</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 拷贝文件\ndocker cp my-nginx:&#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html&#x2F;index.html index.html\n# 查看文件内容\ncat index.html\n# 修改文件内容\nvi index.html\n# 查看文件内容\ncat index.html</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-06-03-image.png\" alt=\"\"></p>\n<h1 id=\"向容器内拷贝文件\"><a href=\"#向容器内拷贝文件\" class=\"headerlink\" title=\"向容器内拷贝文件\"></a>向容器内拷贝文件</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 拷贝文件\ndocker cp index.html my-nginx:&#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html&#x2F;index.html </code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-08-22-image.png\" alt=\"\"></p>\n<p>浏览器输入<code>IP:40080</code>,显示页面已经改变</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-09-59-image.png\" alt=\"\"></p>\n<h1 id=\"进入容器\"><a href=\"#进入容器\" class=\"headerlink\" title=\"进入容器\"></a>进入容器</h1><p>为了方便查看变化,这里拷贝了一份不一样的文件进人容器,执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 修改文件名\nmv index.html new.html\n# 修改文件内容\nvi new.html\n# 拷贝文件进容器\ndocker cp new.html my-nginx:&#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html&#x2F;new.html\n# 查看修改文件的内容\ncat new.html</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-34-23-image.png\" alt=\"\"></p>\n<p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 从容器中拷贝nginx配置文件\ndocker cp my-nginx:&#x2F;etc&#x2F;nginx&#x2F;conf.d&#x2F;default.conf .\n# 查看配置文件\ncat default.conf</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-29-28-image.png\" alt=\"\"></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 修改配置文件\nvi default.conf\n# 查看修改后的配置文件\ncat default.conf</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-30-01-image.png\" alt=\"\"></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 再将配置文件拷贝回容器\ndocker cp default.conf my-nginx:&#x2F;etc&#x2F;nginx&#x2F;conf.d&#x2F;default.conf\n# 进入容器\ndocker exec -it my-nginx &#x2F;bin&#x2F;bash\n# 查看拷贝进容器的文件\ncat &#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html&#x2F;new.html</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-37-58-image.png\" alt=\"\"></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看拷贝进容器的nginx配置文件\ncat &#x2F;etc&#x2F;nginx&#x2F;conf.d&#x2F;default.conf\n# 重启nginx\nnginx -s reload\n# 退出容器\nexit</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-38-52-image.png\" alt=\"\"></p>\n<p>浏览器输入<code>IP:40080</code>,显示页面已经改变</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerBuilder/2023-02-08-16-39-30-image.png\" alt=\"\"></p>\n","categories":[{"name":"云原生2023","slug":"云原生2023","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F2023/"}],"tags":[{"name":"云原生2023","slug":"云原生2023","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F2023/"}]},{"title":"免费HTTPS证书部署","slug":"useFreeSSL","date":"2023-02-07T07:15:03.000Z","updated":"2023-02-07T08:19:59.689Z","comments":true,"path":"/post/useFreeSSL/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>由于腾讯云限制了免费证书的使用个数,而我之前因为免费就随意了很多,现在,一个正在使用的证书过期了,没法继续使用,这样就导致了在浏览器中不能一步到位的打开网站</p>\n<h1 id=\"网站介绍\"><a href=\"#网站介绍\" class=\"headerlink\" title=\"网站介绍\"></a>网站介绍</h1><p>使用的是<a href=\"https://freessl.cn/\">FreeSSL.cn</a>网站该网站提供免费的HTTPS证书申请下面是网站首页</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-29-10-image.png\" alt=\"\"></p>\n<h1 id=\"安装acme-sh\"><a href=\"#安装acme-sh\" class=\"headerlink\" title=\"安装acme.sh\"></a>安装acme.sh</h1><p>我们需要先在服务器上安装acme.sh建议使用root用户安装</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">curl https:&#x2F;&#x2F;get.acme.sh | sh -s email&#x3D;my@example.com</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-49-45-image.png\" alt=\"\"></p>\n<h1 id=\"ACME-域名配置\"><a href=\"#ACME-域名配置\" class=\"headerlink\" title=\"ACME 域名配置\"></a>ACME 域名配置</h1><p>在首页中输入想要申请证书的域名,点击后面的按钮</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-31-54-image.png\" alt=\"\"></p>\n<p>点击下一步</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-32-57-image.png\" alt=\"\"></p>\n<p>根据内容,去你的域名管理处添加信息,添加后回来点击按钮</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-38-46-image.png\" alt=\"\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-15-40-47-image.png\" alt=\"\"></p>\n<p>出现下面的页面,可以先直接点击完成</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-02-28-image.png\" alt=\"\"></p>\n<h1 id=\"部署证书\"><a href=\"#部署证书\" class=\"headerlink\" title=\"部署证书\"></a>部署证书</h1><p>acme.sh 部署命令,这个就是上面图中的内容</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">acme.sh --issue -d blog.huangge1199.cn --dns dns_dp --server [专属 ACME 地址]</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-07-46-image.png\" alt=\"\"></p>\n<p>生成证书,注意生成证书的路径根据自己的情况修改</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">acme.sh --install-cert -d blog.huangge1199.cn \\\n--key-file &#x2F;www&#x2F;server&#x2F;panel&#x2F;vhost&#x2F;cert&#x2F;blog.huangge1199.cn&#x2F;key.pem \\\n--fullchain-file &#x2F;www&#x2F;server&#x2F;panel&#x2F;vhost&#x2F;cert&#x2F;blog.huangge1199.cn&#x2F;cert.pem \\\n--reloadcmd &quot;service nginx reload&quot;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-09-45-image.png\" alt=\"\"></p>\n<p>修改nginx配置文件添加如下的内容证书文件的路径和名字同生成证书的路径与名字一致</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">ssl_certificate &#x2F;www&#x2F;server&#x2F;panel&#x2F;vhost&#x2F;cert&#x2F;blog.huangge1199.cn&#x2F;cert.pem;\nssl_certificate_key &#x2F;www&#x2F;server&#x2F;panel&#x2F;vhost&#x2F;cert&#x2F;blog.huangge1199.cn&#x2F;key.pem;\nssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;\nssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\nssl_prefer_server_ciphers on;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-12-23-image.png\" alt=\"\"></p>\n<p>nginx最好再重启一次</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">service nginx reload</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-13-25-image.png\" alt=\"\"></p>\n<h1 id=\"验证\"><a href=\"#验证\" class=\"headerlink\" title=\"验证\"></a>验证</h1><p>点击跳转,<a href=\"[https://blog.huangge1199.cn/](https://blog.huangge1199.cn/\">龙儿之家</a>)</p>\n<p><img src=\"https://img.huangge1199.cn/blog/useFreeSSL/2023-02-07-16-15-44-image.png\" alt=\"\"></p>\n","categories":[{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/categories/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}],"tags":[{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/tags/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}]},{"title":"群晖安装PostgreSQL","slug":"inPostgreSqlBySynology","date":"2023-01-15T06:57:00.000Z","updated":"2023-02-14T00:37:25.621Z","comments":true,"path":"/post/inPostgreSqlBySynology/","link":"","excerpt":"","content":"<h1 id=\"确认套件中心有PostgreSQL\"><a href=\"#确认套件中心有PostgreSQL\" class=\"headerlink\" title=\"确认套件中心有PostgreSQL\"></a>确认套件中心有PostgreSQL</h1><p>我这边在套件中心中搜索到PostgreSQL了要安装就先要确认有它我这边的环境的spk7d 系统版本</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inPostgreSqlBySynology/2023-01-15-15-20-42-image.png\" alt=\"\"></p>\n<p>我在套件中心设置的套件来源有2个</p>\n<ul>\n<li><p><a href=\"https://packages.synocommunity.com/\">https://packages.synocommunity.com/</a></p>\n</li>\n<li><p><a href=\"https://spk7.imnks.com/\">https://spk7.imnks.com/</a></p>\n</li>\n</ul>\n<p><img src=\"https://img.huangge1199.cn/blog/inPostgreSqlBySynology/2023-01-15-15-17-48-image.png\" alt=\"\"></p>\n<h1 id=\"安装\"><a href=\"#安装\" class=\"headerlink\" title=\"安装\"></a>安装</h1><p>这步就简单了,直接在套件中心安装套件即可,安装过程中,需要设置用户名、密码和端口号,端口号不能重复的</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inPostgreSqlBySynology/2023-01-15-15-22-35-image.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"TDengine安装使用","slug":"tgengine-1","date":"2022-11-24T07:03:40.000Z","updated":"2022-11-24T09:53:57.437Z","comments":true,"path":"/post/tgengine-1/","link":"","excerpt":"","content":"<h1 id=\"引言\"><a href=\"#引言\" class=\"headerlink\" title=\"引言\"></a>引言</h1><p>近期听说了时序数据库TDengine本人的好奇心又出来了同是时序数据库的InfluxDB不也挺好的嘛通过一些网上的资料以及些简单的实际操作本人得出的结论是</p>\n<ul>\n<li><p>数据量少时InfluxDB的性能好些</p>\n</li>\n<li><p>当数据量越来越大之后TDengine就更适合你使用了</p>\n</li>\n</ul>\n<h1 id=\"内容介绍\"><a href=\"#内容介绍\" class=\"headerlink\" title=\"内容介绍\"></a>内容介绍</h1><p>本文将会围绕TGengine进行简单的介绍当然我也是初次使用这份文档也只是初步的学习记录如果有朋友在实际中使用了TGengine并且觉得这篇文章有什么问题还请在下方留言我会根据实际情况对文章进行修改这样也是为了防止给别人留坑</p>\n<ol>\n<li><p>对TGengine做下简单介绍摘抄自官方文档</p>\n</li>\n<li><p>安装TGengine服务端的过程</p>\n</li>\n<li><p>TDengine 数据建模</p>\n</li>\n<li><p>DataGrip如何查看数据</p>\n</li>\n<li><p>使用java语言进行REST连接测试</p>\n</li>\n</ol>\n<p>另外,我这边服务端是使用<code>TDengine-server-2.6.0.30-Linux-x64.tar.gz</code>进行安装的</p>\n<h1 id=\"介绍\"><a href=\"#介绍\" class=\"headerlink\" title=\"介绍\"></a>介绍</h1><blockquote>\n<p>注:本段内容摘自<a href=\"https://docs.taosdata.com/2.6/intro/\">官方文档</a></p>\n</blockquote>\n<p>TDengine 是一款高性能、分布式、支持 SQL 的时序数据库 (Database)其核心代码包括集群功能全部开源开源协议AGPL v3.0。TDengine 能被广泛运用于物联网、工业互联网、车联网、IT 运维、金融等领域。除核心的时序数据库 (Database) 功能外TDengine 还提供缓存、数据订阅、流式计算等大数据平台所需要的系列功能,最大程度减少研发和运维的复杂度。</p>\n<h1 id=\"牢骚\"><a href=\"#牢骚\" class=\"headerlink\" title=\"牢骚\"></a>牢骚</h1><p>在对比的过程中我发现TDengine的官方文档不是太好怎么说尼虽然更改方面都提及到了但是需要看很多内容之后才能完全的解决好这个就不是太好了。比如说安装虽然在立即开始里面有但是详细的安装卸载是放在运维指南里面按照我们的习惯从上往下从左往右可能看到最后才看到安装和卸载但是在这之前却是有大量的实际操作文档在中间夹杂。</p>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-15-26-47-image.png\" alt=\"\"></p>\n<h1 id=\"安装服务端\"><a href=\"#安装服务端\" class=\"headerlink\" title=\"安装服务端\"></a>安装服务端</h1><p>目前 2.X 版服务端 taosd 和 taosAdapter 仅在 Linux 系统上安装和运行,应用驱动 taosc 与 TDengine CLI 可以在 Windows 或 Linux 上安装和运行。另外在 2.4 之前的版本中没有 taosAdapterRESTful 接口是由 taosd 内置的 HTTP 服务提供的。</p>\n<ol>\n<li><p>下载安装包<font color='green'>TDengine-server-2.6.0.30-Linux-x64.tar.gz (45 M)</font>并上传至服务器</p>\n<p>链接: <a href=\"https://pan.baidu.com/s/1-w7O2xUuq0iaF1glh36bow?pwd=ansm\">https://pan.baidu.com/s/1-w7O2xUuq0iaF1glh36bow?pwd=ansm</a> 提取码: ansm </p>\n</li>\n<li><p>进入安装包所在目录,解压文件</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 解压命令\ntar -zxvf TDengine-server-2.6.0.30-Linux-x64.tar.gz</code></pre>\n</li>\n<li><p>进入解压目录,执行其中的 install.sh 安装脚本</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 进入解压目录命令(目录根据自己的解决自行更改)\ncd &#x2F;app&#x2F;TDengine-server-2.6.0.30\n# 执行安装命令\n.&#x2F;install.sh</code></pre>\n</li>\n</ol>\n<blockquote>\n<p>注:中途两次输入,直接回车就好,什么都不用输入</p>\n</blockquote>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/42c99f658589ee0c93af7c4742ce9616684c4ef6.png\" alt=\"2022-11-24-16-07-50-image.png\"></p>\n<ol>\n<li><p>启动taosd并确认状态</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 启动命令\nsystemctl start taosd\n# 确认状态\nsystemctl status taosd</code></pre>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-16-30-image.png\" alt=\"\"></p>\n<ol>\n<li><p>启动taosAdapter并确认状态</p>\n<blockquote>\n<p>注TDengine 在 2.4 版本之后包含一个独立组件 taosAdapter 需要使用 systemctl 命令管理 taosAdapter 服务的启动和停止,不符合的要跳过本步骤</p>\n</blockquote>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">&#96;&#96;&#96;shell\n# 启动命令\nsystemctl start taosadapter\n# 确认状态\nsystemctl status taosadapter</code></pre>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">\n![](https:&#x2F;&#x2F;img.huangge1199.cn&#x2F;blog&#x2F;tgengine-1&#x2F;2022-11-24-16-23-43-image.png) \n\n6. 进入taos确认安装成功、\n \n &#96;&#96;&#96;shell\n # 启动命令(默认密码taosdata)\n taos -p</code></pre>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-27-20-image.png\" alt=\"\"> </p>\n<h1 id=\"TDengine-数据建模\"><a href=\"#TDengine-数据建模\" class=\"headerlink\" title=\"TDengine 数据建模\"></a>TDengine 数据建模</h1><ol>\n<li><p>创建数据库</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建数据库命令\nCREATE DATABASE power;\n# 切换数据库\nUSE power;</code></pre>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-33-10-image.png\" alt=\"\"></p>\n<ol>\n<li><p>创建表</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建表\ncreate table t (ts timestamp, speed int);\n# 插入2条数据(建议插入两条记录时隔几秒)\ninsert into t values (now, 10);\ninsert into t values (now, 20);</code></pre>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-37-22-image.png\" alt=\"\"></p>\n<ol>\n<li><p>查询表数据</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查询表 t\nselect * from t;</code></pre>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-38-51-image.png\" alt=\"\"></p>\n<h1 id=\"DataGrip查看数据\"><a href=\"#DataGrip查看数据\" class=\"headerlink\" title=\"DataGrip查看数据\"></a>DataGrip查看数据</h1><ol>\n<li><p>编译jar</p>\n<p>从 GitHub 仓库克隆 JDBC 连接器的源码,<code>git clone https://github.com/taosdata/taos-connector-jdbc.git -b 2.0.40</code>(此处推荐 -b 指定发布了的 Tags 版本)</p>\n<p>克隆完源码后,若是编译 2.0.40 及以下版本的將commons-logging 依赖包的 scope 值由 test 改为 compile</p>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-59-32-image.png\" alt=\"\"></p>\n<p>在目录下执行:<code>mvn clean package -D maven.test.skip=true</code></p>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-17-02-35-image.png\" alt=\"\"></p>\n<ol>\n<li><p>自建驱动</p>\n<p>使用Driver and Data Source自建驱动注意红框内容jar包是之前编译生成的</p>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-16-48-41-image.png\" alt=\"\"></p>\n<ol>\n<li><p>创建数据库连接</p>\n<p>第一个红框Driver选择之前自建的第二个红框URL 写<code>jdbc:TAOS-RS://IP:6041/数据库名</code></p>\n</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-17-08-57-image.png\" alt=\"\"></p>\n<h1 id=\"java进行REST连接测试\"><a href=\"#java进行REST连接测试\" class=\"headerlink\" title=\"java进行REST连接测试\"></a>java进行REST连接测试</h1><p>新建Springboot项目maven引入jar包</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;dependency&gt;\n &lt;groupId&gt;com.taosdata.jdbc&lt;&#x2F;groupId&gt;\n &lt;artifactId&gt;taos-jdbcdriver&lt;&#x2F;artifactId&gt;\n &lt;version&gt;2.0.40&lt;&#x2F;version&gt;\n&lt;&#x2F;dependency&gt;</code></pre>\n<p>main 方法:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public static void main(String[] args) throws SQLException &#123;\n String jdbcUrl &#x3D; &quot;jdbc:TAOS-RS:&#x2F;&#x2F;IP:6041&#x2F;数据库名?user&#x3D;用户名&amp;password&#x3D;密码&quot;;\n Connection conn &#x3D; DriverManager.getConnection(jdbcUrl);\n System.out.println(&quot;Connected&quot;);\n conn.close();\n&#125;</code></pre>\n<p>测试结果:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/tgengine-1/2022-11-24-17-15-33-image.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"群晖nas上部署gitea后修改IP地址","slug":"giteaNas","date":"2022-10-25T03:14:24.000Z","updated":"2022-10-25T04:43:45.854Z","comments":true,"path":"/post/giteaNas/","link":"","excerpt":"","content":"<h1 id=\"事件\"><a href=\"#事件\" class=\"headerlink\" title=\"事件\"></a>事件</h1><p>今天我在nas的套件中心中发现了Gitea这个套件想到自己的代码都是保存在GitHub或者Gitee上面的<br>于是乎我边在nas上面装了这个套件装备将代码在nas里面也备份一份</p>\n<p>我的nas所在网络没有公网IP用内网穿透形式弄的但是在用穿透后的<code>IP:端口</code>进入时,就报了下面的警告</p>\n<p><img src=\"https://img.huangge1199.cn/blog/giteaNas/2022-10-25-12-25-02-image.png\" alt=\"\"></p>\n<p>看介绍,是说地址不一样了,绿框中的地址分别是我本地地址和穿透后的公网地址,为了方便,我就想把地址换成<br>公网的地址,这样以后复制地址什么的也方便</p>\n<h1 id=\"换IP\"><a href=\"#换IP\" class=\"headerlink\" title=\"换IP\"></a>换IP</h1><p>有两种方法:</p>\n<ol>\n<li>每次都将本地IP改为穿透的公网ip</li>\n<li>修改配置文件<code>conf.ini</code></li>\n</ol>\n<p>第一种方法需要每一次都改,太麻烦了,我这里使用的是第二种方法</p>\n<p>群晖的gitea的配置文件是在安装目录下的<code>/var</code>下面,我安装在<code>/var/packages</code>里</p>\n<p><img src=\"https://img.huangge1199.cn/blog/giteaNas/2022-10-25-12-24-05-1666671836575.jpg\" alt=\"\"></p>\n<p>打开<code>conf.ini</code>文件注意这地方需要root权限因此执行命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi conf.ini</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/giteaNas/2022-10-25-12-31-55-image.png\" alt=\"\"></p>\n<p>将12行这地方改成穿透后的公网IP</p>\n<h1 id=\"重启gitea套件\"><a href=\"#重启gitea套件\" class=\"headerlink\" title=\"重启gitea套件\"></a>重启gitea套件</h1><ol>\n<li>在套件中心中找到gitea然后停用</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/giteaNas/2022-10-25-12-38-13-image.png\" alt=\"\"></p>\n<ol>\n<li>启动gitea</li>\n</ol>\n<p><img src=\"https://img.huangge1199.cn/blog/giteaNas/2022-10-25-12-39-15-image.png\" alt=\"\"></p>\n<h1 id=\"完成验证\"><a href=\"#完成验证\" class=\"headerlink\" title=\"完成验证\"></a>完成验证</h1><p>为了确保成功,完成后再通过穿透后的公网进入,页面的红框消失</p>\n","categories":[{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/categories/nas/"},{"name":"安装部署","slug":"nas/安装部署","permalink":"https://hexo.huangge1199.cn/categories/nas/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/tags/nas/"}]},{"title":"vue下el-popover组件实现滚轴跟随功能","slug":"elPopover","date":"2022-10-19T06:13:52.000Z","updated":"2022-10-19T06:29:55.526Z","comments":true,"path":"/post/elPopover/","link":"","excerpt":"","content":"<h1 id=\"描述\"><a href=\"#描述\" class=\"headerlink\" title=\"描述\"></a>描述</h1><p>使用的是点击触发弹出内容,目标是在弹出内容的情况下,上下来回滚动鼠标,弹出内容和点击按钮不分离</p>\n<p>通过监听页面滚动来实现功能当监听到页面有滚动时通过组件的updatePopper()方法来更新组件的位置</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><pre class=\"line-numbers language-vue\" data-language=\"vue\"><code class=\"language-vue\">&lt;el-popover \n ref&#x3D;&quot;popover&quot;\n placement&#x3D;&quot;right&quot;\n width&#x3D;&quot;400&quot;\n trigger&#x3D;&quot;click&quot;\n style&#x3D;&quot;position: relative&quot;&gt;\n &lt;el-table :data&#x3D;&quot;gridData&quot;&gt;\n &lt;el-table-column width&#x3D;&quot;150&quot; property&#x3D;&quot;date&quot; label&#x3D;&quot;日期&quot;&gt;&lt;&#x2F;el-table-column&gt;\n &lt;el-table-column width&#x3D;&quot;100&quot; property&#x3D;&quot;name&quot; label&#x3D;&quot;姓名&quot;&gt;&lt;&#x2F;el-table-column&gt;\n &lt;el-table-column width&#x3D;&quot;300&quot; property&#x3D;&quot;address&quot; label&#x3D;&quot;地址&quot;&gt;&lt;&#x2F;el-table-column&gt;\n &lt;&#x2F;el-table&gt;\n &lt;el-button slot&#x3D;&quot;reference&quot;&gt;click 激活&lt;&#x2F;el-button&gt;\n&lt;&#x2F;el-popover&gt;\n\n&lt;script&gt;\nexport default &#123;\n data() &#123;\n return &#123;\n gridData: [&#123;\n date: &#39;2016-05-02&#39;,\n name: &#39;王小虎&#39;,\n address: &#39;上海市普陀区金沙江路 1518 弄&#39;\n &#125;, &#123;\n date: &#39;2016-05-04&#39;,\n name: &#39;王小虎&#39;,\n address: &#39;上海市普陀区金沙江路 1518 弄&#39;\n &#125;, &#123;\n date: &#39;2016-05-01&#39;,\n name: &#39;王小虎&#39;,\n address: &#39;上海市普陀区金沙江路 1518 弄&#39;\n &#125;, &#123;\n date: &#39;2016-05-03&#39;,\n name: &#39;王小虎&#39;,\n address: &#39;上海市普陀区金沙江路 1518 弄&#39;\n &#125;]\n &#125;;\n &#125;,\n mounted() &#123;\n window.addEventListener(&#39;scroll&#39;, this.handleScroll, true)\n &#125;,\n methods: &#123;\n handleScroll() &#123;\n this.$refs.popover.updatePopper()\n &#125;\n &#125;\n&#125;;\n&lt;&#x2F;script&gt;</code></pre>\n","categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"前端/vue","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/vue/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/tags/vue/"}]},{"title":"力扣2415. 反转二叉树的奇数层","slug":"reverse-odd-levels-of-binary-tree","date":"2022-09-19T16:28:22.000Z","updated":"2024-04-25T08:10:09.107Z","comments":true,"path":"/post/reverse-odd-levels-of-binary-tree/","link":"","excerpt":"","content":"<p>311周赛第三题</p>\n<p>原题链接:<a href=\"https://leetcode.cn/problems/reverse-odd-levels-of-binary-tree/\">2415. 反转二叉树的奇数层</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一棵 <strong>完美</strong> 二叉树的根节点 <code>root</code> ,请你反转这棵树中每个 <strong>奇数</strong> 层的节点值。</p>\n\n<ul> \n <li>例如,假设第 3 层的节点值是 <code>[2,1,3,4,7,11,29,18]</code> ,那么反转后它应该变成 <code>[18,29,11,7,4,3,1,2]</code> 。</li> \n</ul>\n\n<p>反转后,返回树的根节点。</p>\n\n<p><strong>完美</strong> 二叉树需满足:二叉树的所有父节点都有两个子节点,且所有叶子节点都在同一层。</p>\n\n<p>节点的 <strong>层数</strong> 等于该节点到根节点之间的边数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p> \n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/07/28/first_case1.png\" style=\"width: 626px; height: 191px;\" /> \n<pre>\n<strong>输入:</strong>root = [2,3,5,8,13,21,34]\n<strong>输出:</strong>[2,5,3,8,13,21,34]\n<strong>解释:</strong>\n这棵树只有一个奇数层。\n在第 1 层的节点分别是 3、5 ,反转后为 5、3 。\n</pre>\n\n<p><strong>示例 2</strong></p> \n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/07/28/second_case3.png\" style=\"width: 591px; height: 111px;\" /> \n<pre>\n<strong>输入:</strong>root = [7,13,11]\n<strong>输出:</strong>[7,11,13]\n<strong>解释:</strong> \n在第 1 层的节点分别是 13、11 ,反转后为 11、13 。 \n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2]\n<strong>输出:</strong>[0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]\n<strong>解释:</strong>奇数层由非零值组成。\n在第 1 层的节点分别是 1、2 ,反转后为 2、1 。\n在第 3 层的节点分别是 1、1、1、1、2、2、2、2 ,反转后为 2、2、2、2、1、1、1、1 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li>树中的节点数目在范围 <code>[1, 2<sup>14</sup>]</code> 内</li> \n <li><code>0 &lt;= Node.val &lt;= 10<sup>5</sup></code></li> \n <li><code>root</code> 是一棵 <strong>完美</strong> 二叉树</li> \n</ul>\n\n<h1 id=\"思路:\"><a href=\"#思路:\" class=\"headerlink\" title=\"思路:\"></a>思路:</h1><blockquote>\n<p>看了灵神的周赛视频讲解,或多或少有影响</p>\n</blockquote>\n<p>这题有两种方法,都可以做交换值:</p>\n<ul>\n<li>BFS</li>\n<li>DFS</li>\n</ul>\n<h1 id=\"BFS代码\"><a href=\"#BFS代码\" class=\"headerlink\" title=\"BFS代码\"></a>BFS代码</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.*;\n\nclass Solution &#123;\n public TreeNode reverseOddLevels(TreeNode root) &#123;\n &#x2F;*\n 如果是空节点直接返回\n *&#x2F;\n if (root &#x3D;&#x3D; null) &#123;\n return null;\n &#125;\n &#x2F;&#x2F; 队列存入每层的节点\n Queue&lt;TreeNode&gt; queue &#x3D; new LinkedList&lt;&gt;();\n queue.add(root);\n int level &#x3D; 0;\n while (!queue.isEmpty()) &#123;\n &#x2F;*\n 拿出每层的节点放入列表中,并将下一层的节点放入队列中\n *&#x2F;\n int size &#x3D; queue.size();\n List&lt;TreeNode&gt; nodeList &#x3D; new ArrayList&lt;&gt;();\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n TreeNode node &#x3D; queue.poll();\n nodeList.add(node);\n if (node.left !&#x3D; null) &#123;\n queue.add(node.left);\n queue.add(node.right);\n &#125;\n &#125;\n &#x2F;*\n 奇数层,在列表中交换收尾节点的值\n *&#x2F;\n if (level &#x3D;&#x3D; 1) &#123;\n int nodeSize &#x3D; nodeList.size();\n for (int i &#x3D; 0; i &lt; nodeSize &#x2F; 2; i++) &#123;\n int num &#x3D; nodeList.get(i).val;\n nodeList.get(i).val &#x3D; nodeList.get(nodeSize - i - 1).val;\n nodeList.get(nodeSize - i - 1).val &#x3D; num;\n &#125;\n &#125;\n &#x2F;&#x2F; 改变奇偶层\n level &#x3D; 1 - level;\n &#125;\n return root;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import Optional\n\n\nclass Solution:\n def reverseOddLevels(self, root: Optional[TreeNode]) -&gt; Optional[TreeNode]:\n queue &#x3D; [root]\n level &#x3D; 1\n while queue[0].left:\n next &#x3D; []\n for node in queue:\n next +&#x3D; [node.left, node.right]\n queue &#x3D; next\n if level:\n for i in range(len(queue) &#x2F;&#x2F; 2):\n node1, node2 &#x3D; queue[i], queue[len(queue) - 1 - i]\n node1.val, node2.val &#x3D; node2.val, node1.val\n level &#x3D; 1 - level\n return root</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n<h1 id=\"DFS代码\"><a href=\"#DFS代码\" class=\"headerlink\" title=\"DFS代码\"></a>DFS代码</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.*;\n\nclass Solution &#123;\n public TreeNode reverseOddLevels(TreeNode root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return root;\n &#125;\n dfs(root.left, root.right, 1);\n return root;\n &#125;\n \n private void dfs(TreeNode left, TreeNode right, int level) &#123;\n if (left &#x3D;&#x3D; null) &#123;\n return;\n &#125;\n if (level &#x3D;&#x3D; 1) &#123;\n &#x2F;&#x2F; 如果是奇数层,交换值\n int tmp &#x3D; left.val;\n left.val &#x3D; right.val;\n right.val &#x3D; tmp;\n &#125;\n dfs(left.left, right.right, 1 - level);\n dfs(left.right, right.left, 1 - level);\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import Optional\n\n\nclass Solution:\n def reverseOddLevels(self, root: Optional[TreeNode]) -&gt; Optional[TreeNode]:\n def dfs(left, right, level: bool) -&gt; None:\n if left is None: return\n if level: left.val, right.val &#x3D; right.val, left.val\n dfs(left.left, right.right, not level)\n dfs(left.right, right.left, not level)\n\n dfs(root.left, root.right, True)\n return root</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2414:最长的字母序连续子字符串的长度","slug":"length-of-the-longest-alphabetical-continuous-substring","date":"2022-09-19T14:47:57.000Z","updated":"2024-04-25T08:10:09.103Z","comments":true,"path":"/post/length-of-the-longest-alphabetical-continuous-substring/","link":"","excerpt":"","content":"<p>311周赛第二题</p>\n<p>原题链接:<a href=\"https://leetcode.cn/problems/length-of-the-longest-alphabetical-continuous-substring/\">2414. 最长的字母序连续子字符串的长度</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p><strong>字母序连续字符串</strong> 是由字母表中连续字母组成的字符串。换句话说,字符串 <code>\"abcdefghijklmnopqrstuvwxyz\"</code> 的任意子字符串都是 <strong>字母序连续字符串</strong> 。</p>\n\n<ul> \n <li>例如,<code>\"abc\"</code> 是一个字母序连续字符串,而 <code>\"acb\"</code> 和 <code>\"za\"</code> 不是。</li> \n</ul>\n\n<p>给你一个仅由小写英文字母组成的字符串 <code>s</code> ,返回其 <strong>最长</strong> 的 字母序连续子字符串 的长度。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>s = \"abacaba\"\n<strong>输出:</strong>2\n<strong>解释:</strong>共有 4 个不同的字母序连续子字符串 \"a\"、\"b\"、\"c\" 和 \"ab\" 。\n\"ab\" 是最长的字母序连续子字符串。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>s = \"abcde\"\n<strong>输出:</strong>5\n<strong>解释:</strong>\"abcde\" 是最长的字母序连续子字符串。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li> \n <li><code>s</code> 由小写英文字母组成</li> \n</ul>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>遍历一次,判断相邻字符是否连续,找到最长的连续子字符串的长度</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int longestContinuousSubstring(String s) &#123;\n int cnt &#x3D; 0;\n int bf &#x3D; 0;\n for (int i &#x3D; 1; i &lt; s.length(); i++) &#123;\n if (s.charAt(i) - s.charAt(i - 1) !&#x3D; 1) &#123;\n cnt &#x3D; Math.max(cnt, i - bf);\n bf &#x3D; i;\n &#125;\n &#125;\n return Math.max(cnt, s.length() - bf);\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def longestContinuousSubstring(self, s: str) -&gt; int:\n cnt &#x3D; bf &#x3D; 0\n for i in range(1, len(s)):\n if ord(s[i]) - ord(s[i - 1]) !&#x3D; 1:\n cnt &#x3D; max(cnt, i - bf)\n bf &#x3D; i\n return max(cnt, len(s) - bf)</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2413:最小偶倍数","slug":"smallestEvenMultiple","date":"2022-09-19T13:47:05.000Z","updated":"2024-04-25T08:10:09.109Z","comments":true,"path":"/post/smallestEvenMultiple/","link":"","excerpt":"","content":"<p>311周赛第一题</p>\n<p>原题链接:<a href=\"https://leetcode.cn/problems/smallest-even-multiple/\">2413. 最小偶倍数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个正整数 <code>n</code> ,返回 <code>2</code><em> </em>和<em> </em><code>n</code> 的最小公倍数(正整数)。</p>\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>n = 5\n<strong>输出:</strong>10\n<strong>解释:</strong>5 和 2 的最小公倍数是 10 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>n = 6\n<strong>输出:</strong>6\n<strong>解释:</strong>6 和 2 的最小公倍数是 6 。注意数字会是它自身的倍数。\n</pre>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 &lt;= n &lt;= 150</code></li> \n</ul>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>这题比较简单,就直接上代码</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button><button type=\"button\" class=\"tab \" data-href=\"categories-3\">Python3 使用lcm</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int smallestEvenMultiple(int n) &#123;\n return n % 2 &#x3D;&#x3D; 0 ? n : n * 2;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def smallestEvenMultiple(self, n: int) -&gt; int:\n return n if n % 2 &#x3D;&#x3D; 0 else n * 2\n</code></pre></div><div class=\"tab-item-content\" id=\"categories-3\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from math import lcm\n\n \nclass Solution:\n def smallestEvenMultiple(self, n: int) -&gt; int:\n return lcm(n, 2)\n</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"python3学习笔记--pairwise","slug":"pyPairwise","date":"2022-09-05T12:52:18.000Z","updated":"2022-09-22T07:39:53.196Z","comments":true,"path":"/post/pyPairwise/","link":"","excerpt":"","content":"<h1 id=\"说明\"><a href=\"#说明\" class=\"headerlink\" title=\"说明\"></a>说明</h1><p>pairwise(iterable)是itertools下的一个方法<br>该方法是会返回传入列表所有相邻元素,如果传入的数据少于两个,会返回空</p>\n<h1 id=\"官方文档\"><a href=\"#官方文档\" class=\"headerlink\" title=\"官方文档\"></a>官方文档</h1><p>Return successive overlapping pairs taken from the input iterable.</p>\n<p>The number of 2-tuples in the output iterator will be one fewer than the number of inputs. It will be empty if the input iterable has fewer than two values.</p>\n<p>Roughly equivalent to:<br><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">def pairwise(iterable):\n # pairwise(&#39;ABCDEFG&#39;) --&gt; AB BC CD DE EF FG\n a, b &#x3D; tee(iterable)\n next(b, None)\n return zip(a, b)</code></pre></p>\n<h1 id=\"源码\"><a href=\"#源码\" class=\"headerlink\" title=\"源码\"></a>源码</h1><p>在<code>itertools.py</code>文件中<br><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class pairwise(object):\n &quot;&quot;&quot;\n Return an iterator of overlapping pairs taken from the input iterator.\n \n s -&gt; (s0,s1), (s1,s2), (s2, s3), ...\n &quot;&quot;&quot;\n def __getattribute__(self, *args, **kwargs): # real signature unknown\n &quot;&quot;&quot; Return getattr(self, name). &quot;&quot;&quot;\n pass\n\n def __init__(self, *args, **kwargs): # real signature unknown\n pass\n\n def __iter__(self, *args, **kwargs): # real signature unknown\n &quot;&quot;&quot; Implement iter(self). &quot;&quot;&quot;\n pass\n\n @staticmethod # known case of __new__\n def __new__(*args, **kwargs): # real signature unknown\n &quot;&quot;&quot; Create and return a new object. See help(type) for accurate signature. &quot;&quot;&quot;\n pass\n\n def __next__(self, *args, **kwargs): # real signature unknown\n &quot;&quot;&quot; Implement next(self). &quot;&quot;&quot;\n pass</code></pre></p>\n<h1 id=\"参考代码\"><a href=\"#参考代码\" class=\"headerlink\" title=\"参考代码\"></a>参考代码</h1><p>代码:<br><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">#!&#x2F;usr&#x2F;bin&#x2F;env python3\n# @Time : 2022&#x2F;9&#x2F;5 20:23\n# @Author : 轩辕龙儿\n# @File : pyPairwise.py \n# @Software: PyCharm\nfrom itertools import pairwise\n\nif __name__ &#x3D;&#x3D; &quot;__main__&quot;:\n arrs &#x3D; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n print(&quot;传入数据0, 1, 2, 3, 4, 5, 6, 7, 8, 9&quot;)\n for arr in pairwise(arrs):\n print(str(arr[0]) + &quot;,&quot; + str(arr[1]))\n print(&quot;------------------------------------&quot;)\n print(&quot;传入数据1&quot;)\n for arr in pairwise([1]):\n print(str(arr[0]) + &quot;,&quot; + str(arr[1]))</code></pre><br>控制台输出:<br><pre class=\"line-numbers language-none\"><code class=\"language-none\">&quot;D:\\Program Files\\Python310\\python.exe&quot; D:&#x2F;project&#x2F;leet-code-python&#x2F;study&#x2F;pyPairwise.py \n传入数据0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n0,1\n1,2\n2,3\n3,4\n4,5\n5,6\n6,7\n7,8\n8,9\n------------------------------------\n传入数据1\n\nProcess finished with exit code 0</code></pre></p>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"历史上的今天--8月17日","slug":"history0817","date":"2022-08-17T02:45:26.000Z","updated":"2022-09-22T07:39:52.892Z","comments":true,"path":"/post/history0817/","link":"","excerpt":"","content":"<p>2016年8月17日</p>\n<ul>\n<li>里约奥运会中国女乒团体夺金</li>\n<li>里约奥运会曹缘获男子单人3米板冠军</li>\n</ul>\n<p>2015年8月17日</p>\n<ul>\n<li>泰国曼谷炸弹袭击事件</li>\n</ul>\n<p>2008年8月17日</p>\n<ul>\n<li>美国游泳神童菲尔普斯在北京奥运会创造神话</li>\n<li>南部非洲发展共同体(南共体)自由贸易区正式启动</li>\n</ul>\n<p>2005年8月17日</p>\n<ul>\n<li>胡锦涛与肯尼亚总统齐贝吉会谈</li>\n</ul>\n<p>2000年8月17日</p>\n<ul>\n<li>三峡库区首批移民抵上海</li>\n</ul>\n<p>1999年8月17日</p>\n<ul>\n<li>土耳其发生强烈地震 1.8万人丧生</li>\n</ul>\n<p>1998年8月17日</p>\n<ul>\n<li>海灯法师名誉案</li>\n<li>克林顿承认和莱温斯基有不正当关系</li>\n</ul>\n<p>1996年8月17日</p>\n<ul>\n<li>俄发射“联盟TM-24”号宇宙飞船</li>\n<li>日本成功发射两颗卫星</li>\n</ul>\n<p>1993年8月17日</p>\n<ul>\n<li>数学家冯康逝世</li>\n</ul>\n<p>1992年8月17日</p>\n<ul>\n<li>清理三角债基本结束</li>\n<li>南部非洲发展共同体成立</li>\n</ul>\n<p>1990年8月17日</p>\n<ul>\n<li>伊拉克从伊朗撤军并释放战俘</li>\n<li>我国建成第一台天文子午环</li>\n</ul>\n<p>1988年8月17日</p>\n<ul>\n<li>巴基斯坦总统齐亚在飞行爆炸中死亡</li>\n</ul>\n<p>1987年8月17日</p>\n<ul>\n<li>德国纳粹党副领袖赫斯死亡</li>\n</ul>\n<p>1982年8月17日</p>\n<ul>\n<li>世界上第一张镭射唱片(CD)的诞生</li>\n<li>中美发表《八一七公报》</li>\n</ul>\n<p>1971年8月17日</p>\n<ul>\n<li>纳粹德国陆军元帅威廉·李斯特病逝</li>\n</ul>\n<p>1969年8月17日</p>\n<ul>\n<li>世界上规模最大的嬉皮士聚会</li>\n</ul>\n<p>1968年8月17日</p>\n<ul>\n<li>尼日利亚内战导致饥荒灾难</li>\n</ul>\n<p>1964年8月17日</p>\n<ul>\n<li>我国试办托拉斯</li>\n</ul>\n<p>1958年8月17日</p>\n<ul>\n<li>北戴河会议掀起全民大炼钢铁运动</li>\n<li>中央通过《关于在农村建立人民公社的决议》</li>\n</ul>\n<p>1952年8月17日</p>\n<ul>\n<li>中国围棋“棋圣”聂卫平出生</li>\n<li>周恩来总理访问苏联</li>\n</ul>\n<p>1949年8月17日</p>\n<ul>\n<li>解放军攻占福州</li>\n<li>日本松川事件发生</li>\n</ul>\n<p>1945年8月17日</p>\n<ul>\n<li>溥仪被苏军俘获</li>\n<li>印度尼西亚八月革命爆发</li>\n</ul>\n<p>1937年8月17日</p>\n<ul>\n<li>中国著名书法家刘炳森出生</li>\n<li>阎海文殉国</li>\n</ul>\n<p>1931年8月17日</p>\n<ul>\n<li>邓演达被逮捕</li>\n</ul>\n<p>1926年8月17日</p>\n<ul>\n<li>中国第三代领导核心江泽民主席诞辰</li>\n</ul>\n<p>1895年8月17日</p>\n<ul>\n<li>《中外纪闻》创刊</li>\n</ul>\n<p>1893年8月17日</p>\n<ul>\n<li>民间音乐家 “瞎子阿炳”华彦钧出生</li>\n</ul>\n<p>1877年8月17日</p>\n<ul>\n<li>左宗棠奏请在新疆设行省</li>\n</ul>\n<p>1850年8月17日</p>\n<ul>\n<li>南美独立战争领袖圣马丁逝世</li>\n</ul>\n<p>1807年8月17日</p>\n<ul>\n<li>轮船在全世界第一次投入商业使用</li>\n</ul>\n<p>1786年8月17日</p>\n<ul>\n<li>普鲁士国王腓特烈大帝逝世</li>\n</ul>\n<p>1740年8月17日</p>\n<ul>\n<li>本笃十四世当选为教皇</li>\n</ul>\n<p>1648年8月17日</p>\n<ul>\n<li>普雷斯顿战役爆</li>\n</ul>\n<p>1601年8月17日</p>\n<ul>\n<li>法国数学家费马出生</li>\n</ul>\n<p>1307年8月17日</p>\n<ul>\n<li>孔子被加封为 “大成至圣文宣王”</li>\n</ul>\n","categories":[{"name":"历史上的今天","slug":"历史上的今天","permalink":"https://hexo.huangge1199.cn/categories/%E5%8E%86%E5%8F%B2%E4%B8%8A%E7%9A%84%E4%BB%8A%E5%A4%A9/"}],"tags":[{"name":"历史上的今天","slug":"历史上的今天","permalink":"https://hexo.huangge1199.cn/tags/%E5%8E%86%E5%8F%B2%E4%B8%8A%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"windows server下安装zookeeper和kafka集群","slug":"dpKafkaZKCluster","date":"2022-07-08T02:42:20.000Z","updated":"2022-09-22T07:39:52.882Z","comments":true,"path":"/post/dpKafkaZKCluster/","link":"","excerpt":"","content":"<h1 id=\"安装说明\"><a href=\"#安装说明\" class=\"headerlink\" title=\"安装说明\"></a>安装说明</h1><p>单机部署zookeeper和kafka集群kafka使用2.8.0版本的该版本已经将zookeeper集成在内了因此只需要下载kafka的包即可。</p>\n<p>安装目录C:/kafka/</p>\n<p>三个节点都在目录下依次为kafka1、kafka2、kafka3</p>\n<h1 id=\"下载\"><a href=\"#下载\" class=\"headerlink\" title=\"下载\"></a>下载</h1><p>从kafka官网下载<a href=\"https://archive.apache.org/dist/kafka/2.8.0/kafka_2.13-2.8.0.tgz\">kafka_2.13-2.8.0.tgz 下载地址</a></p>\n<p>下载好后将内容解压后依次拷贝到kafka1、kafka2、kafka3的目录下作为集群的3个节点</p>\n<h1 id=\"zookeeper\"><a href=\"#zookeeper\" class=\"headerlink\" title=\"zookeeper\"></a>zookeeper</h1><h2 id=\"1、配置文件\"><a href=\"#1、配置文件\" class=\"headerlink\" title=\"1、配置文件\"></a>1、配置文件</h2><p>修改zookeeper的配置文件conf/zookeeper.properties以节点1为例确保有以下内容</p>\n<pre class=\"line-numbers language-properties\" data-language=\"properties\"><code class=\"language-properties\">dataDir&#x3D;C:&#x2F;kafka&#x2F;kafka1&#x2F;zkData\ndataLogDir&#x3D;C:&#x2F;kafka&#x2F;kafka1&#x2F;zkLog\nclientPort&#x3D;2187\n\ntickTime&#x3D;2000\ninitLimit&#x3D;10\nsyncLimit&#x3D;5\n\nserver.1&#x3D;192.168.0.116:2887:3887\nserver.2&#x3D;192.168.0.116:2888:3888\nserver.3&#x3D;192.168.0.116:2889:3889</code></pre>\n<p>三个节点的clientPort依次设置成2187、2188、2189</p>\n<blockquote>\n<p>注意:</p>\n<ul>\n<li><p>三个节点的dataDir和dataLogDir的目录不同</p>\n</li>\n<li><p>dataDir和dataLogDir必须保证目录存在不会根据配置文件自动生成</p>\n</li>\n<li><p>余下内容全部相同</p>\n</li>\n</ul>\n</blockquote>\n<h2 id=\"2、创建myid文件\"><a href=\"#2、创建myid文件\" class=\"headerlink\" title=\"2、创建myid文件\"></a>2、创建myid文件</h2><p>依次在三个节点的dataDir目录下创建myid文件内容依次填入1、2、3。</p>\n<h2 id=\"3、创建启动脚本\"><a href=\"#3、创建启动脚本\" class=\"headerlink\" title=\"3、创建启动脚本\"></a>3、创建启动脚本</h2><p>依次在三个节点kafka的目录下添加启动脚本zkStart.bat</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">.\\bin\\windows\\zookeeper-server-start.bat .\\config\\zookeeper.properties</code></pre>\n<h1 id=\"kafka\"><a href=\"#kafka\" class=\"headerlink\" title=\"kafka\"></a>kafka</h1><h2 id=\"1、修改配置文件\"><a href=\"#1、修改配置文件\" class=\"headerlink\" title=\"1、修改配置文件\"></a>1、修改配置文件</h2><p>修改kafka的配置文件server.properties以节点1为例修改内容如下</p>\n<pre class=\"line-numbers language-properties\" data-language=\"properties\"><code class=\"language-properties\">broker.id&#x3D;0\nlisteners&#x3D;PLAINTEXT:&#x2F;&#x2F;192.168.0.116:9097\nadvertised.listeners&#x3D;PLAINTEXT:&#x2F;&#x2F;192.168.0.116:9097\nhost.name&#x3D; 192.168.0.116\nport&#x3D;9097\nlog.dirs&#x3D;C:&#x2F;kafka&#x2F;kafka1&#x2F;log\nzookeeper.connect&#x3D;192.168.0.116:2187,192.168.0.116:2188,192.168.0.116:2189</code></pre>\n<blockquote>\n<p>注意:</p>\n<ul>\n<li><p>broker.id依次为0、1、2</p>\n</li>\n<li><p>port依次为9097、9098、9099</p>\n</li>\n<li><p>log.dirs必须保证目录存在不会根据配置文件自动生成</p>\n</li>\n</ul>\n</blockquote>\n<h2 id=\"2、创建启动、停止脚本\"><a href=\"#2、创建启动、停止脚本\" class=\"headerlink\" title=\"2、创建启动、停止脚本\"></a>2、创建启动、停止脚本</h2><p>依次在三个节点kafka的目录下添加</p>\n<p>启动脚本start.bat</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">.&#x2F;bin&#x2F;kafka-server-start.sh config&#x2F;server.properties</code></pre>\n<p>停止脚本stop.bat</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">.&#x2F;bin&#x2F;kafka-server-stop.sh config&#x2F;server.properties</code></pre>\n<h1 id=\"测试:发送消息\"><a href=\"#测试:发送消息\" class=\"headerlink\" title=\"测试:发送消息\"></a>测试:发送消息</h1><h2 id=\"1、创建主题\"><a href=\"#1、创建主题\" class=\"headerlink\" title=\"1、创建主题\"></a>1、创建主题</h2><p>在kafka目录下执行下面的命令</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">kafka-topics.bat --create --zookeeper IP:2181 --replication-factor 3 --partitions 1 --topic test7</code></pre>\n<h2 id=\"2、创建生产者\"><a href=\"#2、创建生产者\" class=\"headerlink\" title=\"2、创建生产者\"></a>2、创建生产者</h2><p>在kafka的bin\\windows目录下执行下面的命令</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">kafka-console-producer.bat --broker-list 192.168.0.116:9097,192.168.0.116:9098,192.168.0.116:9099 --topic test7</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dpKafkaZKCluster/2022-07-08-15-14-23-image.png\" alt=\"\"></p>\n<h2 id=\"3、创建消费者\"><a href=\"#3、创建消费者\" class=\"headerlink\" title=\"3、创建消费者\"></a>3、创建消费者</h2><p>在kafka的bin\\windows目录下执行下面的命令</p>\n<pre class=\"line-numbers language-batch\" data-language=\"batch\"><code class=\"language-batch\">kafka-console-consumer.bat --bootstrap-server 192.168.0.116:9097 --topic test7 --from-beginning</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dpKafkaZKCluster/2022-07-08-15-14-57-image.png\" alt=\"\"></p>\n<h2 id=\"4、生产者发送消息消费者接收消息\"><a href=\"#4、生产者发送消息消费者接收消息\" class=\"headerlink\" title=\"4、生产者发送消息消费者接收消息\"></a>4、生产者发送消息消费者接收消息</h2><p>生产者随意输入内容,消费者显示内容</p>\n<p>生产者:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dpKafkaZKCluster/2022-07-08-15-15-55-image.png\" alt=\"\"></p>\n<p>消费者:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dpKafkaZKCluster/2022-07-08-15-16-48-image.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"deepin下安装docker-compose","slug":"inDCByOsDeepin","date":"2022-07-05T13:57:49.000Z","updated":"2022-09-22T07:39:52.923Z","comments":true,"path":"/post/inDCByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"下载文件\"><a href=\"#下载文件\" class=\"headerlink\" title=\"下载文件\"></a>下载文件</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo wget -c -t 0 https:&#x2F;&#x2F;github.com&#x2F;docker&#x2F;compose&#x2F;releases&#x2F;download&#x2F;1.26.0&#x2F;docker-compose-&#96;uname -s&#96;-&#96;uname -m&#96; -O &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inDCByOsDeepin/2022-07-05-21-18-26-image.png\" alt=\"\"></p>\n<h1 id=\"添加执行权限\"><a href=\"#添加执行权限\" class=\"headerlink\" title=\"添加执行权限\"></a>添加执行权限</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo chmod a+rx &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inDCByOsDeepin/2022-07-05-21-20-08-image.png\" alt=\"\"></p>\n<h1 id=\"验证是否安装成功\"><a href=\"#验证是否安装成功\" class=\"headerlink\" title=\"验证是否安装成功\"></a>验证是否安装成功</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker-compose -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inDCByOsDeepin/2022-07-05-21-20-46-image.png\" alt=\"\"></p>\n<h1 id=\"卸载\"><a href=\"#卸载\" class=\"headerlink\" title=\"卸载\"></a>卸载</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo rm &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose</code></pre>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"},{"name":"deepin","slug":"docker/deepin","permalink":"https://hexo.huangge1199.cn/categories/docker/deepin/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"Jenkins通过kubernetes plugin连接K8s集群","slug":"bindK8sToJenkins","date":"2022-06-28T14:21:47.000Z","updated":"2022-09-22T07:39:52.766Z","comments":true,"path":"/post/bindK8sToJenkins/","link":"","excerpt":"","content":"<h2 id=\"一、Jenkins安装kubernetes-plugin插件\"><a href=\"#一、Jenkins安装kubernetes-plugin插件\" class=\"headerlink\" title=\"一、Jenkins安装kubernetes plugin插件\"></a>一、Jenkins安装kubernetes plugin插件</h2><h3 id=\"1-1-点击左侧系统管理\"><a href=\"#1-1-点击左侧系统管理\" class=\"headerlink\" title=\"1.1 点击左侧系统管理\"></a>1.1 点击左侧系统管理</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-26-15-image.png\" alt=\"\"></p>\n<h3 id=\"1-2-点击插件管理\"><a href=\"#1-2-点击插件管理\" class=\"headerlink\" title=\"1.2 点击插件管理\"></a>1.2 点击插件管理</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-27-34-image.png\" alt=\"\"></p>\n<h3 id=\"1-3-安装插件Kubernetes-plugin\"><a href=\"#1-3-安装插件Kubernetes-plugin\" class=\"headerlink\" title=\"1.3 安装插件Kubernetes plugin\"></a>1.3 安装插件Kubernetes plugin</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-28-53-image.png\" alt=\"\"></p>\n<h3 id=\"1-4-安装好后重启Jenkins\"><a href=\"#1-4-安装好后重启Jenkins\" class=\"headerlink\" title=\"1.4 安装好后重启Jenkins\"></a>1.4 安装好后重启Jenkins</h3><p>浏览器输入<a href=\"http://192.168.0.196:8080/restart页面点击“是”重启Jenkins\">http://192.168.0.196:8080/restart页面点击“是”重启Jenkins</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-30-31-image.png\" alt=\"\"></p>\n<h2 id=\"二、进入配置页\"><a href=\"#二、进入配置页\" class=\"headerlink\" title=\"二、进入配置页\"></a>二、进入配置页</h2><h3 id=\"2-1-左侧点击系统管理\"><a href=\"#2-1-左侧点击系统管理\" class=\"headerlink\" title=\"2.1 左侧点击系统管理\"></a>2.1 左侧点击系统管理</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-31-51-image.png\" alt=\"\"></p>\n<h3 id=\"2-2-点击节点管理\"><a href=\"#2-2-点击节点管理\" class=\"headerlink\" title=\"2.2 点击节点管理\"></a>2.2 点击节点管理</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-32-25-image.png\" alt=\"\"></p>\n<h3 id=\"2-3-点击Configure-Clouds\"><a href=\"#2-3-点击Configure-Clouds\" class=\"headerlink\" title=\"2.3 点击Configure Clouds\"></a>2.3 点击Configure Clouds</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-33-15-image.png\" alt=\"\"></p>\n<h2 id=\"三、配置\"><a href=\"#三、配置\" class=\"headerlink\" title=\"三、配置\"></a>三、配置</h2><h3 id=\"3-1-下拉框选择Kubernetes\"><a href=\"#3-1-下拉框选择Kubernetes\" class=\"headerlink\" title=\"3.1 下拉框选择Kubernetes\"></a>3.1 下拉框选择Kubernetes</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-34-14-image.png\" alt=\"\"></p>\n<h3 id=\"3-2-点击Kubernetes-Cloud-details…进入配置详情页\"><a href=\"#3-2-点击Kubernetes-Cloud-details…进入配置详情页\" class=\"headerlink\" title=\"3.2 点击Kubernetes Cloud details…进入配置详情页\"></a>3.2 点击Kubernetes Cloud details…进入配置详情页</h3><p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-35-00-image.png\" alt=\"\"></p>\n<h3 id=\"3-3-填入认证信息\"><a href=\"#3-3-填入认证信息\" class=\"headerlink\" title=\"3.3 填入认证信息\"></a>3.3 填入认证信息</h3><p>需要填写红框内的4个内容</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-42-49-image.png\" alt=\"\"></p>\n<h4 id=\"Kubernetes-地址\"><a href=\"#Kubernetes-地址\" class=\"headerlink\" title=\"Kubernetes 地址\"></a>Kubernetes 地址</h4><p>这个通过命令行 查看</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl cluster-info</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-16-34-image.png\" alt=\"\"></p>\n<p>红框内的就是地址</p>\n<h4 id=\"Kubernetes-服务证书-key\"><a href=\"#Kubernetes-服务证书-key\" class=\"headerlink\" title=\"Kubernetes 服务证书 key\"></a>Kubernetes 服务证书 key</h4><p>为/root/.kube/config中的certificate-authority-data部分并通过base64加密</p>\n<p>终端输入下面的命令查看certificate-authority-data</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">cat .kube&#x2F;config</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-46-52-image.png\" alt=\"\"></p>\n<p>在执行下面的命令进行base64加密</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">echo &quot;certificate-authority-data冒号后面的内容&quot; | base64 -d</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-52-27-image.png\" alt=\"\"></p>\n<p>红框的内容填入“Kubernetes 服务证书 key”中</p>\n<h4 id=\"Kubernetes-命名空间\"><a href=\"#Kubernetes-命名空间\" class=\"headerlink\" title=\"Kubernetes 命名空间\"></a>Kubernetes 命名空间</h4><p>使用default默认就好</p>\n<h4 id=\"凭据\"><a href=\"#凭据\" class=\"headerlink\" title=\"凭据\"></a>凭据</h4><p>这地方需要添加一个凭借</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-54-22-image.png\" alt=\"\"></p>\n<p>在弹出的页面中类型选Secret text</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-22-57-05-image.png\" alt=\"\"></p>\n<p>下面的Secret通过终端添加</p>\n<ul>\n<li>创建一个</li>\n</ul>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl create sa jenkins</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-19-07-image.png\" alt=\"\"></p>\n<p>获取token名</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl describe sa jenkins</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-19-57-image.png\" alt=\"\"></p>\n<p>获取token值</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl describe secrets jenkins-token-szvg9 -n default</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-21-36-image.png\" alt=\"\"></p>\n<p>上图中的token即为Secret填入的内容</p>\n<p>最后的描述可以随意填写</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-07-30-image.png\" alt=\"\"></p>\n<p>点击添加,凭据就好了</p>\n<h2 id=\"四、验证\"><a href=\"#四、验证\" class=\"headerlink\" title=\"四、验证\"></a>四、验证</h2><p>点击连接测试左侧显示k8s集群版本</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-23-35-image.png\" alt=\"\"> </p>\n<p>下面把Jenkins地址填上再点击保存按钮就完成了</p>\n<p><img src=\"https://img.huangge1199.cn/blog/bindK8sToJenkins/2022-06-28-23-26-16-image.png\" alt=\"\"></p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/"}]},{"title":"helm不需要证书安装rancher","slug":"inRancherByHelmNoCert","date":"2022-06-26T03:16:37.000Z","updated":"2022-09-22T07:39:53.027Z","comments":true,"path":"/post/inRancherByHelmNoCert/","link":"","excerpt":"","content":"<h2 id=\"前置\"><a href=\"#前置\" class=\"headerlink\" title=\"前置\"></a>前置</h2><p>安装好k8s和helm</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-16-48-16-image.png\" alt=\"\"></p>\n<h2 id=\"安装命令\"><a href=\"#安装命令\" class=\"headerlink\" title=\"安装命令\"></a>安装命令</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm install rancher rancher-stable&#x2F;rancher \\\n --namespace cattle-system \\\n --set hostname&#x3D;rancher.my.org \\\n --set replicas&#x3D;1 \\\n --set ingress.tls.source&#x3D;secret</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-16-49-50-image.png\" alt=\"\"></p>\n<h2 id=\"设置域名映射\"><a href=\"#设置域名映射\" class=\"headerlink\" title=\"设置域名映射\"></a>设置域名映射</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi &#x2F;etc&#x2F;hosts\n\n# 添加域名映射 \n127.0.0.1 rancher.my.org\n\n# cat &#x2F;etc&#x2F;hosts</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-16-51-20-image.png\" alt=\"\"></p>\n<h2 id=\"确认安装完成\"><a href=\"#确认安装完成\" class=\"headerlink\" title=\"确认安装完成\"></a>确认安装完成</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl -n cattle-system get deploy rancher</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-16-56-27-image.png\" alt=\"\"></p>\n<h2 id=\"浏览器访问\"><a href=\"#浏览器访问\" class=\"headerlink\" title=\"浏览器访问\"></a>浏览器访问</h2><p>浏览器输入 <a href=\"https://rancher.my.org/\">https://rancher.my.org/</a></p>\n<p>高级—》继续访问</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-16-59-29-image.png\" alt=\"\"></p>\n<h2 id=\"密码查看\"><a href=\"#密码查看\" class=\"headerlink\" title=\"密码查看\"></a>密码查看</h2><p>终端输入,查看密码</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get secret --namespace cattle-system bootstrap-secret -o go-template&#x3D;&#39;&#123;&#123;.data.bootstrapPassword|base64decode&#125;&#125;&#123;&#123;&quot;\\n&quot;&#125;&#125;&#39;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-17-01-02-image.png\" alt=\"\"></p>\n<h2 id=\"设置自己好记的密码\"><a href=\"#设置自己好记的密码\" class=\"headerlink\" title=\"设置自己好记的密码\"></a>设置自己好记的密码</h2><p>输入密码进入后选择Set a specific password to use然后下方设置自己的密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-17-02-18-image.png\" alt=\"\"></p>\n<h2 id=\"进入的页面\"><a href=\"#进入的页面\" class=\"headerlink\" title=\"进入的页面\"></a>进入的页面</h2><p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelmNoCert/2022-06-26-17-04-28-image.png\" alt=\"\"></p>\n<p>至此rancher部署完成</p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"deepin主机下通过Kubeadm方式安装K8S","slug":"inK8sByKubeadmByDeepin","date":"2022-06-24T13:39:51.000Z","updated":"2022-09-22T07:39:52.955Z","comments":true,"path":"/post/inK8sByKubeadmByDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、关闭swap\"><a href=\"#1、关闭swap\" class=\"headerlink\" title=\"1、关闭swap\"></a>1、关闭swap</h1><p>依次执行下面的命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看分区的使用状态\nfree -mh\n# 禁用swap分区\nsudo swapoff -a\n# 查看分区的使用状态\nfree -mh</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-21-45-13-image.png\" alt=\"\"></p>\n<h1 id=\"2、添加k8s源\"><a href=\"#2、添加k8s源\" class=\"headerlink\" title=\"2、添加k8s源\"></a>2、添加k8s源</h1><p>编辑文件/etc/apt/sources.list.d/kubernetes.list</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi &#x2F;etc&#x2F;apt&#x2F;sources.list.d&#x2F;kubernetes.list</code></pre>\n<p>插入以下内容:</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">deb https:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;kubernetes&#x2F;apt&#x2F; kubernetes-xenial main</code></pre>\n<p>再执行命令查看:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">cat &#x2F;etc&#x2F;apt&#x2F;sources.list.d&#x2F;kubernetes.list</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-22-10-06-image.png\" alt=\"\"></p>\n<h1 id=\"3、导入k8s密钥\"><a href=\"#3、导入k8s密钥\" class=\"headerlink\" title=\"3、导入k8s密钥\"></a>3、导入k8s密钥</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo curl -fsSL https:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;kubernetes&#x2F;apt&#x2F;doc&#x2F;apt-key.gpg | sudo apt-key add -</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-22-16-25-image.png\" alt=\"\"></p>\n<h1 id=\"4、更新并安装kubeadm-kubelet-和-kubectl\"><a href=\"#4、更新并安装kubeadm-kubelet-和-kubectl\" class=\"headerlink\" title=\"4、更新并安装kubeadm, kubelet 和 kubectl\"></a>4、更新并安装kubeadm, kubelet 和 kubectl</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo apt-get update\nsudo apt-get install kubelet kubeadm kubectl</code></pre>\n<h1 id=\"5、设置阿里云镜像加速\"><a href=\"#5、设置阿里云镜像加速\" class=\"headerlink\" title=\"5、设置阿里云镜像加速\"></a>5、设置阿里云镜像加速</h1><p>编辑文件/etc/docker/daemon.json</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi &#x2F;etc&#x2F;docker&#x2F;daemon.json</code></pre>\n<p>修改成如下内容:</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">&#123;\n &quot;registry-mirrors&quot;: [\n &quot;https:&#x2F;&#x2F;&#123;阿里云分配的地址&#125;.mirror.aliyuncs.com&quot;,\n &quot;https:&#x2F;&#x2F;registry-1.docker.io&#x2F;v2&#x2F;&quot;\n ]\n&#125;</code></pre>\n<p>再执行命令查看:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">cat &#x2F;etc&#x2F;docker&#x2F;daemon.json</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-22-49-46-image.png\" alt=\"\"></p>\n<h1 id=\"6、拉取镜像\"><a href=\"#6、拉取镜像\" class=\"headerlink\" title=\"6、拉取镜像\"></a>6、拉取镜像</h1><p>从阿里云拉取镜像并转换tag执行命令如下</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">for i in &#96;kubeadm config images list&#96;; do\n imageName&#x3D;$&#123;i#k8s.gcr.io&#x2F;&#125;\n docker pull registry.aliyuncs.com&#x2F;google_containers&#x2F;$imageName\n docker tag registry.aliyuncs.com&#x2F;google_containers&#x2F;$imageName k8s.gcr.io&#x2F;$imageName\n docker rmi registry.aliyuncs.com&#x2F;google_containers&#x2F;$imageName\ndone;</code></pre>\n<p>如果有拉取不下来的可以再上网找找镜像然后转换tag或者直接执行下面的命令用docker官方镜像拉取但是官方镜像拉取速度可能会很慢</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">for i in &#96;kubeadm config images list&#96;; do\n docker pull i\ndone;</code></pre>\n<h1 id=\"7、kubeadm初始化\"><a href=\"#7、kubeadm初始化\" class=\"headerlink\" title=\"7、kubeadm初始化\"></a>7、kubeadm初始化</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm init --pod-network-cidr&#x3D;10.244.0.0&#x2F;16</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-23-00-07-image.png\" alt=\"\"></p>\n<h1 id=\"8、执行提示的命令\"><a href=\"#8、执行提示的命令\" class=\"headerlink\" title=\"8、执行提示的命令\"></a>8、执行提示的命令</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mkdir -p $HOME&#x2F;.kube\nsudo cp -i &#x2F;etc&#x2F;kubernetes&#x2F;admin.conf $HOME&#x2F;.kube&#x2F;config\nsudo chown $(id -u):$(id -g) $HOME&#x2F;.kube&#x2F;config</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-23-02-42-image.png\" alt=\"\"></p>\n<h1 id=\"9、安装网络插件\"><a href=\"#9、安装网络插件\" class=\"headerlink\" title=\"9、安装网络插件\"></a>9、安装网络插件</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f https:&#x2F;&#x2F;github.com&#x2F;coreos&#x2F;flannel&#x2F;raw&#x2F;master&#x2F;Documentation&#x2F;kube-flannel.yml</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-23-05-02-image.png\" alt=\"\"></p>\n<h1 id=\"10、安装Ingress\"><a href=\"#10、安装Ingress\" class=\"headerlink\" title=\"10、安装Ingress\"></a>10、安装Ingress</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;kubernetes&#x2F;ingress-nginx&#x2F;controller-v1.1.0&#x2F;deploy&#x2F;static&#x2F;provider&#x2F;cloud&#x2F;deploy.yaml</code></pre>\n<p>查看命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get pods --all-namespaces</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadmByDeepin/2022-06-24-23-41-18-image.png\" alt=\"\"></p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"deepin","slug":"云原生/deepin","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/deepin/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"Helm安装Rancher","slug":"inRancherByHelm","date":"2022-06-18T02:44:37.000Z","updated":"2022-09-22T07:39:53.009Z","comments":true,"path":"/post/inRancherByHelm/","link":"","excerpt":"","content":"<h1 id=\"前置\"><a href=\"#前置\" class=\"headerlink\" title=\"前置\"></a>前置</h1><p>本人是直接在<font color='red'>deeepin</font>系统上用rke安装的k8s集群形式但是只有一个节点<font color='red'>rke</font>是<font color='red'>1.3.10</font>版本的,安装好的<font color='red'>k8s</font>是<font color='red'>1.22.9</font>的版本</p>\n<h1 id=\"前提条件-—-helm安装\"><a href=\"#前提条件-—-helm安装\" class=\"headerlink\" title=\"前提条件 — helm安装\"></a>前提条件 — helm安装</h1><p>安照官网说明安装就可以:<a href=\"https://helm.sh/zh/docs/intro/install/\">官网安装步骤</a></p>\n<p>简单说明:</p>\n<p>我这边是二进制形式安装的</p>\n<ul>\n<li>下载 需要的版本</li>\n<li>解压(tar -zxvf helm-v3.9.0-linux-amd64.tar.gz)</li>\n<li>在解压目中找到helm程序移动到需要的目录中(mv linux-amd64/helm /usr/local/bin/helm)</li>\n</ul>\n<h1 id=\"1、安装证书管理\"><a href=\"#1、安装证书管理\" class=\"headerlink\" title=\"1、安装证书管理\"></a>1、安装证书管理</h1><blockquote>\n<p>这里选用 Rancher 生成的 TLS 证书,因此需要 cert-manager</p>\n</blockquote>\n<h2 id=\"1-1-添加配置\"><a href=\"#1-1-添加配置\" class=\"headerlink\" title=\"1.1 添加配置\"></a>1.1 添加配置</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f https:&#x2F;&#x2F;github.com&#x2F;jetstack&#x2F;cert-manager&#x2F;releases&#x2F;download&#x2F;v1.5.1&#x2F;cert-manager.crds.yaml</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/ca771f4aa96e9cafe14c329195308b345c23427b.png\" alt=\"\"></p>\n<h2 id=\"1-2-添加-Jetstack-Helm-仓库\"><a href=\"#1-2-添加-Jetstack-Helm-仓库\" class=\"headerlink\" title=\"1.2 添加 Jetstack Helm 仓库\"></a>1.2 添加 Jetstack Helm 仓库</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm repo add jetstack https:&#x2F;&#x2F;charts.jetstack.io</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-11-51-51-image.png\" alt=\"\"></p>\n<h2 id=\"1-3-更新本地-Helm-chart-仓库缓存\"><a href=\"#1-3-更新本地-Helm-chart-仓库缓存\" class=\"headerlink\" title=\"1.3 更新本地 Helm chart 仓库缓存\"></a>1.3 更新本地 Helm chart 仓库缓存</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm repo update</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-11-53-22-image.png\" alt=\"\"></p>\n<h2 id=\"1-4-安装-cert-manager-Helm-chart\"><a href=\"#1-4-安装-cert-manager-Helm-chart\" class=\"headerlink\" title=\"1.4 安装 cert-manager Helm chart\"></a>1.4 安装 cert-manager Helm chart</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm install cert-manager jetstack&#x2F;cert-manager \\\n --namespace cert-manager \\\n --create-namespace \\\n --version v1.5.1</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-11-55-29-image.png\" alt=\"\"></p>\n<p>如果报错内容如下:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-11-56-38-image.png\" alt=\"\"></p>\n<p>可做如下操作:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 列出空间列表\nhelm ls --all-namespaces\n# 删除\nkubectl delete namespace cert-manager\n# 列出空间列表\nhelm ls --all-namespaces</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-11-59-43-image.png\" alt=\"\"></p>\n<p>然后在重新执行命令即可</p>\n<h2 id=\"1-5-确认安装成功\"><a href=\"#1-5-确认安装成功\" class=\"headerlink\" title=\"1.5 确认安装成功\"></a>1.5 确认安装成功</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get pods --namespace cert-manager</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-02-27-image.png\" alt=\"\"></p>\n<h1 id=\"2、安装ingress-nginx\"><a href=\"#2、安装ingress-nginx\" class=\"headerlink\" title=\"2、安装ingress-nginx\"></a>2、安装ingress-nginx</h1><h2 id=\"2-1-添加ingress-nginx-repo\"><a href=\"#2-1-添加ingress-nginx-repo\" class=\"headerlink\" title=\"2.1 添加ingress-nginx repo\"></a>2.1 添加ingress-nginx repo</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm repo add ingress-nginx https:&#x2F;&#x2F;kubernetes.github.io&#x2F;ingress-nginx</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-10-24-image.png\" alt=\"\"></p>\n<h2 id=\"2-2-安装\"><a href=\"#2-2-安装\" class=\"headerlink\" title=\"2.2 安装\"></a>2.2 安装</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm install ingress-nginx ingress-nginx&#x2F;ingress-nginx -n kube-system \\</code></pre>\n<h1 id=\"3、安装rancher\"><a href=\"#3、安装rancher\" class=\"headerlink\" title=\"3、安装rancher\"></a>3、安装rancher</h1><h2 id=\"3-1-添加rancher-repo\"><a href=\"#3-1-添加rancher-repo\" class=\"headerlink\" title=\"3.1 添加rancher repo\"></a>3.1 添加rancher repo</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm repo add rancher-stable https:&#x2F;&#x2F;releases.rancher.com&#x2F;server-charts&#x2F;stable</code></pre>\n<h2 id=\"3-2-查看列表\"><a href=\"#3-2-查看列表\" class=\"headerlink\" title=\"3.2 查看列表\"></a>3.2 查看列表</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm repo list</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-12-48-image.png\" alt=\"\"></p>\n<h2 id=\"3-3-安装\"><a href=\"#3-3-安装\" class=\"headerlink\" title=\"3.3 安装\"></a>3.3 安装</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">helm install rancher rancher-stable&#x2F;rancher \\\n&gt; --namespace cattle-system \\\n&gt; --create-namespace \\\n&gt; --set hostname&#x3D;rancher.my.org \\\n&gt; --no-hooks \\\n&gt; --version 2.6.5</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-18-50-image.png\" alt=\"\"></p>\n<blockquote>\n<p>配置的hostname=rancher.my.org这个域名需要添加到 <code>/etc/hosts</code></p>\n</blockquote>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-24-48-image.png\" alt=\"\"></p>\n<h2 id=\"3-4-运行\"><a href=\"#3-4-运行\" class=\"headerlink\" title=\"3.4 运行\"></a>3.4 运行</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl -n cattle-system rollout status deploy&#x2F;rancher</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-19-21-image.png\" alt=\"\"></p>\n<h2 id=\"3-5-查看-Rancher-运行状态\"><a href=\"#3-5-查看-Rancher-运行状态\" class=\"headerlink\" title=\"3.5 查看 Rancher 运行状态\"></a>3.5 查看 Rancher 运行状态</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl -n cattle-system get deploy rancher</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-20-59-image.png\" alt=\"\"></p>\n<p>至此Rancher部署完成</p>\n<h2 id=\"3-6-浏览器查看\"><a href=\"#3-6-浏览器查看\" class=\"headerlink\" title=\"3.6 浏览器查看\"></a>3.6 浏览器查看</h2><p><a href=\"https://rancher.my.org/\">https://rancher.my.org/</a> ,进入后简单配置下就可以了</p>\n<p>默认密码在终端输入下面的命令,显示的就是默认密码,之后可以修改成自己好记的密码</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get secret --namespace cattle-system bootstrap-secret -o go-template&#x3D;&#39;&#123;&#123;.data.bootstrapPassword|base64decode&#125;&#125;&#123;&#123;&quot;\\n&quot;&#125;&#125;&#39;</code></pre>\n<p>进入后的样子:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRancherByHelm/2022-06-18-12-27-32-image.png\" alt=\"\"></p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"deepin下安装hexo","slug":"inHexoByOsDeepin","date":"2022-06-03T06:51:52.000Z","updated":"2022-11-24T07:09:04.666Z","comments":true,"path":"/post/inHexoByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、前置条件\"><a href=\"#1、前置条件\" class=\"headerlink\" title=\"1、前置条件\"></a>1、前置条件</h1><p>安装好nodejs</p>\n<p>参考:<a href=\"http://192.168.0.198:5080/post/inNodejsByOsDeepin/\">deepin下安装nodejs</a></p>\n<h1 id=\"2、全局安装Hexo\"><a href=\"#2、全局安装Hexo\" class=\"headerlink\" title=\"2、全局安装Hexo\"></a>2、全局安装Hexo</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">npm install -g hexo-cli</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inHexoByOsDeepin/image-20220603141423311.png\" alt=\"\"></p>\n<h1 id=\"3、创建软链接\"><a href=\"#3、创建软链接\" class=\"headerlink\" title=\"3、创建软链接\"></a>3、创建软链接</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建hexo软链接\nsudo ln -s &#x2F;home&#x2F;deepin&#x2F;app&#x2F;node&#x2F;bin&#x2F;hexo &#x2F;usr&#x2F;local&#x2F;bin&#x2F;\n# 查看软链接列表\nsudo ls -l &#x2F;usr&#x2F;local&#x2F;bin&#x2F;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inHexoByOsDeepin/image-20220603141527169.png\" alt=\"\"></p>\n<h1 id=\"4、查看Hexo版本\"><a href=\"#4、查看Hexo版本\" class=\"headerlink\" title=\"4、查看Hexo版本\"></a>4、查看Hexo版本</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">hexo -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inHexoByOsDeepin/image-20220603141613298.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装nodejs","slug":"inNodejsByOsDeepin","date":"2022-06-03T06:51:52.000Z","updated":"2022-09-22T07:39:52.980Z","comments":true,"path":"/post/inNodejsByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、下载安装包\"><a href=\"#1、下载安装包\" class=\"headerlink\" title=\"1、下载安装包\"></a>1、下载安装包</h1><p><a href=\"https://nodejs.org/en/download/\">官网地址</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603110634896.png\" alt=\"image-20220603110634896\"></p>\n<blockquote>\n<p>注意版本</p>\n</blockquote>\n<h1 id=\"2、解压安装包\"><a href=\"#2、解压安装包\" class=\"headerlink\" title=\"2、解压安装包\"></a>2、解压安装包</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 解压命令\ntar -xf node-v16.15.1-linux-x64.tar.xz\n# 查看列表\nls -l</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603111656347.png\" alt=\"image-20220603111656347\"></p>\n<h1 id=\"3、移动文件\"><a href=\"#3、移动文件\" class=\"headerlink\" title=\"3、移动文件\"></a>3、移动文件</h1><p>这步是为了方便找到自己安装的软件,可做可不做</p>\n<p>我这边是统一移动到用户的app目录下</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 移动文件\nmv node-v16.15.1-linux-x64 ..&#x2F;app&#x2F;\n# 查看列表\nls -l\n# 切换目录\ncd ..&#x2F;app&#x2F;\n# 查看列表\nls -l\n# 更改名称(目录名过长)\nmv node-v16.15.1-linux-x64 node\n# 查看列表\nls -l</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603112001543.png\" alt=\"image-20220603112001543\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603112153367.png\" alt=\"image-20220603112153367\"></p>\n<h1 id=\"4、创建软链接\"><a href=\"#4、创建软链接\" class=\"headerlink\" title=\"4、创建软链接\"></a>4、创建软链接</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建node软链接\nsudo ln -s &#x2F;home&#x2F;deepin&#x2F;app&#x2F;node&#x2F;bin&#x2F;node &#x2F;usr&#x2F;local&#x2F;bin&#x2F;\n# 创建npm软链接\nsudo ln -s &#x2F;home&#x2F;deepin&#x2F;app&#x2F;node&#x2F;bin&#x2F;npm &#x2F;usr&#x2F;local&#x2F;bin&#x2F;\n# 确认软链接建立好了\nsudo ls -l &#x2F;usr&#x2F;local&#x2F;bin&#x2F;</code></pre>\n<blockquote>\n<p>此处涉及到权限问题,因此命令前要加<code>sudo</code></p>\n</blockquote>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603112904096.png\" alt=\"image-20220603112904096\"></p>\n<h1 id=\"5、确认node和npm版本\"><a href=\"#5、确认node和npm版本\" class=\"headerlink\" title=\"5、确认node和npm版本\"></a>5、确认node和npm版本</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">node -v\nnpm -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603113034176.png\" alt=\"image-20220603113034176\"></p>\n<h1 id=\"6、设置镜像\"><a href=\"#6、设置镜像\" class=\"headerlink\" title=\"6、设置镜像\"></a>6、设置镜像</h1><p>设置国内淘宝的镜像提高npm的下载速度</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看npm配置列表\nnpm config list\n# 执行如下命令设置成国内的镜像\nnpm config set registry https:&#x2F;&#x2F;registry.npm.taobao.org\n# 查看npm配置列表\nnpm config list</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByOsDeepin/image-20220603113454241.png\" alt=\"image-20220603113454241\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装nvm","slug":"inNvmByOsDeepin","date":"2022-06-03T06:51:52.000Z","updated":"2023-02-15T06:15:21.788Z","comments":true,"path":"/post/inNvmByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、下载安装包\"><a href=\"#1、下载安装包\" class=\"headerlink\" title=\"1、下载安装包\"></a>1、下载安装包</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">wget https:&#x2F;&#x2F;github.com&#x2F;nvm-sh&#x2F;nvm&#x2F;archive&#x2F;refs&#x2F;tags&#x2F;v0.39.2.tar.gz -O nvm-0.39.2.tar.gz</code></pre>\n<p><img src=\"/home/huangge1199/Projects/my-blog/source/_posts/inNvmByOsDeepin/image-20221209002248521.png\" alt=\"image-20221209002248521\"></p>\n<h1 id=\"2、解压\"><a href=\"#2、解压\" class=\"headerlink\" title=\"2、解压\"></a>2、解压</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">tar -zxvf nvm-0.39.2.tar.gz</code></pre>\n<h1 id=\"3、安装\"><a href=\"#3、安装\" class=\"headerlink\" title=\"3、安装\"></a>3、安装</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 切换目录\ncd nvm-0.39.2&#x2F;\n# 执行安装命令\n.&#x2F;install.sh\n# 查看nvm版本检查是否安装成功\nnvm -v</code></pre>\n<p><img src=\"/home/huangge1199/Projects/my-blog/source/_posts/inNvmByOsDeepin/image-20221209004412627.png\" alt=\"image-20221209004412627\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装vue","slug":"inVueByOsDeepin","date":"2022-06-03T06:51:52.000Z","updated":"2022-09-22T07:39:53.067Z","comments":true,"path":"/post/inVueByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、前置条件\"><a href=\"#1、前置条件\" class=\"headerlink\" title=\"1、前置条件\"></a>1、前置条件</h1><p>安装好nodejs</p>\n<p>参考:<a href=\"http://192.168.0.198:5080/post/inNodejsByOsDeepin/\">deepin下安装nodejs</a></p>\n<h1 id=\"2、全局安装Vue\"><a href=\"#2、全局安装Vue\" class=\"headerlink\" title=\"2、全局安装Vue\"></a>2、全局安装Vue</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 下面两个版本的二选一哦\nnpm install -g @vue&#x2F;cli\t\t&#x2F;&#x2F;vue3.0\nnpm install -g vue-cli\t\t&#x2F;&#x2F;vue2.0</code></pre>\n<p>我这边安装的是3.0版本的</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inVueByOsDeepin/image-20220603114033774.png\" alt=\"image-20220603114033774\"></p>\n<h1 id=\"3、全局安装webpack\"><a href=\"#3、全局安装webpack\" class=\"headerlink\" title=\"3、全局安装webpack\"></a>3、全局安装webpack</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">npm install -g webpack</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inVueByOsDeepin/image-20220603114219499.png\" alt=\"image-20220603114219499\"></p>\n<h1 id=\"4、创建软链接\"><a href=\"#4、创建软链接\" class=\"headerlink\" title=\"4、创建软链接\"></a>4、创建软链接</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建Vue软链接\nsudo ln -s &#x2F;home&#x2F;deepin&#x2F;app&#x2F;node&#x2F;bin&#x2F;vue &#x2F;usr&#x2F;local&#x2F;bin&#x2F;\n# 创建webpack软链接\nsudo ln -s &#x2F;home&#x2F;deepin&#x2F;app&#x2F;node&#x2F;bin&#x2F;webpack &#x2F;usr&#x2F;local&#x2F;bin&#x2F;\n# 查看软链接列表\nsudo ls -l &#x2F;usr&#x2F;local&#x2F;bin&#x2F;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inVueByOsDeepin/image-20220603114513508.png\" alt=\"image-20220603114513508\"></p>\n<h1 id=\"5、查看Vue版本\"><a href=\"#5、查看Vue版本\" class=\"headerlink\" title=\"5、查看Vue版本\"></a>5、查看Vue版本</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vue --version</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inVueByOsDeepin/image-20220603114616673.png\" alt=\"image-20220603114616673\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装Maven","slug":"inMavenByOsDeepin","date":"2022-06-03T06:46:52.000Z","updated":"2022-09-22T07:39:52.966Z","comments":true,"path":"/post/inMavenByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、前置条件\"><a href=\"#1、前置条件\" class=\"headerlink\" title=\"1、前置条件\"></a>1、前置条件</h1><p>安装好jdk</p>\n<p>参考:<a href=\"http://192.168.0.198:5080/post/inJdkByOsDeepin/\">deepin下安装jdk</a></p>\n<h1 id=\"2、下载安装包\"><a href=\"#2、下载安装包\" class=\"headerlink\" title=\"2、下载安装包\"></a>2、下载安装包</h1><p>官网地址:<a href=\"https://maven.apache.org/download.cgi\">maven下载页面</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603115702494.png\" alt=\"image-20220603115702494\"></p>\n<p>我这边下载的是3.8.5版本的,如果下载其他版本,用下面的链接:</p>\n<p><a href=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/https://archive.apache.org/dist/maven/maven-3/\">其他版本maven</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603120000596.png\" alt=\"image-20220603120000596\"></p>\n<h1 id=\"3、解压\"><a href=\"#3、解压\" class=\"headerlink\" title=\"3、解压\"></a>3、解压</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">tar -xf apache-maven-3.8.5-bin.tar.gz\nls -l</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603120156243.png\" alt=\"image-20220603120156243\"></p>\n<h1 id=\"4、移动\"><a href=\"#4、移动\" class=\"headerlink\" title=\"4、移动\"></a>4、移动</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mv apache-maven-3.8.5 ..&#x2F;app&#x2F;\nls -l\nls -l ..&#x2F;app&#x2F;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603120347751.png\" alt=\"image-20220603120347751\"></p>\n<h1 id=\"5、配置环境变量\"><a href=\"#5、配置环境变量\" class=\"headerlink\" title=\"5、配置环境变量\"></a>5、配置环境变量</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi &#x2F;etc&#x2F;profile</code></pre>\n<p>文件最下面加入下面的内容</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\"># configuration maven development enviroument\nexport MAVEN_HOME&#x3D;&#x2F;home&#x2F;deepin&#x2F;app&#x2F;apache-maven-3.8.5\nexport PATH&#x3D;$PATH:$MAVEN_HOME&#x2F;bin</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603121051155.png\" alt=\"image-20220603121051155\"></p>\n<p>执行命令让配置文件生效:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">source &#x2F;etc&#x2F;profile</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603121153205.png\" alt=\"image-20220603121153205\"></p>\n<h1 id=\"6、验证\"><a href=\"#6、验证\" class=\"headerlink\" title=\"6、验证\"></a>6、验证</h1><p>查看maven版本做验证</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mvn -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603121458972.png\" alt=\"image-20220603121458972\"></p>\n<h1 id=\"7、配置仓库文件目录\"><a href=\"#7、配置仓库文件目录\" class=\"headerlink\" title=\"7、配置仓库文件目录\"></a>7、配置仓库文件目录</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;home&#x2F;deepin&#x2F;app&#x2F;apache-maven-3.8.5&#x2F;conf&#x2F;settings.xml</code></pre>\n<p>找到localRepository在下方加入下面的内容</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;localRepository&gt;&#x2F;home&#x2F;deepin&#x2F;repo&lt;&#x2F;localRepository&gt;</code></pre>\n<p>红框内容为新加入的</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603122200505.png\" alt=\"image-20220603122200505\"></p>\n<h1 id=\"8、添加阿里镜像源\"><a href=\"#8、添加阿里镜像源\" class=\"headerlink\" title=\"8、添加阿里镜像源\"></a>8、添加阿里镜像源</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;home&#x2F;deepin&#x2F;app&#x2F;apache-maven-3.8.5&#x2F;conf&#x2F;settings.xml</code></pre>\n<p>找到mirror添加下面的内容</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;mirror&gt;\t\n &lt;id&gt;alimaven&lt;&#x2F;id&gt;\n &lt;mirrorOf&gt;*&lt;&#x2F;mirrorOf&gt;\n &lt;name&gt;aliyun maven&lt;&#x2F;name&gt;\n &lt;url&gt;https:&#x2F;&#x2F;maven.aliyun.com&#x2F;repository&#x2F;public&lt;&#x2F;url&gt;\n&lt;&#x2F;mirror&gt;</code></pre>\n<p>下面红框内容为添加的</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inMavenByOsDeepin/image-20220603122859128.png\" alt=\"image-20220603122859128\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"nvm安装nodejs","slug":"inNodejsByNvm","date":"2022-06-03T06:46:52.000Z","updated":"2023-03-15T06:20:21.727Z","comments":true,"path":"/post/inNodejsByNvm/","link":"","excerpt":"","content":"<h1 id=\"nvm下载\"><a href=\"#nvm下载\" class=\"headerlink\" title=\"nvm下载\"></a>nvm下载</h1><p><a href=\"https://github.com/coreybutler/nvm-windows\">nvm的GitHub下载地址</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-23-07-image.png\" alt=\"\"></p>\n<p>进入后下载</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-24-26-image.png\" alt=\"\"></p>\n<h1 id=\"nvm安装\"><a href=\"#nvm安装\" class=\"headerlink\" title=\"nvm安装\"></a>nvm安装</h1><p>下载后双击exe文件进行安装同意后点击next</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-26-41-image.png\" alt=\"\"></p>\n<p>设置安装目录</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-28-55-image.png\" alt=\"\"></p>\n<p>设置nodejs目录最好不要带空格</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-31-09-image.png\" alt=\"\"></p>\n<p>点击install安装</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-31-34-image.png\" alt=\"\"></p>\n<p>点击Finish安装完成</p>\n<h1 id=\"nvm添加淘宝镜像\"><a href=\"#nvm添加淘宝镜像\" class=\"headerlink\" title=\"nvm添加淘宝镜像\"></a>nvm添加淘宝镜像</h1><p>打开nvm安装目录下的settings.txt文件添加淘宝镜像地址红框内为新增的</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">node_mirror: https:&#x2F;&#x2F;npm.taobao.org&#x2F;mirrors&#x2F;node&#x2F;\nnpm_mirror: https:&#x2F;&#x2F;npm.taobao.org&#x2F;mirrors&#x2F;npm&#x2F;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-40-28-image.png\" alt=\"\"></p>\n<h1 id=\"nvm设置环境变量\"><a href=\"#nvm设置环境变量\" class=\"headerlink\" title=\"nvm设置环境变量\"></a>nvm设置环境变量</h1><p>此电脑右键点击属性</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-22-47-21-image.png\" alt=\"\"></p>\n<p>点击高级系统设置</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-06-30-image.png\" alt=\"\"></p>\n<p>点击环境变量</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-08-12-image.png\" alt=\"\"></p>\n<p>确认环境变量中有NVM_HOME和NVM_SYMLINK</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-10-10-image.png\" alt=\"\"></p>\n<p>确认</p>\n<p>管理员身份运行cmd执行查看的命令确认安装成功</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">nvm -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-16-26-image.png\" alt=\"\"></p>\n<h1 id=\"node安装\"><a href=\"#node安装\" class=\"headerlink\" title=\"node安装\"></a>node安装</h1><p>执行命令列出有效可下载的node版本</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">nvm list available</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-20-11-image.png\" alt=\"\"></p>\n<p>执行安装命令安装指定版本的node</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">nvm install &lt;version&gt;</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-21-39-image.png\" alt=\"\"></p>\n<p>执行命令查看已安装的node版本</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">nvm list</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-22-47-image.png\" alt=\"\"></p>\n<p>执行命令使用某个版本的node</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-25-48-image.png\" alt=\"\"></p>\n<p>执行命令查看node版本</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">node -v</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-26-48-image.png\" alt=\"\"></p>\n<h1 id=\"node环境变量\"><a href=\"#node环境变量\" class=\"headerlink\" title=\"node环境变量\"></a>node环境变量</h1><p>新建目录node_global、node_cache可以建在nodejs目录下 </p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-33-44-image.png\" alt=\"\"></p>\n<p>新建环境变量变量名NODE_PATH变量值node_global路径\\node_modules</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-37-35-image.png\" alt=\"\"></p>\n<p>在Path环境变量中增加node_global路径</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inNodejsByNvm/2023-01-14-23-41-08-image.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装jdk","slug":"inJdkByOsDeepin","date":"2022-06-03T06:43:52.000Z","updated":"2022-09-22T07:39:52.933Z","comments":true,"path":"/post/inJdkByOsDeepin/","link":"","excerpt":"","content":"<h1 id=\"1、jdk-下载\"><a href=\"#1、jdk-下载\" class=\"headerlink\" title=\"1、jdk 下载\"></a>1、jdk 下载</h1><p><a href=\"https://www.oracle.com/java/technologies/downloads/#java11\">官网下载地址</a>如下:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inJdkByOsDeepin/image-20220603015920009.png\" alt=\"image-20220603015920009\"></p>\n<blockquote>\n<p>注意区分是哪个版本的</p>\n</blockquote>\n<h1 id=\"2、安装deb包\"><a href=\"#2、安装deb包\" class=\"headerlink\" title=\"2、安装deb包\"></a>2、安装deb包</h1><p>终端进入到deb文件所在目录执行安装命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo dpkg -i jdk-11.0.15.1_linux-x64_bin.deb</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inJdkByOsDeepin/image-20220603020439325.png\" alt=\"image-20220603020439325\"></p>\n<h1 id=\"3、配置环境变量\"><a href=\"#3、配置环境变量\" class=\"headerlink\" title=\"3、配置环境变量\"></a>3、配置环境变量</h1><p>终端执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo vi &#x2F;etc&#x2F;profile</code></pre>\n<p>然后输入密码,在文件的最后加上下面的内容</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">#configuration java development enviroument\nexport JAVA_HOME&#x3D;&#x2F;usr&#x2F;lib&#x2F;jvm&#x2F;jdk-11\nexport PATH&#x3D;$JAVA_HOME&#x2F;bin:$PATH \nexport CLASSPATH&#x3D;.:$JAVA_HOME&#x2F;lib&#x2F;dt.jar:$JAVA_HOME&#x2F;lib&#x2F;tools.jar </code></pre>\n<h1 id=\"4、使环境变量生效\"><a href=\"#4、使环境变量生效\" class=\"headerlink\" title=\"4、使环境变量生效\"></a>4、使环境变量生效</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">source &#x2F;etc&#x2F;profile</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inJdkByOsDeepin/image-20220603021925685.png\" alt=\"image-20220603021925685\"></p>\n<h1 id=\"5、检查是否成功\"><a href=\"#5、检查是否成功\" class=\"headerlink\" title=\"5、检查是否成功\"></a>5、检查是否成功</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-she\" data-language=\"she\"><code class=\"language-she\">java -version</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inJdkByOsDeepin/image-20220603022022217.png\" alt=\"image-20220603022022217\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"deepin下安装git","slug":"inGitByOsDeepin","date":"2022-06-03T06:30:52.000Z","updated":"2022-09-22T07:39:52.929Z","comments":true,"path":"/post/inGitByOsDeepin/","link":"","excerpt":"","content":"<blockquote>\n<p>个人建议直接终端安装,下面的安装也是终端命令行安装的</p>\n</blockquote>\n<h1 id=\"1、安装git\"><a href=\"#1、安装git\" class=\"headerlink\" title=\"1、安装git\"></a>1、安装git</h1><p>执行安装命令:</p>\n<pre class=\"line-numbers language-she\" data-language=\"she\"><code class=\"language-she\">sudo apt-get install git</code></pre>\n<p><img src=\"inGitByOsDeepin/image-20220603103757605.png\" alt=\"image-20220603103757605\"></p>\n<h1 id=\"2、确认git安装成功\"><a href=\"#2、确认git安装成功\" class=\"headerlink\" title=\"2、确认git安装成功\"></a>2、确认git安装成功</h1><p>执行查看git版本的命令以此确认安装成功</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git --version</code></pre>\n<p><img src=\"inGitByOsDeepin/image-20220603103959058.png\" alt=\"image-20220603103959058\"></p>\n<h1 id=\"3、配置git全局用户名和邮箱\"><a href=\"#3、配置git全局用户名和邮箱\" class=\"headerlink\" title=\"3、配置git全局用户名和邮箱\"></a>3、配置git全局用户名和邮箱</h1><p>配置全局用户名:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git config --global user.name &quot;用户名&quot;</code></pre>\n<p><img src=\"inGitByOsDeepin/image-20220603104225094.png\" alt=\"image-20220603104225094\"></p>\n<p>配置全局邮箱:</p>\n<pre class=\"line-numbers language-shel\" data-language=\"shel\"><code class=\"language-shel\">git config --global user.email &quot;邮箱&quot;</code></pre>\n<p><img src=\"inGitByOsDeepin/image-20220603104335664.png\" alt=\"image-20220603104335664\"></p>\n<h1 id=\"4、确认配置结果\"><a href=\"#4、确认配置结果\" class=\"headerlink\" title=\"4、确认配置结果\"></a>4、确认配置结果</h1><p>查看配置信息确认</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">git config --list</code></pre>\n<p><img src=\"inGitByOsDeepin/image-20220603104447770.png\" alt=\"image-20220603104447770\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"}]},{"title":"docker构建自定义镜像","slug":"createMyImage","date":"2022-05-31T07:07:55.000Z","updated":"2022-09-22T07:39:52.812Z","comments":true,"path":"/post/createMyImage/","link":"","excerpt":"","content":"<h1 id=\"1、编写Dockerfile\"><a href=\"#1、编写Dockerfile\" class=\"headerlink\" title=\"1、编写Dockerfile\"></a>1、编写Dockerfile</h1><p>Dockerfile</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">FROM nginx\nRUN apt update &amp;&amp; apt install -y vim</code></pre>\n<h1 id=\"2、构建镜像\"><a href=\"#2、构建镜像\" class=\"headerlink\" title=\"2、构建镜像\"></a>2、构建镜像</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker build -t vim-nginx:1 .</code></pre>\n<blockquote>\n<p>注要在Dockerfile所在目录下执行</p>\n</blockquote>\n<p>这步时间较长,多等等,出现下面红框表示安装成功</p>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-16-21-41-image.png\" alt=\"\"></p>\n<p>完成后,执行命令确认镜像生成:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker images</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-16-28-07-image.png\" alt=\"\"></p>\n<h1 id=\"3、测试镜像\"><a href=\"#3、测试镜像\" class=\"headerlink\" title=\"3、测试镜像\"></a>3、测试镜像</h1><p>启动容器:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker run -d --name new-nginx vim-nginx:1\ndocker ps -a</code></pre>\n<p>下面红框内是执行过程,中间的部分我命令敲错了,忽略掉</p>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-16-32-54-image.png\" alt=\"\"></p>\n<p>进入容器使用vim命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker exec -it new-nginx bash\nvim 123.txt\nexit</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-17-08-23-image.png\" alt=\"\"></p>\n<p>停止容器:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker stop new-nginx\ndocker ps -a</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-17-11-22-image.png\" alt=\"\"></p>\n<p>删除容器:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker rm new-nginx\ndocker ps -a</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-17-12-17-image.png\" alt=\"\"></p>\n<h1 id=\"4、docker登录\"><a href=\"#4、docker登录\" class=\"headerlink\" title=\"4、docker登录\"></a>4、docker登录</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker login</code></pre>\n<p>然后输入用户名和密码</p>\n<blockquote>\n<p>注:用户名不是登录的邮箱</p>\n</blockquote>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-17-22-07-image.png\" alt=\"\"></p>\n<h1 id=\"5、镜像修改\"><a href=\"#5、镜像修改\" class=\"headerlink\" title=\"5、镜像修改\"></a>5、镜像修改</h1><p>tag命令修改为规范的镜像</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker tag vim-nginx:1 huangge1199&#x2F;vim-nginx:1\ndocker images</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-05-31-17-30-38-image.png\" alt=\"\"></p>\n<h1 id=\"6、推送镜像\"><a href=\"#6、推送镜像\" class=\"headerlink\" title=\"6、推送镜像\"></a>6、推送镜像</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker push huangge1199&#x2F;vim-nginx:1</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-06-01-08-37-12-image.png\" alt=\"\"></p>\n<p>网页进入自己的docker仓库</p>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-06-01-08-38-34-image.png\" alt=\"\"></p>\n<h1 id=\"7、删除本地镜像\"><a href=\"#7、删除本地镜像\" class=\"headerlink\" title=\"7、删除本地镜像\"></a>7、删除本地镜像</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker rmi huangge1199&#x2F;vim-nginx:1\ndocker images</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-06-01-08-39-28-image.png\" alt=\"\"></p>\n<h1 id=\"8、拉取镜像\"><a href=\"#8、拉取镜像\" class=\"headerlink\" title=\"8、拉取镜像\"></a>8、拉取镜像</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull huangge1199&#x2F;vim-nginx:1\ndocker images</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/createMyImage/2022-06-01-08-42-46-image.png\" alt=\"\"> </p>\n<h1 id=\"9、重复3的步骤测试镜像\"><a href=\"#9、重复3的步骤测试镜像\" class=\"headerlink\" title=\"9、重复3的步骤测试镜像\"></a>9、重复3的步骤测试镜像</h1><blockquote>\n<p>注意步骤3和现在的镜像名可能不同记得替换</p>\n</blockquote>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"}]},{"title":"通过Kubeadm方式安装K8S","slug":"inK8sByKubeadm","date":"2022-05-31T06:10:52.000Z","updated":"2022-09-22T07:39:52.940Z","comments":true,"path":"/post/inK8sByKubeadm/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>根据前几次的经验这一次运用脚本的形式安装可以节约大部分的步骤把一些前置的配置什么的写到shell脚本里面随着<code>vagrant up</code>启动命令一起安装</p>\n<p>集群环境:</p>\n<div class=\"table-container\">\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\"></th>\n<th>IP</th>\n<th>内存</th>\n<th>CPU核数</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">master</td>\n<td>172.17.8.51</td>\n<td>4G</td>\n<td>2</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">node</td>\n<td>172.17.8.52</td>\n<td>4G</td>\n<td>1</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">node</td>\n<td>172.17.8.53</td>\n<td>4G</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n</div>\n<h1 id=\"1、编写Vagrantfile文件\"><a href=\"#1、编写Vagrantfile文件\" class=\"headerlink\" title=\"1、编写Vagrantfile文件\"></a>1、编写Vagrantfile文件</h1><p>Vagrantfile内容</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\"># -*- mode: ruby -*-\n# vi: set ft&#x3D;ruby :\n# on win10, you need &#96;vagrant plugin install vagrant-vbguest --plugin-version 0.21&#96; and change synced_folder.type&#x3D;&quot;virtualbox&quot;\n# reference &#96;https:&#x2F;&#x2F;www.dissmeyer.com&#x2F;2020&#x2F;02&#x2F;11&#x2F;issue-with-centos-7-vagrant-boxes-on-windows-10&#x2F;&#96;\n\n\nVagrant.configure(&quot;2&quot;) do |config|\n config.vm.box_check_update &#x3D; false\n config.vm.provider &#39;virtualbox&#39; do |vb|\n vb.customize [ &quot;guestproperty&quot;, &quot;set&quot;, :id, &quot;&#x2F;VirtualBox&#x2F;GuestAdd&#x2F;VBoxService&#x2F;--timesync-set-threshold&quot;, 1000 ]\n end \n $num_instances &#x3D; 3\n # curl https:&#x2F;&#x2F;discovery.etcd.io&#x2F;new?size&#x3D;3\n (1..$num_instances).each do |i|\n config.vm.define &quot;node#&#123;i&#125;&quot; do |node|\n node.vm.box &#x3D; &quot;centos&#x2F;7&quot;\n node.vm.hostname &#x3D; &quot;node#&#123;i&#125;&quot;\n ip &#x3D; &quot;172.17.8.#&#123;i+50&#125;&quot;\n node.vm.network &quot;private_network&quot;, ip: ip\n node.vm.provider &quot;virtualbox&quot; do |vb|\n vb.memory &#x3D; &quot;4096&quot;\n if i&#x3D;&#x3D;1 then\n vb.cpus &#x3D; 2\n else\n vb.cpus &#x3D; 1\n end\n vb.name &#x3D; &quot;node#&#123;i+50&#125;&quot;\n end\n end\n end\n config.vm.provision &quot;shell&quot;, privileged: true, path: &quot;.&#x2F;setup.sh&quot;\nend</code></pre>\n<h1 id=\"2、编写启动后的脚本\"><a href=\"#2、编写启动后的脚本\" class=\"headerlink\" title=\"2、编写启动后的脚本\"></a>2、编写启动后的脚本</h1><p>setup.sh内容</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">#&#x2F;bin&#x2F;sh\n\n# 安装docker相关依赖\nsudo yum install -y yum-utils\n\n# 添加阿里源\nsudo yum-config-manager \\\n --add-repo \\\n http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;docker-ce&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo\nsudo sed -i &#39;s&#x2F;gpgcheck&#x3D;1&#x2F;gpgcheck&#x3D;0&#x2F;g&#39; &#x2F;etc&#x2F;yum.repos.d&#x2F;docker-ce.repo \n# 安装docker\nyes y|sudo yum install docker-ce docker-ce-cli containerd.io\n\n# 启动docker\nsudo systemctl start docker\ny\ny\n\n# 更改cgroup driver以及docker镜像仓库源\nsudo bash -c &#39;cat &gt; &#x2F;etc&#x2F;docker&#x2F;daemon.json &lt;&lt;EOF\n&#123;\n &quot;exec-opts&quot;: [&quot;native.cgroupdriver&#x3D;systemd&quot;],\n &quot;log-driver&quot;: &quot;json-file&quot;,\n &quot;log-opts&quot;: &#123;\n &quot;max-size&quot;: &quot;100m&quot;\n &#125;,\n &quot;storage-driver&quot;: &quot;overlay2&quot;,\n &quot;storage-opts&quot;: [\n &quot;overlay2.override_kernel_check&#x3D;true&quot;\n ],\n &quot;registry-mirrors&quot;: [\n &quot;https:&#x2F;&#x2F;registry.docker-cn.com&quot;,\n &quot;http:&#x2F;&#x2F;hub-mirror.c.163.com&quot;,\n &quot;https:&#x2F;&#x2F;w5a7th34.mirror.aliyuncs.com&quot;,\n &quot;http:&#x2F;&#x2F;f1361db2.m.daocloud.io&quot;,\n &quot;https:&#x2F;&#x2F;mirror.ccs.tencentyun.com&quot;\n ]\n&#125;\nEOF&#39;\n\n# 添加docker组\nif [ ! $(getent group docker) ];\nthen \n sudo groupadd docker;\nelse\n echo &quot;docker user group already exists&quot;\nfi\n\nsudo gpasswd -a $USER docker\n\n# 加载、重启docker\nsudo systemctl daemon-reload\nsudo systemctl restart docker\n\nsudo sed -i &#39;s&#x2F;PasswordAuthentication no&#x2F;PasswordAuthentication yes&#x2F;g&#39; &#x2F;etc&#x2F;ssh&#x2F;sshd_config\nsudo systemctl restart sshd\n\nsudo bash -c &#39;cat &lt;&lt;EOF &gt; &#x2F;etc&#x2F;yum.repos.d&#x2F;kubernetes.repo\n[kubernetes]\nname&#x3D;Kubernetes\nbaseurl&#x3D;https:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;kubernetes&#x2F;yum&#x2F;repos&#x2F;kubernetes-el7-x86_64\nenabled&#x3D;1\ngpgcheck&#x3D;0\nrepo_gpgcheck&#x3D;0\ngpgkey&#x3D;https:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;kubernetes&#x2F;yum&#x2F;doc&#x2F;yum-key.gpg\nhttps:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;kubernetes&#x2F;yum&#x2F;doc&#x2F;rpm-package-key.gpg\nEOF&#39;\n\nsudo setenforce 0\n\n# 安装kubeadm, kubectl, kubelet\nsudo yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6 --disableexcludes&#x3D;kubernetes\n\n# 设置docker和kubelet开机自启并启动\nsudo systemctl enable docker &amp;&amp; systemctl start docker\nsudo systemctl enable kubelet &amp;&amp; systemctl start kubelet\n\n# 设置网络桥接\nsudo bash -c &#39;cat &lt;&lt;EOF &gt; &#x2F;etc&#x2F;sysctl.d&#x2F;k8s.conf\nnet.bridge.bridge-nf-call-ip6tables &#x3D; 1\nnet.bridge.bridge-nf-call-iptables &#x3D; 1\nnet.ipv4.ip_forward&#x3D;1\nEOF&#39;\nsudo sysctl --system\n\n# 关闭防火墙\nsudo systemctl stop firewalld\nsudo systemctl disable firewalld\n\n# 关闭swap\nsudo swapoff -a\n\n# 设置开机自启\nsudo systemctl enable docker.service\nsudo systemctl enable kubelet.service</code></pre>\n<h1 id=\"3、启动\"><a href=\"#3、启动\" class=\"headerlink\" title=\"3、启动\"></a>3、启动</h1><p>注Vagrantfile和setup.sh放在同一目录并且在该目录下执行启动命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vagrant up</code></pre>\n<p>由于在启动中加入了脚本,此次启动执行的内容多,时间要比以往长些</p>\n<h1 id=\"4、通过远程连接工具连接\"><a href=\"#4、通过远程连接工具连接\" class=\"headerlink\" title=\"4、通过远程连接工具连接\"></a>4、通过远程连接工具连接</h1><p>目前三台机器分别有两个用户root和vagrant密码全部是vagrant</p>\n<h1 id=\"5、部署主节点\"><a href=\"#5、部署主节点\" class=\"headerlink\" title=\"5、部署主节点\"></a>5、部署主节点</h1><p>注:这步时间较长,耐心等待</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm init \\\n--apiserver-advertise-address&#x3D;172.17.8.51 \\\n--image-repository registry.aliyuncs.com&#x2F;google_containers \\\n--kubernetes-version v1.23.6 \\\n--service-cidr&#x3D;10.96.0.0&#x2F;12 \\\n--pod-network-cidr&#x3D;10.244.0.0&#x2F;16</code></pre>\n<p>出现下面的内容,主节点部署完成</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-18-24-59-image.png\" alt=\"\"></p>\n<h1 id=\"6、使用-kubectl-工具\"><a href=\"#6、使用-kubectl-工具\" class=\"headerlink\" title=\"6、使用 kubectl 工具\"></a>6、使用 kubectl 工具</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mkdir -p $HOME&#x2F;.kube\nsudo cp -i &#x2F;etc&#x2F;kubernetes&#x2F;admin.conf $HOME&#x2F;.kube&#x2F;config\nsudo chown $(id -u):$(id -g) $HOME&#x2F;.kube&#x2F;config</code></pre>\n<h1 id=\"7、安装-Pod-网络插件CNI\"><a href=\"#7、安装-Pod-网络插件CNI\" class=\"headerlink\" title=\"7、安装 Pod 网络插件CNI\"></a>7、安装 Pod 网络插件CNI</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;coreos&#x2F;flannel&#x2F;master&#x2F;Documentation&#x2F;kube-flannel.yml</code></pre>\n<p>注如果连接不上可以在当前目录新建文件kube-flannel.yml替换掉文件</p>\n<p>kube-flannel.yml内容</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">---\napiVersion: policy&#x2F;v1beta1\nkind: PodSecurityPolicy\nmetadata:\n name: psp.flannel.unprivileged\n annotations:\n seccomp.security.alpha.kubernetes.io&#x2F;allowedProfileNames: docker&#x2F;default\n seccomp.security.alpha.kubernetes.io&#x2F;defaultProfileName: docker&#x2F;default\n apparmor.security.beta.kubernetes.io&#x2F;allowedProfileNames: runtime&#x2F;default\n apparmor.security.beta.kubernetes.io&#x2F;defaultProfileName: runtime&#x2F;default\nspec:\n privileged: false\n volumes:\n - configMap\n - secret\n - emptyDir\n - hostPath\n allowedHostPaths:\n - pathPrefix: &quot;&#x2F;etc&#x2F;cni&#x2F;net.d&quot;\n - pathPrefix: &quot;&#x2F;etc&#x2F;kube-flannel&quot;\n - pathPrefix: &quot;&#x2F;run&#x2F;flannel&quot;\n readOnlyRootFilesystem: false\n # Users and groups\n runAsUser:\n rule: RunAsAny\n supplementalGroups:\n rule: RunAsAny\n fsGroup:\n rule: RunAsAny\n # Privilege Escalation\n allowPrivilegeEscalation: false\n defaultAllowPrivilegeEscalation: false\n # Capabilities\n allowedCapabilities: [&#39;NET_ADMIN&#39;, &#39;NET_RAW&#39;]\n defaultAddCapabilities: []\n requiredDropCapabilities: []\n # Host namespaces\n hostPID: false\n hostIPC: false\n hostNetwork: true\n hostPorts:\n - min: 0\n max: 65535\n # SELinux\n seLinux:\n # SELinux is unused in CaaSP\n rule: &#39;RunAsAny&#39;\n---\nkind: ClusterRole\napiVersion: rbac.authorization.k8s.io&#x2F;v1\nmetadata:\n name: flannel\nrules:\n- apiGroups: [&#39;extensions&#39;]\n resources: [&#39;podsecuritypolicies&#39;]\n verbs: [&#39;use&#39;]\n resourceNames: [&#39;psp.flannel.unprivileged&#39;]\n- apiGroups:\n - &quot;&quot;\n resources:\n - pods\n verbs:\n - get\n- apiGroups:\n - &quot;&quot;\n resources:\n - nodes\n verbs:\n - list\n - watch\n- apiGroups:\n - &quot;&quot;\n resources:\n - nodes&#x2F;status\n verbs:\n - patch\n---\nkind: ClusterRoleBinding\napiVersion: rbac.authorization.k8s.io&#x2F;v1\nmetadata:\n name: flannel\nroleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: flannel\nsubjects:\n- kind: ServiceAccount\n name: flannel\n namespace: kube-system\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: flannel\n namespace: kube-system\n---\nkind: ConfigMap\napiVersion: v1\nmetadata:\n name: kube-flannel-cfg\n namespace: kube-system\n labels:\n tier: node\n app: flannel\ndata:\n cni-conf.json: |\n &#123;\n &quot;name&quot;: &quot;cbr0&quot;,\n &quot;cniVersion&quot;: &quot;0.3.1&quot;,\n &quot;plugins&quot;: [\n &#123;\n &quot;type&quot;: &quot;flannel&quot;,\n &quot;delegate&quot;: &#123;\n &quot;hairpinMode&quot;: true,\n &quot;isDefaultGateway&quot;: true\n &#125;\n &#125;,\n &#123;\n &quot;type&quot;: &quot;portmap&quot;,\n &quot;capabilities&quot;: &#123;\n &quot;portMappings&quot;: true\n &#125;\n &#125;\n ]\n &#125;\n net-conf.json: |\n &#123;\n &quot;Network&quot;: &quot;10.244.0.0&#x2F;16&quot;,\n &quot;Backend&quot;: &#123;\n &quot;Type&quot;: &quot;vxlan&quot;\n &#125;\n &#125;\n---\napiVersion: apps&#x2F;v1\nkind: DaemonSet\nmetadata:\n name: kube-flannel-ds\n namespace: kube-system\n labels:\n tier: node\n app: flannel\nspec:\n selector:\n matchLabels:\n app: flannel\n template:\n metadata:\n labels:\n tier: node\n app: flannel\n spec:\n affinity:\n nodeAffinity:\n requiredDuringSchedulingIgnoredDuringExecution:\n nodeSelectorTerms:\n - matchExpressions:\n - key: kubernetes.io&#x2F;os\n operator: In\n values:\n - linux\n hostNetwork: true\n priorityClassName: system-node-critical\n tolerations:\n - operator: Exists\n effect: NoSchedule\n serviceAccountName: flannel\n initContainers:\n - name: install-cni-plugin\n #image: flannelcni&#x2F;flannel-cni-plugin:v1.1.0 for ppc64le and mips64le (dockerhub limitations may apply)\n image: rancher&#x2F;mirrored-flannelcni-flannel-cni-plugin:v1.1.0\n command:\n - cp\n args:\n - -f\n - &#x2F;flannel\n - &#x2F;opt&#x2F;cni&#x2F;bin&#x2F;flannel\n volumeMounts:\n - name: cni-plugin\n mountPath: &#x2F;opt&#x2F;cni&#x2F;bin\n - name: install-cni\n #image: flannelcni&#x2F;flannel:v0.18.0 for ppc64le and mips64le (dockerhub limitations may apply)\n image: rancher&#x2F;mirrored-flannelcni-flannel:v0.18.0\n command:\n - cp\n args:\n - -f\n - &#x2F;etc&#x2F;kube-flannel&#x2F;cni-conf.json\n - &#x2F;etc&#x2F;cni&#x2F;net.d&#x2F;10-flannel.conflist\n volumeMounts:\n - name: cni\n mountPath: &#x2F;etc&#x2F;cni&#x2F;net.d\n - name: flannel-cfg\n mountPath: &#x2F;etc&#x2F;kube-flannel&#x2F;\n containers:\n - name: kube-flannel\n #image: flannelcni&#x2F;flannel:v0.18.0 for ppc64le and mips64le (dockerhub limitations may apply)\n image: rancher&#x2F;mirrored-flannelcni-flannel:v0.18.0\n command:\n - &#x2F;opt&#x2F;bin&#x2F;flanneld\n args:\n - --ip-masq\n - --kube-subnet-mgr\n resources:\n requests:\n cpu: &quot;100m&quot;\n memory: &quot;50Mi&quot;\n limits:\n cpu: &quot;100m&quot;\n memory: &quot;50Mi&quot;\n securityContext:\n privileged: false\n capabilities:\n add: [&quot;NET_ADMIN&quot;, &quot;NET_RAW&quot;]\n env:\n - name: POD_NAME\n valueFrom:\n fieldRef:\n fieldPath: metadata.name\n - name: POD_NAMESPACE\n valueFrom:\n fieldRef:\n fieldPath: metadata.namespace\n - name: EVENT_QUEUE_DEPTH\n value: &quot;5000&quot;\n volumeMounts:\n - name: run\n mountPath: &#x2F;run&#x2F;flannel\n - name: flannel-cfg\n mountPath: &#x2F;etc&#x2F;kube-flannel&#x2F;\n - name: xtables-lock\n mountPath: &#x2F;run&#x2F;xtables.lock\n volumes:\n - name: run\n hostPath:\n path: &#x2F;run&#x2F;flannel\n - name: cni-plugin\n hostPath:\n path: &#x2F;opt&#x2F;cni&#x2F;bin\n - name: cni\n hostPath:\n path: &#x2F;etc&#x2F;cni&#x2F;net.d\n - name: flannel-cfg\n configMap:\n name: kube-flannel-cfg\n - name: xtables-lock\n hostPath:\n path: &#x2F;run&#x2F;xtables.lock\n type: FileOrCreate</code></pre>\n<h1 id=\"8、节点加入集群\"><a href=\"#8、节点加入集群\" class=\"headerlink\" title=\"8、节点加入集群\"></a>8、节点加入集群</h1><p>在第5步<code>kubeadm init</code>命令输出的日志中最后几行有需要执行的命令那个命令拿出来直接在node2和node3上运行就可以了token的有效期是24小时超过了需要重新生成</p>\n<p>当然,如果你想我一样,忘记复制了还恰好关掉了远程,那么就有两种方式可以解决</p>\n<ul>\n<li><p>通过生成新的token显示命令对应8.1操作)</p>\n</li>\n<li><p>直接查看token对应8.2操作)</p>\n</li>\n</ul>\n<p>8.1、执行下面的命令生成新的token</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm token create --print-join-command</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-19-27-17-image.png\" alt=\"\"></p>\n<p>这里显示的命令拿到要加入的节点node2和node3执行就可以加入集群中</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-19-28-18-image.png\" alt=\"\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-19-30-16-image.png\" alt=\"\"></p>\n<p>然后回到master主节点执行命令确认加入成功</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get nodes</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-19-58-04-image.png\" alt=\"\"></p>\n<p>8.2、查看token命令获取</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm token list</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-20-54-08-image.png\" alt=\"\"></p>\n<p>主节点:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看节点\nkubectl get nodes</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-21-15-08-image.png\" alt=\"\"></p>\n<p>节点3</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm join 172.17.8.51:6443 --token o15q87.xtnzlfis6gtez1x6 --discovery-token-unsafe-skip-ca-verification</code></pre>\n<p> <img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-21-22-21-image.png\" alt=\"\"></p>\n<p>主节点:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看节点\nkubectl get nodes</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-21-22-55-image.png\" alt=\"\"></p>\n<h1 id=\"9、集群中移除节点\"><a href=\"#9、集群中移除节点\" class=\"headerlink\" title=\"9、集群中移除节点\"></a>9、集群中移除节点</h1><p>主节点执行:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 查看节点\nkubectl get nodes\n# 移除节点3\nkubectl delete node node3\n# 查看节点\nkubectl get nodes</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inK8sByKubeadm/2022-06-04-20-59-19-image.png\" alt=\"\"></p>\n<p>删除的节点执行:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubeadm reset\nsystemctl stop kubelet\nsystemctl stop docker\nrm -rf &#x2F;var&#x2F;lib&#x2F;cni&#x2F;\nrm -rf &#x2F;var&#x2F;lib&#x2F;kubelet&#x2F;*\nrm -rf &#x2F;etc&#x2F;cni&#x2F;\nsystemctl start docker\nsystemctl start kubelet</code></pre>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"一条命令运行rancher","slug":"inReacherByDC","date":"2022-05-26T00:49:12.000Z","updated":"2022-09-22T07:39:53.041Z","comments":true,"path":"/post/inReacherByDC/","link":"","excerpt":"","content":"<h1 id=\"1、rancher安装\"><a href=\"#1、rancher安装\" class=\"headerlink\" title=\"1、rancher安装\"></a>1、rancher安装</h1><p>控制台中rke用户下执行docker命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker run --name&#x3D;rancher -d --privileged --restart&#x3D;unless-stopped -p 30040:80 -p 30050:443 rancher&#x2F;rancher:latest</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-05-14-image.png\" alt=\"\"> </p>\n<h1 id=\"2、检查是否正常启动\"><a href=\"#2、检查是否正常启动\" class=\"headerlink\" title=\"2、检查是否正常启动\"></a>2、检查是否正常启动</h1><p>可通过下面两个命令查看:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker ps | grep rancher ## 查看正在运行中的docker容器</code></pre>\n<h1 id=\"3、浏览器访问\"><a href=\"#3、浏览器访问\" class=\"headerlink\" title=\"3、浏览器访问\"></a>3、浏览器访问</h1><p>输入<a href=\"https://IP:PORT\">https://IP:PORT</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-10-27-image.png\" alt=\"\"></p>\n<p>点击高级,然后点击继续前往</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-11-34-image.png\" alt=\"\"></p>\n<h1 id=\"4、密码\"><a href=\"#4、密码\" class=\"headerlink\" title=\"4、密码\"></a>4、密码</h1><p>根据提示,输入并修改密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-12-49-image.png\" alt=\"\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-13-57-image.png\" alt=\"\"></p>\n<p>浏览器输入密码后,选择红框的,并在下方输入自己想要设置的密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-15-39-image.png\" alt=\"\"></p>\n<p>进入后里面有一个默认的k3s</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-18-34-image.png\" alt=\"\"></p>\n<h1 id=\"5、加入其他存在的集群\"><a href=\"#5、加入其他存在的集群\" class=\"headerlink\" title=\"5、加入其他存在的集群\"></a>5、加入其他存在的集群</h1><p>点击<code>Import Existing</code></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-19-37-image.png\" alt=\"\"></p>\n<p>选择<code>Generic</code></p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-20-46-image.png\" alt=\"\"></p>\n<p>集群名字随意输入,只要你能记住</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-22-26-image.png\" alt=\"\"></p>\n<p>根据红框的操作执行命令注册进来</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-23-58-image.png\" alt=\"\"></p>\n<p>执行命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f https:&#x2F;&#x2F;172.17.8.51:30050&#x2F;v3&#x2F;import&#x2F;2llq4b95zbspwqlcjrb898dtwqmqgtcxtfxjdlkgp8c79jpzf8tfn6_c-m-5ffgdfz6.yaml</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-24-48-image.png\" alt=\"\"></p>\n<p>报了认证的问题,执行第二个命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">curl --insecure -sfL https:&#x2F;&#x2F;172.17.8.51:30050&#x2F;v3&#x2F;import&#x2F;2llq4b95zbspwqlcjrb898dtwqmqgtcxtfxjdlkgp8c79jpzf8tfn6_c-m-5ffgdfz6.yaml | kubectl apply -f -</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inReacherByDC/2022-06-04-20-26-55-image.png\" alt=\"\"></p>\n<p>我这边是运行成功了</p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"力扣675. 为高尔夫比赛砍树","slug":"day20220523","date":"2022-05-24T01:18:23.000Z","updated":"2022-09-22T07:39:52.865Z","comments":true,"path":"/post/day20220523/","link":"","excerpt":"","content":"<p>2022年05月24日 力扣每日一题</p>\n<p><a href=\"https://leetcode.cn/problems/cut-off-trees-for-golf-event/\">675. 为高尔夫比赛砍树</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>你被请来给一个要举办高尔夫比赛的树林砍树。树林由一个 <code>m x n</code> 的矩阵表示, 在这个矩阵中:</p>\n\n<ul> \n <li><code>0</code> 表示障碍,无法触碰</li> \n <li><code>1</code> 表示地面,可以行走</li> \n <li><code>比 1 大的数</code> 表示有树的单元格,可以行走,数值表示树的高度</li> \n</ul>\n\n<p>每一步,你都可以向上、下、左、右四个方向之一移动一个单位,如果你站的地方有一棵树,那么你可以决定是否要砍倒它。</p>\n\n<p>你需要按照树的高度从低向高砍掉所有的树,每砍过一颗树,该单元格的值变为 <code>1</code>(即变为地面)。</p>\n\n<p>你将从 <code>(0, 0)</code> 点开始工作,返回你砍完所有树需要走的最小步数。 如果你无法砍完所有的树,返回 <code>-1</code> 。</p>\n\n<p>可以保证的是,没有两棵树的高度是相同的,并且你至少需要砍倒一棵树。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p> \n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/11/26/trees1.jpg\" style=\"width: 242px; height: 242px;\" /> \n<pre> \n<strong>输入:</strong>forest = [[1,2,3],[0,0,4],[7,6,5]] \n<strong>输出:</strong>6 \n<strong>解释:</strong>沿着上面的路径,你可以用 6 步,按从最矮到最高的顺序砍掉这些树。</pre>\n\n<p><strong>示例 2</strong></p> \n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/11/26/trees2.jpg\" style=\"width: 242px; height: 242px;\" /> \n<pre> \n<strong>输入:</strong>forest = [[1,2,3],[0,0,0],[7,6,5]] \n<strong>输出:</strong>-1 \n<strong>解释:</strong>由于中间一行被障碍阻塞,无法访问最下面一行中的树。 \n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre> \n<strong>输入:</strong>forest = [[2,3,4],[0,0,5],[8,7,6]] \n<strong>输出:</strong>6 \n<strong>解释:</strong>可以按与示例 1 相同的路径来砍掉所有的树。 \n(0,0) 位置的树,可以直接砍去,不用算步数。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul> \n <li><code>m == forest.length</code></li> \n <li><code>n == forest[i].length</code></li> \n <li><code>1 <= m, n <= 50</code></li> \n <li><code>0 <= forest[i][j] <= 10<sup>9</sup></code></li> \n</ul> </p>\n<div><div>Related Topics</div><div><li>广度优先搜索</li><li>数组</li><li>矩阵</li><li>堆(优先队列)</li></div></div>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><ol>\n<li><p>记录每颗需要砍树的位置,并排好序</p>\n<p>注意:这个需要砍的树是从<font color=\"red\">2</font>开始算的,不是<font color=\"red\">1</font></p>\n</li>\n<li><p>循环计算到达下一棵被砍树的步数</p>\n<p>可使用广度优先搜索,从出发的树开始,依次取出并将下一步能够到达的树加入到队列,直到目标树为止</p>\n</li>\n</ol>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int cutOffTree(List&lt;List&lt;Integer&gt;&gt; forest) &#123;\n &#x2F;*\n 起始位置不可到达的情况即坐标0,0位置为0\n *&#x2F;\n if (forest.get(0).get(0) &#x3D;&#x3D; 0) &#123;\n return -1;\n &#125;\n int xL &#x3D; forest.size();\n int yL &#x3D; forest.get(0).size();\n &#x2F;*\n 按照顺序排列需要砍的树,记录每棵树的位置\n *&#x2F;\n TreeMap&lt;Integer, Pair&lt;Integer, Integer&gt;&gt; map &#x3D; new TreeMap&lt;&gt;();\n for (int i &#x3D; 0; i &lt; xL; i++) &#123;\n List&lt;Integer&gt; list &#x3D; forest.get(i);\n for (int j &#x3D; 0; j &lt; yL; j++) &#123;\n if (list.get(j) &gt; 1) &#123;\n map.put(list.get(j), new Pair&lt;&gt;(i, j));\n &#125;\n &#125;\n &#125;\n int step &#x3D; 0;\n Pair&lt;Integer, Integer&gt; pair &#x3D; null;\n Queue&lt;Pair&lt;Integer, Integer&gt;&gt; queue &#x3D; new LinkedList&lt;&gt;();\n queue.add(new Pair&lt;&gt;(0, 0));\n boolean[][] uses &#x3D; new boolean[xL][yL];\n uses[0][0] &#x3D; true;\n int[] xs &#x3D; new int[]&#123;1, -1, 0, 0&#125;;\n int[] ys &#x3D; new int[]&#123;0, 0, 1, -1&#125;;\n for (int key : map.keySet()) &#123;\n Pair&lt;Integer, Integer&gt; cur &#x3D; map.get(key);\n if (queue.peek().equals(cur)) &#123;\n continue;\n &#125;\n boolean bl &#x3D; false;\n &#x2F;*\n 计算到达下一棵需要砍树的步数\n *&#x2F;\n while (!queue.isEmpty() &amp;&amp; !bl) &#123;\n int nums &#x3D; queue.size();\n step++;\n for (int i &#x3D; 0; i &lt; nums &amp;&amp; !bl; i++) &#123;\n Pair&lt;Integer, Integer&gt; tmp &#x3D; queue.poll();\n for (int j &#x3D; 0; j &lt; 4; j++) &#123;\n int x &#x3D; tmp.getKey() + xs[j];\n int y &#x3D; tmp.getValue() + ys[j];\n if (x &#x3D;&#x3D; cur.getKey() &amp;&amp; y &#x3D;&#x3D; cur.getValue()) &#123;\n bl &#x3D; true;\n break;\n &#125;\n if (x &lt; 0 || x &gt;&#x3D; xL || y &lt; 0 || y\n &gt;&#x3D; yL || uses[x][y] || forest.get(x).get(y\n continue;\n &#125;\n queue.add(new Pair&lt;&gt;(x, y));\n uses[x][y] &#x3D; true;\n &#125;\n &#125;\n &#125;\n if (!bl) &#123;\n return -1;\n &#125;\n queue &#x3D; new LinkedList&lt;&gt;();\n queue.add(cur);\n uses &#x3D; new boolean[xL][yL];\n uses[cur.getKey()][cur.getValue()] &#x3D; true;\n &#125;\n return step;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣周赛293题解","slug":"weekly-contest-293","date":"2022-05-19T06:52:09.000Z","updated":"2023-06-20T03:16:55.431Z","comments":true,"path":"/post/weekly-contest-293/","link":"","excerpt":"","content":"<h1 id=\"第一题\"><a href=\"#第一题\" class=\"headerlink\" title=\"第一题\"></a>第一题</h1><h2 id=\"力扣原题链接:\"><a href=\"#力扣原题链接:\" class=\"headerlink\" title=\"力扣原题链接:\"></a>力扣原题链接:</h2><p><a href=\"https://leetcode.cn/problems/find-resultant-array-after-removing-anagrams/\">2273. 移除字母异位词后的结果数组</a></p>\n<h2 id=\"单个题解:\"><a href=\"#单个题解:\" class=\"headerlink\" title=\"单个题解:\"></a>单个题解:</h2><p><a href=\"http://192.168.0.198:5080/post/find-resultant-array-after-removing-anagrams/\">力扣2273. 移除字母异位词后的结果数组</a></p>\n<h2 id=\"题目:\"><a href=\"#题目:\" class=\"headerlink\" title=\"题目:\"></a>题目:</h2><p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>words</code> ,其中 <code>words[i]</code> 由小写英文字符组成。</p>\n\n<p>在一步操作中,需要选出任一下标 <code>i</code> ,从 <code>words</code> 中 <strong>删除</strong> <code>words[i]</code> 。其中下标 <code>i</code> 需要同时满足下述两个条件:</p>\n\n<ol> \n <li><code>0 < i < words.length</code></li> \n <li><code>words[i - 1]</code> 和 <code>words[i]</code> 是 <strong>字母异位词</strong> 。</li> \n</ol>\n\n<p>只要可以选出满足条件的下标,就一直执行这个操作。</p>\n\n<p>在执行所有操作后,返回 <code>words</code> 。可以证明,按任意顺序为每步操作选择下标都会得到相同的结果。</p>\n\n<p><strong>字母异位词</strong> 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。例如,<code>\"dacb\"</code> 是 <code>\"abdc\"</code> 的一个字母异位词。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"] \n<strong>输出:</strong>[\"abba\",\"cd\"] \n<strong>解释:</strong> \n获取结果数组的方法之一是执行下述步骤 - 由于 words[2] = \"bbaa\" 和 words[1] = \"baba\" 是字母异位词,选择下标 2 并删除 words[2] 。 \n 现在 words = [\"abba\",\"baba\",\"cd\",\"cd\"] 。 - 由于 words[1] = \"baba\" 和 words[0] = \"abba\" 是字母异位词,选择下标 1 并删除 words[1] 。 \n 现在 words = [\"abba\",\"cd\",\"cd\"] 。 - 由于 words[2] = \"cd\" 和 words[1] = \"cd\" 是字母异位词,选择下标 2 并删除 words[2] 。 \n 现在 words = [\"abba\",\"cd\"] 。 无法再执行任何操作,所以 [\"abba\",\"cd\"] 是最终答案。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>words = [\"a\",\"b\",\"c\",\"d\",\"e\"] \n<strong>输出:</strong>[\"a\",\"b\",\"c\",\"d\",\"e\"] \n<strong>解释:</strong> \nwords 中不存在互为字母异位词的两个相邻字符串,所以无需执行任何操作。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 <= words.length <= 100</code></li> \n <li><code>1 <= words[i].length <= 10</code></li> \n <li><code>words[i]</code> 由小写英文字母组成</li> \n</ul> \n<div><div>Related Topics</div><div><li>数组</li><li>哈希表</li><li>字符串</li><li>排序</li></div></div>\n\n## 思路:\n\n遍历字符串数组分别将每一个字符串装换成字符数组字符数组排序如果排序后转成的字符串一样则说明是字母异位词 \n\n## 代码:\n\njava \n\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public List&lt;String&gt; removeAnagrams(String[] words) &#123;\n char[] strs &#x3D; words[0].toCharArray();\n Arrays.sort(strs);\n List&lt;String&gt; list &#x3D; new ArrayList&lt;&gt;();\n int index &#x3D; 0;\n for (int i &#x3D; 1; i &lt; words.length; i++) &#123;\n char[] strs1 &#x3D; words[i].toCharArray();\n Arrays.sort(strs1);\n if (!String.valueOf(strs).equals(String.valueOf(strs1))) &#123;\n list.add(words[index]);\n strs &#x3D; strs1;\n index &#x3D; i;\n &#125;\n &#125;\n list.add(words[index]);\n return list;\n &#125;\n&#125;</code></pre>\n\n# 第二题\n\n## 力扣原题链接:\n\n[2274. 不含特殊楼层的最大连续楼层数](https://leetcode.cn/problems/maximum-consecutive-floors-without-special-floors/)\n\n## 单个题解:\n\n[力扣2274. 不含特殊楼层的最大连续楼层数](http://192.168.0.198:5080/post/maximum-consecutive-floors-without-special-floors/)\n\n## 题目:\n\n<p>Alice 管理着一家公司并租用大楼的部分楼层作为办公空间。Alice 决定将一些楼层作为 <strong>特殊楼层</strong> ,仅用于放松。</p>\n\n<p>给你两个整数 <code>bottom</code> 和 <code>top</code> ,表示 Alice 租用了从 <code>bottom</code> 到 <code>top</code>(含 <code>bottom</code> 和 <code>top</code> 在内)的所有楼层。另给你一个整数数组 <code>special</code> ,其中 <code>special[i]</code> 表示 Alice 指定用于放松的特殊楼层。</p>\n\n<p>返回不含特殊楼层的 <strong>最大</strong> 连续楼层数。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre> \n<strong>输入:</strong>bottom = 2, top = 9, special = [4,6] \n<strong>输出:</strong>3 \n<strong>解释:</strong>下面列出的是不含特殊楼层的连续楼层范围: \n- (2, 3) ,楼层数为 2 。 \n- (5, 5) ,楼层数为 1 。 \n- (7, 9) ,楼层数为 3 。 \n因此返回最大连续楼层数 3 。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre> \n<strong>输入:</strong>bottom = 6, top = 8, special = [7,6,8] \n<strong>输出:</strong>0 \n<strong>解释:</strong>每层楼都被规划为特殊楼层,所以返回 0 。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示</strong></p>\n\n<ul> \n <li><code>1 <= special.length <= 10<sup>5</sup></code></li> \n <li><code>1 <= bottom <= special[i] <= top <= 10<sup>9</sup></code></li> \n <li><code>special</code> 中的所有值 <strong>互不相同</strong></li> \n</ul> \n<div><div>Related Topics</div><div><li>数组</li><li>排序</li></div></div>\n\n## 思路:\n\n这题相当于在bottom到top的范围内被special的数分割了我们需要找到分割后最长的一段\n\n步骤\n\n1. 为了保证数据的顺序进行对special进行排序\n2. 遍历`special`对`bottom~top`进行分割,当`bottom<=special[i]`时, \n 连续楼层数为`special[i]-bottom`,与之前的最大连续层数对比,得到当前的最大连续层数, \n 同时更新`bottom = special[i] + 1`\n3. 遍历完,还有最后一段的连续层数`top - special[special.length - 1]`\n4. 至此,不包含特殊层的最大的连续层数就出来了\n\n## 代码:\n\njava\n\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int maxConsecutive(int bottom, int top, int[] special) &#123;\n Arrays.sort(special);\n int max &#x3D; 0;\n for (int j : special) &#123;\n if (bottom &lt;&#x3D; j) &#123;\n max &#x3D; Math.max(max, j - bottom);\n bottom &#x3D; j + 1;\n &#125;\n &#125;\n max &#x3D; Math.max(max, top - special[special.length - 1]);\n return max;\n &#125;\n&#125;</code></pre>\n\n# 第三题\n\n## 力扣原题链接:\n\n[2275. 按位与结果大于零的最长组合](https://leetcode.cn/problems/largest-combination-with-bitwise-and-greater-than-zero/)\n\n## 单个题解:\n\n[力扣2275. 按位与结果大于零的最长组合](http://192.168.0.198:5080/post/largest-combination-with-bitwise-and-greater-than-zero/)\n\n## 题目:\n\n<p>对数组 <code>nums</code> 执行 <strong>按位与</strong> 相当于对数组 <code>nums</code> 中的所有整数执行 <strong>按位与</strong> 。</p>\n\n<ul> \n <li>例如,对 <code>nums = [1, 5, 3]</code> 来说,按位与等于 <code>1 & 5 & 3 = 1</code> 。</li> \n <li>同样,对 <code>nums = [7]</code> 而言,按位与等于 <code>7</code> 。</li> \n</ul>\n\n<p>给你一个正整数数组 <code>candidates</code> 。计算 <code>candidates</code> 中的数字每种组合下 <strong>按位与</strong> 的结果。 <code>candidates</code> 中的每个数字在每种组合中只能使用 <strong>一次</strong> 。</p>\n\n<p>返回按位与结果大于 <code>0</code> 的 <strong>最长</strong> 组合的长度<em>。</em></p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre> \n<strong>输入:</strong>candidates = [16,17,71,62,12,24,14] \n<strong>输出:</strong>4 \n<strong>解释:</strong>组合 [16,17,62,24] 的按位与结果是 16 & 17 & 62 & 24 = 16 > 0 。 \n组合长度是 4 。 \n可以证明不存在按位与结果大于 0 且长度大于 4 的组合。 \n注意符合长度最大的组合可能不止一种。 \n例如组合 [62,12,24,14] 的按位与结果是 62 & 12 & 24 & 14 = 8 > 0 。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre> \n<strong>输入:</strong>candidates = [8,8] \n<strong>输出:</strong>2 \n<strong>解释:</strong>最长组合是 [8,8] ,按位与结果 8 & 8 = 8 > 0 。 \n组合长度是 2 ,所以返回 2 。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 <= candidates.length <= 10<sup>5</sup></code></li> \n <li><code>1 <= candidates[i] <= 10<sup>7</sup></code></li> \n</ul> \n<div><div>Related Topics</div><div><li>位运算</li><li>数组</li><li>哈希表</li><li>计数</li></div></div>\n\n## 思路:\n\n这题需要找出按位与结果大于0的最长组合的长度按位与结果大于0 \n说明这个数组中的每一个二进制数都有相同的一位是1根据这题给的数组值的范围 \n可以确定最多有24位那么我们可以循环24次数组每一次循环统计出第`i`位位数为1的个数 \n然后将每一次的个数做比较得出最长组合的长度\n\n## 代码:\n\njava\n\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int largestCombination(int[] candidates) &#123;\n int max &#x3D; 0;\n for (int i &#x3D; 0; i &lt; 25; i++) &#123;\n int cnt &#x3D; 0;\n for (int j &#x3D; 0; j &lt; candidates.length; j++) &#123;\n if ((candidates[j] &amp; (1 &lt;&lt; i)) &gt; 0) &#123;\n cnt++;\n &#125;\n &#125;\n max &#x3D; Math.max(max, cnt);\n &#125;\n return max;\n &#125;\n&#125;</code></pre>\n\n# 第四题\n\n## 力扣原题链接:\n\n[2276. 统计区间中的整数数目](https://leetcode.cn/problems/count-integers-in-intervals/)\n\n## 单个题解:\n\n[力扣2276. 统计区间中的整数数目](http://192.168.0.198:5080/post/count-integers-in-intervals/)\n\n## 题目:\n\n<p>给你区间的 <strong>空</strong> 集,请你设计并实现满足要求的数据结构:</p>\n\n<ul> \n <li><strong>新增:</strong>添加一个区间到这个区间集合中。</li> \n <li><strong>统计:</strong>计算出现在 <strong>至少一个</strong> 区间中的整数个数。</li> \n</ul>\n\n<p>实现 <code>CountIntervals</code> 类:</p>\n\n<ul> \n <li><code>CountIntervals()</code> 使用区间的空集初始化对象</li> \n <li><code>void add(int left, int right)</code> 添加区间 <code>[left, right]</code> 到区间集合之中。</li> \n <li><code>int count()</code> 返回出现在 <strong>至少一个</strong> 区间中的整数个数。</li> \n</ul>\n\n<p><strong>注意:</strong>区间 <code>[left, right]</code> 表示满足 <code>left <= x <= right</code> 的所有整数 <code>x</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre> \n<strong>输入</strong> \n[\"CountIntervals\", \"add\", \"add\", \"count\", \"add\", \"count\"] \n[[], [2, 3], [7, 10], [], [5, 8], []] \n<strong>输出</strong> \n[null, null, null, 6, null, 8] \n\n<strong>解释</strong> \nCountIntervals countIntervals = new CountIntervals(); // 用一个区间空集初始化对象 \ncountIntervals.add(2, 3); // 将 [2, 3] 添加到区间集合中 \ncountIntervals.add(7, 10); // 将 [7, 10] 添加到区间集合中 \ncountIntervals.count(); // 返回 6 \n // 整数 2 和 3 出现在区间 [2, 3] 中 \n // 整数 7、8、9、10 出现在区间 [7, 10] 中 \ncountIntervals.add(5, 8); // 将 [5, 8] 添加到区间集合中 \ncountIntervals.count(); // 返回 8 \n // 整数 2 和 3 出现在区间 [2, 3] 中 \n // 整数 5 和 6 出现在区间 [5, 8] 中 \n // 整数 7 和 8 出现在区间 [5, 8] 和区间 [7, 10] 中 \n // 整数 9 和 10 出现在区间 [7, 10] 中</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 <= left <= right <= 10<sup>9</sup></code></li> \n <li>最多调用 <code>add</code> 和 <code>count</code> 方法 <strong>总计</strong> <code>10<sup>5</sup></code> 次</li> \n <li>调用 <code>count</code> 方法至少一次</li> \n</ul>\n\n<h2 id=\"思路:\"><a href=\"#思路:\" class=\"headerlink\" title=\"思路:\"></a>思路:</h2><p>这题我的思路是添加一次整理一次并同时计数利用java的TreeSet结构可以快速的定位数据。<br>典型的模板题 </p>\n<h2 id=\"代码:\"><a href=\"#代码:\" class=\"headerlink\" title=\"代码:\"></a>代码:</h2><p>java </p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class CountIntervals &#123;\n TreeSet&lt;Interval&gt; ranges;\n int cnt;\n public CountIntervals() &#123;\n ranges &#x3D; new TreeSet();\n cnt &#x3D; 0;\n &#125;\n public void add(int left, int right) &#123;\n Iterator&lt;Interval&gt; itr &#x3D; ranges.tailSet(new Interval(0, left - 1)).iterator();\n while (itr.hasNext()) &#123;\n Interval iv &#x3D; itr.next();\n if (right &lt; iv.left) &#123;\n break;\n &#125;\n left &#x3D; Math.min(left, iv.left);\n right &#x3D; Math.max(right, iv.right);\n cnt -&#x3D; iv.right - iv.left + 1;\n itr.remove();\n &#125;\n ranges.add(new Interval(left, right));\n cnt +&#x3D; right - left + 1;\n &#125;\n public int count() &#123;\n return cnt;\n &#125;\n&#125;\npublic class Interval implements Comparable&lt;Interval&gt; &#123;\n int left;\n int right;\n public Interval(int left, int right) &#123;\n this.left &#x3D; left;\n this.right &#x3D; right;\n &#125;\n public int compareTo(Interval that) &#123;\n if (this.right &#x3D;&#x3D; that.right) return this.left - that.left;\n return this.right - that.right;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"周赛","slug":"算法/力扣/周赛","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E5%91%A8%E8%B5%9B/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2276. 统计区间中的整数数目","slug":"count-integers-in-intervals","date":"2022-05-19T05:54:33.000Z","updated":"2022-09-22T07:39:52.807Z","comments":true,"path":"/post/count-integers-in-intervals/","link":"","excerpt":"","content":"<p>力扣周赛293—第四题</p>\n<p><a href=\"https://leetcode.cn/problems/count-integers-in-intervals/\">2276. 统计区间中的整数数目</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你区间的 <strong>空</strong> 集,请你设计并实现满足要求的数据结构:</p>\n\n<ul>\n <li><strong>新增:</strong>添加一个区间到这个区间集合中。</li>\n <li><strong>统计:</strong>计算出现在 <strong>至少一个</strong> 区间中的整数个数。</li>\n</ul>\n\n<p>实现 <code>CountIntervals</code> 类:</p>\n\n<ul>\n <li><code>CountIntervals()</code> 使用区间的空集初始化对象</li>\n <li><code>void add(int left, int right)</code> 添加区间 <code>[left, right]</code> 到区间集合之中。</li>\n <li><code>int count()</code> 返回出现在 <strong>至少一个</strong> 区间中的整数个数。</li>\n</ul>\n\n<p><strong>注意:</strong>区间 <code>[left, right]</code> 表示满足 <code>left &lt;= x &lt;= right</code> 的所有整数 <code>x</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入</strong>\n[\"CountIntervals\", \"add\", \"add\", \"count\", \"add\", \"count\"]\n[[], [2, 3], [7, 10], [], [5, 8], []]\n<strong>输出</strong>\n[null, null, null, 6, null, 8]\n\n<strong>解释</strong>\nCountIntervals countIntervals = new CountIntervals(); // 用一个区间空集初始化对象\ncountIntervals.add(2, 3); // 将 [2, 3] 添加到区间集合中\ncountIntervals.add(7, 10); // 将 [7, 10] 添加到区间集合中\ncountIntervals.count(); // 返回 6\n // 整数 2 和 3 出现在区间 [2, 3] 中\n // 整数 7、8、9、10 出现在区间 [7, 10] 中\ncountIntervals.add(5, 8); // 将 [5, 8] 添加到区间集合中\ncountIntervals.count(); // 返回 8\n // 整数 2 和 3 出现在区间 [2, 3] 中\n // 整数 5 和 6 出现在区间 [5, 8] 中\n // 整数 7 和 8 出现在区间 [5, 8] 和区间 [7, 10] 中\n // 整数 9 和 10 出现在区间 [7, 10] 中</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n <li><code>1 &lt;= left &lt;= right &lt;= 10<sup>9</sup></code></li>\n <li>最多调用&nbsp; <code>add</code> 和 <code>count</code> 方法 <strong>总计</strong> <code>10<sup>5</sup></code> 次</li>\n <li>调用 <code>count</code> 方法至少一次</li>\n</ul>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题我的思路是添加一次整理一次并同时计数利用java的TreeSet结构可以快速的定位数据。<br>典型的模板题</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class CountIntervals &#123;\n TreeSet&lt;Interval&gt; ranges;\n int cnt;\n public CountIntervals() &#123;\n ranges &#x3D; new TreeSet();\n cnt &#x3D; 0;\n &#125;\n public void add(int left, int right) &#123;\n Iterator&lt;Interval&gt; itr &#x3D; ranges.tailSet(new Interval(0, left - 1)).iterator();\n while (itr.hasNext()) &#123;\n Interval iv &#x3D; itr.next();\n if (right &lt; iv.left) &#123;\n break;\n &#125;\n left &#x3D; Math.min(left, iv.left);\n right &#x3D; Math.max(right, iv.right);\n cnt -&#x3D; iv.right - iv.left + 1;\n itr.remove();\n &#125;\n ranges.add(new Interval(left, right));\n cnt +&#x3D; right - left + 1;\n &#125;\n public int count() &#123;\n return cnt;\n &#125;\n&#125;\npublic class Interval implements Comparable&lt;Interval&gt; &#123;\n int left;\n int right;\n public Interval(int left, int right) &#123;\n this.left &#x3D; left;\n this.right &#x3D; right;\n &#125;\n public int compareTo(Interval that) &#123;\n if (this.right &#x3D;&#x3D; that.right) return this.left - that.left;\n return this.right - that.right;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2275. 按位与结果大于零的最长组合","slug":"largest-combination-with-bitwise-and-greater-than-zero","date":"2022-05-19T05:41:13.000Z","updated":"2022-09-22T07:39:53.089Z","comments":true,"path":"/post/largest-combination-with-bitwise-and-greater-than-zero/","link":"","excerpt":"","content":"<p>力扣周赛293—第三题</p>\n<p><a href=\"https://leetcode.cn/problems/largest-combination-with-bitwise-and-greater-than-zero/\">2275. 按位与结果大于零的最长组合</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>对数组&nbsp;<code>nums</code> 执行 <strong>按位与</strong> 相当于对数组&nbsp;<code>nums</code> 中的所有整数执行 <strong>按位与</strong> 。</p>\n\n<ul>\n <li>例如,对 <code>nums = [1, 5, 3]</code> 来说,按位与等于 <code>1 &amp; 5 &amp; 3 = 1</code> 。</li>\n <li>同样,对 <code>nums = [7]</code> 而言,按位与等于 <code>7</code> 。</li>\n</ul>\n\n<p>给你一个正整数数组 <code>candidates</code> 。计算 <code>candidates</code> 中的数字每种组合下 <strong>按位与</strong> 的结果。 <code>candidates</code> 中的每个数字在每种组合中只能使用 <strong>一次</strong> 。</p>\n\n<p>返回按位与结果大于 <code>0</code> 的 <strong>最长</strong> 组合的长度<em>。</em></p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>candidates = [16,17,71,62,12,24,14]\n<strong>输出:</strong>4\n<strong>解释:</strong>组合 [16,17,62,24] 的按位与结果是 16 &amp; 17 &amp; 62 &amp; 24 = 16 &gt; 0 。\n组合长度是 4 。\n可以证明不存在按位与结果大于 0 且长度大于 4 的组合。\n注意符合长度最大的组合可能不止一种。\n例如组合 [62,12,24,14] 的按位与结果是 62 &amp; 12 &amp; 24 &amp; 14 = 8 &gt; 0 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>candidates = [8,8]\n<strong>输出:</strong>2\n<strong>解释:</strong>最长组合是 [8,8] ,按位与结果 8 &amp; 8 = 8 &gt; 0 。\n组合长度是 2 ,所以返回 2 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= candidates.length &lt;= 10<sup>5</sup></code></li>\n <li><code>1 &lt;= candidates[i] &lt;= 10<sup>7</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>位运算</li><li>数组</li><li>哈希表</li><li>计数</li></div></div>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题需要找出按位与结果大于0的最长组合的长度按位与结果大于0<br>说明这个数组中的每一个二进制数都有相同的一位是1根据这题给的数组值的范围<br>可以确定最多有24位那么我们可以循环24次数组每一次循环统计出第<code>i</code>位位数为1的个数<br>然后将每一次的个数做比较,得出最长组合的长度</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java<br><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int largestCombination(int[] candidates) &#123;\n int max &#x3D; 0;\n for (int i &#x3D; 0; i &lt; 25; i++) &#123;\n int cnt &#x3D; 0;\n for (int j &#x3D; 0; j &lt; candidates.length; j++) &#123;\n if ((candidates[j] &amp; (1 &lt;&lt; i)) &gt; 0) &#123;\n cnt++;\n &#125;\n &#125;\n max &#x3D; Math.max(max, cnt);\n &#125;\n return max;\n &#125;\n&#125;</code></pre></p>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2274. 不含特殊楼层的最大连续楼层数","slug":"maximum-consecutive-floors-without-special-floors","date":"2022-05-19T01:57:58.000Z","updated":"2022-09-22T07:39:53.096Z","comments":true,"path":"/post/maximum-consecutive-floors-without-special-floors/","link":"","excerpt":"","content":"<p>力扣周赛293—第二题</p>\n<p><a href=\"https://leetcode.cn/problems/maximum-consecutive-floors-without-special-floors/\">2274. 不含特殊楼层的最大连续楼层数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>Alice 管理着一家公司并租用大楼的部分楼层作为办公空间。Alice 决定将一些楼层作为 <strong>特殊楼层</strong> ,仅用于放松。</p>\n\n<p>给你两个整数 <code>bottom</code> 和 <code>top</code> ,表示 Alice 租用了从 <code>bottom</code> 到 <code>top</code>(含 <code>bottom</code> 和 <code>top</code> 在内)的所有楼层。另给你一个整数数组 <code>special</code> ,其中 <code>special[i]</code> 表示&nbsp; Alice 指定用于放松的特殊楼层。</p>\n\n<p>返回不含特殊楼层的 <strong>最大</strong> 连续楼层数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>bottom = 2, top = 9, special = [4,6]\n<strong>输出:</strong>3\n<strong>解释:</strong>下面列出的是不含特殊楼层的连续楼层范围:\n- (2, 3) ,楼层数为 2 。\n- (5, 5) ,楼层数为 1 。\n- (7, 9) ,楼层数为 3 。\n因此返回最大连续楼层数 3 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>bottom = 6, top = 8, special = [7,6,8]\n<strong>输出:</strong>0\n<strong>解释:</strong>每层楼都被规划为特殊楼层,所以返回 0 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= special.length &lt;= 10<sup>5</sup></code></li>\n <li><code>1 &lt;= bottom &lt;= special[i] &lt;= top &lt;= 10<sup>9</sup></code></li>\n <li><code>special</code> 中的所有值 <strong>互不相同</strong></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>排序</li></div></div>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题相当于在bottom到top的范围内被special的数分割了我们需要找到分割后最长的一段</p>\n<p>步骤:</p>\n<ol>\n<li>为了保证数据的顺序进行对special进行排序</li>\n<li>遍历<code>special</code>对<code>bottom~top</code>进行分割,当<code>bottom&lt;=special[i]</code>时,<br>连续楼层数为<code>special[i]-bottom</code>,与之前的最大连续层数对比,得到当前的最大连续层数,<br>同时更新<code>bottom = special[i] + 1</code></li>\n<li>遍历完,还有最后一段的连续层数<code>top - special[special.length - 1]</code></li>\n<li>至此,不包含特殊层的最大的连续层数就出来了</li>\n</ol>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int maxConsecutive(int bottom, int top, int[] special) &#123;\n Arrays.sort(special);\n int max &#x3D; 0;\n for (int j : special) &#123;\n if (bottom &lt;&#x3D; j) &#123;\n max &#x3D; Math.max(max, j - bottom);\n bottom &#x3D; j + 1;\n &#125;\n &#125;\n max &#x3D; Math.max(max, top - special[special.length - 1]);\n return max;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2273. 移除字母异位词后的结果数组","slug":"find-resultant-array-after-removing-anagrams","date":"2022-05-19T01:27:33.000Z","updated":"2022-09-22T07:39:52.888Z","comments":true,"path":"/post/find-resultant-array-after-removing-anagrams/","link":"","excerpt":"","content":"<p>力扣周赛293—第一题</p>\n<p><a href=\"https://leetcode.cn/problems/find-resultant-array-after-removing-anagrams/\">2273. 移除字母异位词后的结果数组</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>words</code> ,其中 <code>words[i]</code> 由小写英文字符组成。</p>\n\n<p>在一步操作中,需要选出任一下标 <code>i</code> ,从 <code>words</code> 中 <strong>删除</strong> <code>words[i]</code> 。其中下标 <code>i</code> 需要同时满足下述两个条件:</p>\n\n<ol> \n <li><code>0 < i < words.length</code></li> \n <li><code>words[i - 1]</code> 和 <code>words[i]</code> 是 <strong>字母异位词</strong> 。</li> \n</ol>\n\n<p>只要可以选出满足条件的下标,就一直执行这个操作。</p>\n\n<p>在执行所有操作后,返回 <code>words</code> 。可以证明,按任意顺序为每步操作选择下标都会得到相同的结果。</p>\n\n<p><strong>字母异位词</strong> 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。例如,<code>\"dacb\"</code> 是 <code>\"abdc\"</code> 的一个字母异位词。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"] \n<strong>输出:</strong>[\"abba\",\"cd\"] \n<strong>解释:</strong> \n获取结果数组的方法之一是执行下述步骤 \n- 由于 words[2] = \"bbaa\" 和 words[1] = \"baba\" 是字母异位词,选择下标 2 并删除 words[2] 。 \n 现在 words = [\"abba\",\"baba\",\"cd\",\"cd\"] 。 \n- 由于 words[1] = \"baba\" 和 words[0] = \"abba\" 是字母异位词,选择下标 1 并删除 words[1] 。 \n 现在 words = [\"abba\",\"cd\",\"cd\"] 。 \n- 由于 words[2] = \"cd\" 和 words[1] = \"cd\" 是字母异位词,选择下标 2 并删除 words[2] 。 \n 现在 words = [\"abba\",\"cd\"] 。 \n无法再执行任何操作所以 [\"abba\",\"cd\"] 是最终答案。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>words = [\"a\",\"b\",\"c\",\"d\",\"e\"] \n<strong>输出:</strong>[\"a\",\"b\",\"c\",\"d\",\"e\"] \n<strong>解释:</strong> \nwords 中不存在互为字母异位词的两个相邻字符串,所以无需执行任何操作。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul> \n <li><code>1 <= words.length <= 100</code></li> \n <li><code>1 <= words[i].length <= 10</code></li> \n <li><code>words[i]</code> 由小写英文字母组成</li> \n</ul> </p>\n<div><div>Related Topics</div><div><li>数组</li><li>哈希表</li><li>字符串</li><li>排序</li></div></div>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>遍历字符串数组,分别将每一个字符串装换成字符数组,字符数组排序,如果排序后转成的字符串一样,则说明是字母异位词</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public List&lt;String&gt; removeAnagrams(String[] words) &#123;\n char[] strs &#x3D; words[0].toCharArray();\n Arrays.sort(strs);\n List&lt;String&gt; list &#x3D; new ArrayList&lt;&gt;();\n int index &#x3D; 0;\n for (int i &#x3D; 1; i &lt; words.length; i++) &#123;\n char[] strs1 &#x3D; words[i].toCharArray();\n Arrays.sort(strs1);\n if (!String.valueOf(strs).equals(String.valueOf(strs1))) &#123;\n list.add(words[index]);\n strs &#x3D; strs1;\n index &#x3D; i;\n &#125;\n &#125;\n list.add(words[index]);\n return list;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣周赛292题解","slug":"weekly-contest-292","date":"2022-05-10T06:01:37.000Z","updated":"2022-09-22T07:39:53.235Z","comments":true,"path":"/post/weekly-contest-292/","link":"","excerpt":"","content":"<h1 id=\"第一题\"><a href=\"#第一题\" class=\"headerlink\" title=\"第一题\"></a>第一题</h1><h2 id=\"力扣原题链接:\"><a href=\"#力扣原题链接:\" class=\"headerlink\" title=\"力扣原题链接:\"></a>力扣原题链接:</h2><p><a href=\"https://leetcode.cn/problems/largest-3-same-digit-number-in-string/\">2264. 字符串中最大的 3 位相同数字</a></p>\n<h2 id=\"单个题解:\"><a href=\"#单个题解:\" class=\"headerlink\" title=\"单个题解:\"></a>单个题解:</h2><p><a href=\"http://192.168.0.198:5080/post/largest-3-same-digit-number-in-string/\">力扣2264. 字符串中最大的 3 位相同数字</a></p>\n<h2 id=\"题解:\"><a href=\"#题解:\" class=\"headerlink\" title=\"题解:\"></a>题解:</h2><p>这题是要找最大的3个相同数并且3个数是相连的因为数字的话只有0~9这10个数字找最大的那我就从999开始然后依次888、777。。。000只要字符串中存在那就是它了。</p>\n<h2 id=\"java代码\"><a href=\"#java代码\" class=\"headerlink\" title=\"java代码\"></a>java代码</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public String largestGoodInteger(String num) &#123;\n String str;\n for (int i &#x3D; 9; i &gt;&#x3D; 0; i--) &#123;\n str &#x3D; &quot;&quot; + i + i + i;\n if (num.contains(str)) &#123;\n return str;\n &#125;\n &#125;\n return &quot;&quot;;\n&#125;</code></pre>\n<h1 id=\"第二题\"><a href=\"#第二题\" class=\"headerlink\" title=\"第二题\"></a>第二题</h1><h2 id=\"力扣原题链接:-1\"><a href=\"#力扣原题链接:-1\" class=\"headerlink\" title=\"力扣原题链接:\"></a>力扣原题链接:</h2><p><a href=\"https://leetcode.cn/problems/count-nodes-equal-to-average-of-subtree/\">6057. 统计值等于子树平均值的节点数</a></p>\n<h2 id=\"单个题解:-1\"><a href=\"#单个题解:-1\" class=\"headerlink\" title=\"单个题解:\"></a>单个题解:</h2><p><a href=\"http://192.168.0.198:5080/post/count-nodes-equal-to-average-of-subtree/\">力扣6057. 统计值等于子树平均值的节点数</a></p>\n<h2 id=\"题解:-1\"><a href=\"#题解:-1\" class=\"headerlink\" title=\"题解:\"></a>题解:</h2><p>这题的思路:</p>\n<ul>\n<li><p>先深度遍历树,统计出每个节点包含的节点数,并将其放入队列中</p>\n</li>\n<li><p>再深度遍历一次树,这次计算出每个节点的元素和,并从队列中取到该节点的节点数,然后求平均值做判断</p>\n</li>\n</ul>\n<h2 id=\"java代码-1\"><a href=\"#java代码-1\" class=\"headerlink\" title=\"java代码\"></a>java代码</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int averageOfSubtree(TreeNode root) &#123;\n counts(root);\n sums(root);\n return count;\n &#125;\n Queue&lt;Integer&gt; queue &#x3D; new LinkedList&lt;&gt;();\n int count &#x3D; 0;\n private int counts(TreeNode root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return 0;\n &#125;\n int cnt &#x3D; counts(root.left) + counts(root.right) + 1;\n queue.add(cnt);\n return cnt;\n &#125;\n private int sums(TreeNode root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return 0;\n &#125;\n int sum &#x3D; root.val;\n sum +&#x3D; sums(root.left);\n sum +&#x3D; sums(root.right);\n if (sum &#x2F; queue.poll() &#x3D;&#x3D; root.val) &#123;\n count++;\n &#125;\n return sum;\n &#125;\n&#125;</code></pre>\n<h1 id=\"第三题\"><a href=\"#第三题\" class=\"headerlink\" title=\"第三题\"></a>第三题</h1><h2 id=\"力扣原题链接:-2\"><a href=\"#力扣原题链接:-2\" class=\"headerlink\" title=\"力扣原题链接:\"></a>力扣原题链接:</h2><p><a href=\"https://leetcode.cn/problems/count-number-of-texts/\">2266. 统计打字方案数</a></p>\n<h2 id=\"单个题解:-2\"><a href=\"#单个题解:-2\" class=\"headerlink\" title=\"单个题解:\"></a>单个题解:</h2><p><a href=\"http://192.168.0.198:5080/post/check-if-there-is-a-valid-parentheses-string-path/\">力扣2267. 检查是否有合法括号字符串路径</a></p>\n<h2 id=\"题解:-2\"><a href=\"#题解:-2\" class=\"headerlink\" title=\"题解:\"></a>题解:</h2><p>这题标的是中等题个人觉得解题方法有点取巧怎么取巧尼因为重复的数最多4个我完全可以嵌套3层if来处理当然我也是这么干的。只要遍历一遍就可以了。</p>\n<p>在遍历到索引<code>i</code>时,有如下情况:</p>\n<ol>\n<li><p>当前数字不和前面的组合,自己单独成一个新的</p>\n<p>索引<code>i</code>的种数 = 索引<code>i-1</code>的种数</p>\n</li>\n<li><p>当前数字与前一个相等,那么该数字的组合就有两种情况</p>\n<ul>\n<li><p>直接和前一个数字凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-2</code>的种数</p>\n</li>\n<li><p>索引<code>i</code>的数字和索引<code>i-2</code>的数字也相等这也有2种情况</p>\n<ul>\n<li><p>把索引<code>i</code>,<code>i-1</code>,<code>i-2</code>都凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-3</code>的种数</p>\n</li>\n<li><p>索引<code>i</code>是7或者9最多可以连续4个把索引<code>i</code>,<code>i-1</code>,<code>i-2</code>,<code>i-3</code>都凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-4</code>的种数</p>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ol>\n<p>同时为了保证数据没有超过int的最大值这里对于每一次的结果都对109+7取余</p>\n<h2 id=\"java代码-2\"><a href=\"#java代码-2\" class=\"headerlink\" title=\"java代码\"></a>java代码</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countTexts(String pressedKeys) &#123;\n int[] cnts &#x3D; new int[pressedKeys.length() + 1];\n cnts[0] &#x3D; 1;\n cnts[1] &#x3D; 1;\n int mod &#x3D; 1000000007;\n for (int i &#x3D; 1; i &lt; pressedKeys.length(); i++) &#123;\n cnts[i + 1] &#x3D; cnts[i];\n if (pressdKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 1)) &#123;\n cnts[i + 1] +&#x3D; cnts[i - 1];\n cnts[i + 1] %&#x3D; mod;\n if (i &gt; 1 &amp;&amp; pressedKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 2)) &#123;\n cnts[i + 1] +&#x3D; cnts[i - 2];\n cnts[i + 1] %&#x3D; mod;\n if (i &gt; 2 &amp;&amp; pressedKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 3) &amp;&amp; (pressedKeys.charAt(i) &#x3D;&#x3D; &#39;7&#39; || pressedKeys.charAt(i) &#x3D;&#x3D; &#39;\n cnts[i + 1] +&#x3D; cnts[i - 3];\n cnts[i + 1] %&#x3D; mod;\n &#125;\n &#125;\n &#125;\n &#125;\n return cnts[pressedKeys.length()];\n &#125;\n&#125;</code></pre>\n<h1 id=\"第四题\"><a href=\"#第四题\" class=\"headerlink\" title=\"第四题\"></a>第四题</h1><h2 id=\"力扣原题链接:-3\"><a href=\"#力扣原题链接:-3\" class=\"headerlink\" title=\"力扣原题链接:\"></a>力扣原题链接:</h2><p><a href=\"https://leetcode.cn/problems/check-if-there-is-a-valid-parentheses-string-path/\">2267. 检查是否有合法括号字符串路径</a></p>\n<h2 id=\"单个题解:-3\"><a href=\"#单个题解:-3\" class=\"headerlink\" title=\"单个题解:\"></a>单个题解:</h2><p><a href=\"http://192.168.0.198:5080/post/count-number-of-texts/\">力扣2266. 统计打字方案数</a></p>\n<h2 id=\"题解:-3\"><a href=\"#题解:-3\" class=\"headerlink\" title=\"题解:\"></a>题解:</h2><p>从左上角到右下角,依次路过,下一个坐标一定是该坐标的右侧或者下侧的坐标,同时玩吗记录下路过到该坐标时未配对的’<code>&#39;(&#39;</code>的个数如果是负数则这条路不对旧不用继续下去了。然后一直到右下角的时候如果个数为1则满足条件</p>\n<h2 id=\"java代码-3\"><a href=\"#java代码-3\" class=\"headerlink\" title=\"java代码\"></a>java代码</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean hasValidPath(char[][] grid) &#123;\n xl &#x3D; grid.length;\n yl &#x3D; grid[0].length;\n use &#x3D; new boolean[xl][yl][xl * yl];\n if ((xl + yl) % 2 &#x3D;&#x3D; 0 || grid[0][0] &#x3D;&#x3D; &#39;)&#39; || grid[xl - 1][yl - \n return false;\n &#125;\n dfs(grid, 0, 0, 0);\n return bl;\n &#125;\n int xl;\n int yl;\n boolean bl &#x3D; false;\n boolean[][][] use;\n private void dfs(char[][] grid, int x, int y, int cnt) &#123;\n if (x &gt;&#x3D; xl || y &gt;&#x3D; yl || cnt &gt; xl - x + yl - y - 1) &#123;\n return;\n &#125;\n if (x &#x3D;&#x3D; xl - 1 &amp;&amp; y &#x3D;&#x3D; yl - 1) &#123;\n bl &#x3D; cnt &#x3D;&#x3D; 1;\n &#125;\n if (use[x][y][cnt]) &#123;\n return;\n &#125;\n use[x][y][cnt] &#x3D; true;\n cnt +&#x3D; grid[x][y] &#x3D;&#x3D; &#39;(&#39; ? 1 : -1;\n if (cnt &lt; 0) &#123;\n return;\n &#125;\n if (!bl) &#123;\n dfs(grid, x + 1, y, cnt);\n &#125;\n if (!bl) &#123;\n dfs(grid, x, y + 1, cnt);\n &#125;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"周赛","slug":"算法/力扣/周赛","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E5%91%A8%E8%B5%9B/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2267. 检查是否有合法括号字符串路径","slug":"check-if-there-is-a-valid-parentheses-string-path","date":"2022-05-10T02:50:21.000Z","updated":"2022-09-22T07:39:52.806Z","comments":true,"path":"/post/check-if-there-is-a-valid-parentheses-string-path/","link":"","excerpt":"","content":"<p>力扣周赛292—第四题</p>\n<p><a href=\"https://leetcode.cn/problems/check-if-there-is-a-valid-parentheses-string-path/\">2267. 检查是否有合法括号字符串路径</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>一个括号字符串是一个 <strong>非空</strong> 且只包含 <code>'('</code> 和 <code>')'</code> 的字符串。如果下面 <strong>任意</strong> 条件为 <strong>真</strong> ,那么这个括号字符串就是 <strong>合法的</strong> 。</p>\n\n<ul> \n <li>字符串是 <code>()</code> 。</li> \n <li>字符串可以表示为 <code>AB</code><code>A</code> 连接 <code>B</code><code>A</code> 和 <code>B</code> 都是合法括号序列。</li> \n <li>字符串可以表示为 <code>(A)</code> ,其中 <code>A</code> 是合法括号序列。</li> \n</ul>\n\n<p>给你一个 <code>m x n</code> 的括号网格图矩阵 <code>grid</code> 。网格图中一个 <strong>合法括号路径</strong> 是满足以下所有条件的一条路径:</p>\n\n<ul> \n <li>路径开始于左上角格子 <code>(0, 0)</code> 。</li> \n <li>路径结束于右下角格子 <code>(m - 1, n - 1)</code> 。</li> \n <li>路径每次只会向 <strong>下</strong> 或者向 <strong>右</strong> 移动。</li> \n <li>路径经过的格子组成的括号字符串是<strong> 合法</strong> 的。</li> \n</ul>\n\n<p>如果网格图中存在一条 <strong>合法括号路径</strong> ,请返回 <code>true</code> ,否则返回 <code>false</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/03/15/example1drawio.png\" style=\"width: 521px; height: 300px;\" /></p>\n\n<pre> \n<b>输入:</b>grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]] \n<b>输出:</b>true \n<b>解释:</b>上图展示了两条路径,它们都是合法括号字符串路径。 \n第一条路径得到的合法字符串是 \"()(())\" 。 \n第二条路径得到的合法字符串是 \"((()))\" 。 \n注意可能有其他的合法括号字符串路径。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/03/15/example2drawio.png\" style=\"width: 165px; height: 165px;\" /></p>\n\n<pre> \n<b>输入:</b>grid = [[\")\",\")\"],[\"(\",\"(\"]] \n<b>输出:</b>false \n<b>解释:</b>两条可行路径分别得到 \"))(\" 和 \")((\" 。由于它们都不是合法括号字符串,我们返回 false 。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>m == grid.length</code></li> \n <li><code>n == grid[i].length</code></li> \n <li><code>1 <= m, n <= 100</code></li> \n <li><code>grid[i][j]</code> 要么是 <code>'('</code> ,要么是 <code>')'</code> 。</li> \n</ul>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>从左上角到右下角,依次路过,下一个坐标一定是该坐标的右侧或者下侧的坐标,同时玩吗记录下路过到该坐标时未配对的’<code>&#39;(&#39;</code>的个数如果是负数则这条路不对旧不用继续下去了。然后一直到右下角的时候如果个数为1则满足条件</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>Java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean hasValidPath(char[][] grid) &#123;\n xl &#x3D; grid.length;\n yl &#x3D; grid[0].length;\n use &#x3D; new boolean[xl][yl][xl * yl];\n if ((xl + yl) % 2 &#x3D;&#x3D; 0 || grid[0][0] &#x3D;&#x3D; &#39;)&#39; || grid[xl - 1][yl - \n return false;\n &#125;\n dfs(grid, 0, 0, 0);\n return bl;\n &#125;\n int xl;\n int yl;\n boolean bl &#x3D; false;\n boolean[][][] use;\n private void dfs(char[][] grid, int x, int y, int cnt) &#123;\n if (x &gt;&#x3D; xl || y &gt;&#x3D; yl || cnt &gt; xl - x + yl - y - 1) &#123;\n return;\n &#125;\n if (x &#x3D;&#x3D; xl - 1 &amp;&amp; y &#x3D;&#x3D; yl - 1) &#123;\n bl &#x3D; cnt &#x3D;&#x3D; 1;\n &#125;\n if (use[x][y][cnt]) &#123;\n return;\n &#125;\n use[x][y][cnt] &#x3D; true;\n cnt +&#x3D; grid[x][y] &#x3D;&#x3D; &#39;(&#39; ? 1 : -1;\n if (cnt &lt; 0) &#123;\n return;\n &#125;\n if (!bl) &#123;\n dfs(grid, x + 1, y, cnt);\n &#125;\n if (!bl) &#123;\n dfs(grid, x, y + 1, cnt);\n &#125;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2266. 统计打字方案数","slug":"count-number-of-texts","date":"2022-05-10T01:32:53.000Z","updated":"2022-09-22T07:39:52.810Z","comments":true,"path":"/post/count-number-of-texts/","link":"","excerpt":"","content":"<p>力扣周赛292—第三题</p>\n<p><a href=\"https://leetcode.cn/problems/count-number-of-texts/\">2266. 统计打字方案数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>Alice 在给 Bob 用手机打字。数字到字母的 <strong>对应</strong> 如下图所示。</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png\" style=\"width: 200px; height: 162px;\"></p>\n\n<p>为了 <strong>打出</strong> 一个字母Alice 需要 <strong>按</strong> 对应字母 <code>i</code> 次,<code>i</code> 是该字母在这个按键上所处的位置。</p>\n\n<ul> \n <li>比方说,为了按出字母 <code>'s'</code> Alice 需要按 <code>'7'</code> 四次。类似的, Alice 需要按 <code>'5'</code> 两次得到字母 <code>'k'</code> 。</li> \n <li>注意,数字 <code>'0'</code> 和 <code>'1'</code> 不映射到任何字母,所以 Alice <strong>不</strong> 使用它们。</li> \n</ul>\n\n<p>但是由于传输的错误Bob 没有收到 Alice 打字的字母信息,反而收到了 <strong>按键的字符串信息</strong> 。</p>\n\n<ul> \n <li>比方说Alice 发出的信息为 <code>\"bob\"</code> Bob 将收到字符串 <code>\"2266622\"</code> 。</li> \n</ul>\n\n<p>给你一个字符串 <code>pressedKeys</code> ,表示 Bob 收到的字符串,请你返回 Alice <strong>总共可能发出多少种文字信息</strong> 。</p>\n\n<p>由于答案可能很大,将它对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><b>输入:</b>pressedKeys = \"22233\" \n<b>输出:</b>8 \n<strong>解释:</strong> \nAlice 可能发出的文字信息包括: \n\"aaadd\", \"abdd\", \"badd\", \"cdd\", \"aaae\", \"abe\", \"bae\" 和 \"ce\" 。 \n由于总共有 8 种可能的信息,所以我们返回 8 。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><b>输入:</b>pressedKeys = \"222222222222222222222222222222222222\" \n<b>输出:</b>82876089 \n<strong>解释:</strong> \n总共有 2082876103 种 Alice 可能发出的文字信息。 \n由于我们需要将答案对 10<sup>9</sup> + 7 取余,所以我们返回 2082876103 % (10<sup>9</sup> + 7) = 82876089 。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>1 <= pressedKeys.length <= 10<sup>5</sup></code></li> \n <li><code>pressedKeys</code> 只包含数字 <code>'2'</code> 到 <code>'9'</code> 。</li> \n</ul>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题标的是中等题个人觉得解题方法有点取巧怎么取巧尼因为重复的数最多4个我完全可以嵌套3层if来处理当然我也是这么干的。只要遍历一遍就可以了。</p>\n<p>在遍历到索引<code>i</code>时,有如下情况:</p>\n<ol>\n<li><p>当前数字不和前面的组合,自己单独成一个新的</p>\n<p>索引<code>i</code>的种数 = 索引<code>i-1</code>的种数</p>\n</li>\n<li><p>当前数字与前一个相等,那么该数字的组合就有两种情况</p>\n<ul>\n<li><p>直接和前一个数字凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-2</code>的种数</p>\n</li>\n<li><p>索引<code>i</code>的数字和索引<code>i-2</code>的数字也相等这也有2种情况</p>\n<ul>\n<li><p>把索引<code>i</code>,<code>i-1</code>,<code>i-2</code>都凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-3</code>的种数</p>\n</li>\n<li><p>索引<code>i</code>是7或者9最多可以连续4个把索引<code>i</code>,<code>i-1</code>,<code>i-2</code>,<code>i-3</code>都凑一起</p>\n<p>索引<code>i</code>的种数=索引<code>i-4</code>的种数</p>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ol>\n<p>同时为了保证数据没有超过int的最大值这里对于每一次的结果都对<span>10<sup>9</sup>+7</span>取余</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>Java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countTexts(String pressedKeys) &#123;\n int[] cnts &#x3D; new int[pressedKeys.length() + 1];\n cnts[0] &#x3D; 1;\n cnts[1] &#x3D; 1;\n int mod &#x3D; 1000000007;\n for (int i &#x3D; 1; i &lt; pressedKeys.length(); i++) &#123;\n cnts[i + 1] &#x3D; cnts[i];\n if (pressdKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 1)) &#123;\n cnts[i + 1] +&#x3D; cnts[i - 1];\n cnts[i + 1] %&#x3D; mod;\n if (i &gt; 1 &amp;&amp; pressedKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 2)) &#123;\n cnts[i + 1] +&#x3D; cnts[i - 2];\n cnts[i + 1] %&#x3D; mod;\n if (i &gt; 2 &amp;&amp; pressedKeys.charAt(i) &#x3D;&#x3D; pressedKeys.charAt(i - 3) &amp;&amp; (pressedKeys.charAt(i) &#x3D;&#x3D; &#39;7&#39; || pressedKeys.charAt(i) &#x3D;&#x3D; &#39;\n cnts[i + 1] +&#x3D; cnts[i - 3];\n cnts[i + 1] %&#x3D; mod;\n &#125;\n &#125;\n &#125;\n &#125;\n return cnts[pressedKeys.length()];\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣6057. 统计值等于子树平均值的节点数","slug":"count-nodes-equal-to-average-of-subtree","date":"2022-05-09T07:57:48.000Z","updated":"2022-09-22T07:39:52.810Z","comments":true,"path":"/post/count-nodes-equal-to-average-of-subtree/","link":"","excerpt":"","content":"<p>力扣周赛292—第二题</p>\n<p><a href=\"https://leetcode.cn/problems/count-nodes-equal-to-average-of-subtree/\">6057. 统计值等于子树平均值的节点数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一棵二叉树的根节点 <code>root</code> ,找出并返回满足要求的节点数,要求节点的值等于其 <strong>子树</strong> 中值的 <strong>平均值</strong> 。</p>\n\n<p><strong>注意:</strong></p>\n\n<ul> \n <li><code>n</code> 个元素的平均值可以由 <code>n</code> 个元素 <strong>求和</strong> 然后再除以 <code>n</code> ,并 <strong>向下舍入</strong> 到最近的整数。</li> \n <li><code>root</code> 的 <strong>子树</strong> 由 <code>root</code> 和它的所有后代组成。</li> \n</ul>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p> \n<img src=\"20220426172421.png\" style=\"width: 300px; height: 212px;\"> \n<pre><strong>输入:</strong>root = [4,8,5,0,1,null,6] \n<strong>输出:</strong>5 \n<strong>解释:</strong> \n对值为 4 的节点:子树的平均值 (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4 。 \n对值为 5 的节点:子树的平均值 (5 + 6) / 2 = 11 / 2 = 5 。 \n对值为 0 的节点:子树的平均值 0 / 1 = 0 。 \n对值为 1 的节点:子树的平均值 1 / 1 = 1 。 \n对值为 6 的节点:子树的平均值 6 / 1 = 6 。 \n</pre>\n\n<p><strong>示例 2</strong></p> \n<img src=\"image-20220326133920.png\" style=\"width: 80px; height: 76px;\"> \n<pre><strong>输入:</strong>root = [1] \n<strong>输出:</strong>1 \n<strong>解释:</strong>对值为 1 的节点:子树的平均值 1 / 1 = 1。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li>树中节点数目在范围 <code>[1, 1000]</code> 内</li> \n <li><code>0 <= Node.val <= 1000</code></li> \n</ul>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题的思路:</p>\n<ul>\n<li><p>先深度遍历树,统计出每个节点包含的节点数,并将其放入队列中</p>\n</li>\n<li><p>再深度遍历一次树,这次计算出每个节点的元素和,并从队列中取到该节点的节点数,然后求平均值做判断</p>\n</li>\n</ul>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>Java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int averageOfSubtree(TreeNode root) &#123;\n counts(root);\n sums(root);\n return count;\n &#125;\n Queue&lt;Integer&gt; queue &#x3D; new LinkedList&lt;&gt;();\n int count &#x3D; 0;\n private int counts(TreeNode root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return 0;\n &#125;\n int cnt &#x3D; counts(root.left) + counts(root.right) + 1;\n queue.add(cnt);\n return cnt;\n &#125;\n private int sums(TreeNode root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return 0;\n &#125;\n int sum &#x3D; root.val;\n sum +&#x3D; sums(root.left);\n sum +&#x3D; sums(root.right);\n if (sum &#x2F; queue.poll() &#x3D;&#x3D; root.val) &#123;\n count++;\n &#125;\n return sum;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2264. 字符串中最大的 3 位相同数字","slug":"largest-3-same-digit-number-in-string","date":"2022-05-09T07:24:16.000Z","updated":"2022-09-22T07:39:53.088Z","comments":true,"path":"/post/largest-3-same-digit-number-in-string/","link":"","excerpt":"","content":"<p>力扣周赛292—第一题</p>\n<p><a href=\"https://leetcode.cn/problems/largest-3-same-digit-number-in-string/\">2264. 字符串中最大的 3 位相同数字</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个字符串 <code>num</code> ,表示一个大整数。如果一个整数满足下述所有条件,则认为该整数是一个 <strong>优质整数</strong> </p>\n\n<ul> \n <li>该整数是 <code>num</code> 的一个长度为 <code>3</code> 的 <strong>子字符串</strong> 。</li> \n <li>该整数由唯一一个数字重复 <code>3</code> 次组成。</li> \n</ul>\n\n<p>以字符串形式返回 <strong>最大的优质整数</strong> 。如果不存在满足要求的整数,则返回一个空字符串 <code>\"\"</code> 。</p>\n\n<p><strong>注意:</strong></p>\n\n<ul> \n <li><strong>子字符串</strong> 是字符串中的一个连续字符序列。</li> \n <li><code>num</code> 或优质整数中可能存在 <strong>前导零</strong> 。</li> \n</ul>\n\n<p><strong>示例 1</strong></p>\n\n<pre> \n<strong>输入:</strong>num = \"6<em><strong>777</strong></em>133339\" \n<strong>输出:</strong>\"777\" \n<strong>解释:</strong>num 中存在两个优质整数:\"777\" 和 \"333\" 。 \n\"777\" 是最大的那个,所以返回 \"777\" 。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre> \n<strong>输入:</strong>num = \"23<em><strong>000</strong></em>19\" \n<strong>输出:</strong>\"000\" \n<strong>解释:</strong>\"000\" 是唯一一个优质整数。 \n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre> \n<strong>输入:</strong>num = \"42352338\" \n<strong>输出:</strong>\"\" \n<strong>解释:</strong>不存在长度为 3 且仅由一个唯一数字组成的整数。因此,不存在优质整数。 \n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul> \n <li><code>3 <= num.length <= 1000</code></li> \n <li><code>num</code> 仅由数字(<code>0</code> - <code>9</code>)组成</li> \n</ul>\n\n<h1 id=\"思路\"><a href=\"#思路\" class=\"headerlink\" title=\"思路\"></a>思路</h1><p>这题是要找最大的3个相同数并且3个数是相连的因为数字的话只有0~9这10个数字找最大的那我就从999开始然后依次888、777。。。000只要字符串中存在那就是它了。</p>\n<h1 id=\"代码\"><a href=\"#代码\" class=\"headerlink\" title=\"代码\"></a>代码</h1><p>java</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public String largestGoodInteger(String num) &#123;\n String str;\n for (int i &#x3D; 9; i &gt;&#x3D; 0; i--) &#123;\n str &#x3D; &quot;&quot; + i + i + i;\n if (num.contains(str)) &#123;\n return str;\n &#125;\n &#125;\n return &quot;&quot;;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"RKE方式安装k8s集群和Dashboard","slug":"inRKE","date":"2022-05-03T08:44:17.000Z","updated":"2022-09-22T07:39:52.990Z","comments":true,"path":"/post/inRKE/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>需要在电脑上安装好VirtualBox和Vagrant</p>\n<h1 id=\"构建3台虚拟机\"><a href=\"#构建3台虚拟机\" class=\"headerlink\" title=\"构建3台虚拟机\"></a>构建3台虚拟机</h1><h2 id=\"1、编写Vagrantfile文件\"><a href=\"#1、编写Vagrantfile文件\" class=\"headerlink\" title=\"1、编写Vagrantfile文件\"></a>1、编写Vagrantfile文件</h2><p>内容如下:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">Vagrant.configure(&quot;2&quot;) do |config|\n config.vm.box_check_update &#x3D; false\n config.vm.provider &#39;virtualbox&#39; do |vb|\n vb.customize [ &quot;guestproperty&quot;, &quot;set&quot;, :id, &quot;&#x2F;VirtualBox&#x2F;GuestAdd&#x2F;VBoxService&#x2F;--timesync-set-threshold&quot;, 1000 ]\n end \n $num_instances &#x3D; 3\n # curl https:&#x2F;&#x2F;discovery.etcd.io&#x2F;new?size&#x3D;3\n (1..$num_instances).each do |i|\n config.vm.define &quot;node#&#123;i&#125;&quot; do |node|\n node.vm.box &#x3D; &quot;centos&#x2F;7&quot;\n node.vm.hostname &#x3D; &quot;node#&#123;i&#125;&quot;\n ip &#x3D; &quot;172.17.8.#&#123;i+100&#125;&quot;\n node.vm.network &quot;private_network&quot;, ip: ip\n node.vm.provider &quot;virtualbox&quot; do |vb|\n vb.memory &#x3D; &quot;8192&quot;\n if i&#x3D;&#x3D;1 then\n vb.cpus &#x3D; 2\n else\n vb.cpus &#x3D; 1\n end\n vb.name &#x3D; &quot;node#&#123;i&#125;&quot;\n end\n end\n end\nend</code></pre>\n<h2 id=\"2、启动3台虚拟机\"><a href=\"#2、启动3台虚拟机\" class=\"headerlink\" title=\"2、启动3台虚拟机\"></a>2、启动3台虚拟机</h2><p>在Vagrantfile文件所在目录的控制台下执行命令</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vagrant up</code></pre>\n<p>等待完成完成后在VirtualBox主页</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-16-24-28-image.png\" alt=\"\"></p>\n<h1 id=\"虚拟机配置用户名密码ssh连接\"><a href=\"#虚拟机配置用户名密码ssh连接\" class=\"headerlink\" title=\"虚拟机配置用户名密码ssh连接\"></a>虚拟机配置用户名密码ssh连接</h1><p>3台虚拟机都需要安装</p>\n<p>配置参考:<a href=\"https://site.huangge1199.cn/189.html\">windows下VirtualBox和vagrant组合安装centos</a> 中的“用户名密码ssh”</p>\n<h1 id=\"虚拟机docker安装\"><a href=\"#虚拟机docker安装\" class=\"headerlink\" title=\"虚拟机docker安装\"></a>虚拟机docker安装</h1><p>3台虚拟机都需要安装</p>\n<p>安装教程:<a href=\"[docker安装-龙儿之家](http://192.168.0.198:5080/post/dockerInstall/\">docker安装教程</a>)</p>\n<h1 id=\"安装-Kubernetes-命令行工具-kubectl\"><a href=\"#安装-Kubernetes-命令行工具-kubectl\" class=\"headerlink\" title=\"安装 Kubernetes 命令行工具 kubectl\"></a>安装 Kubernetes 命令行工具 kubectl</h1><p>3台虚拟机都需要安装</p>\n<p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">yum install wget\nwget https:&#x2F;&#x2F;dl.k8s.io&#x2F;release&#x2F;v1.24.0&#x2F;bin&#x2F;linux&#x2F;amd64&#x2F;kubectl &amp;&amp; chmod +x kubectl &amp;&amp; cp kubectl &#x2F;usr&#x2F;bin&#x2F;</code></pre>\n<p>如果报错curl: (1) Protocol “https not supported or disabled in libcurl</p>\n<h1 id=\"安装RKE命令行工具\"><a href=\"#安装RKE命令行工具\" class=\"headerlink\" title=\"安装RKE命令行工具\"></a>安装RKE命令行工具</h1><p>只有主节点做即可</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">wget https:&#x2F;&#x2F;rancher-mirror.rancher.cn&#x2F;rke&#x2F;v1.3.10&#x2F;rke_linux-amd64 &amp;&amp; mv rke_linux-amd64 rke &amp;&amp; chmod +x rke &amp;&amp; .&#x2F;rke --version &amp;&amp; cp rke &#x2F;usr&#x2F;bin&#x2F;</code></pre>\n<h1 id=\"进行机器配置\"><a href=\"#进行机器配置\" class=\"headerlink\" title=\"进行机器配置\"></a>进行机器配置</h1><p>adduser rke -G docker</p>\n<h2 id=\"1、禁用-SELinux\"><a href=\"#1、禁用-SELinux\" class=\"headerlink\" title=\"1、禁用 SELinux\"></a>1、禁用 SELinux</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;etc&#x2F;selinux&#x2F;config</code></pre>\n<p>将第七行SELINUX=enforcing改为SELINUX=disabled</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-23-24-image.png\" alt=\"\"></p>\n<h2 id=\"2、禁用-swap\"><a href=\"#2、禁用-swap\" class=\"headerlink\" title=\"2、禁用 swap\"></a>2、禁用 swap</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;etc&#x2F;fstab</code></pre>\n<p>使用 # 注释掉有 swap 的一行</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-27-23-image.png\" alt=\"\"></p>\n<h2 id=\"3、关闭防火墙\"><a href=\"#3、关闭防火墙\" class=\"headerlink\" title=\"3、关闭防火墙\"></a>3、关闭防火墙</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">systemctl stop firewalld.service\nsystemctl disable firewalld.service</code></pre>\n<h2 id=\"4、重启查看效果\"><a href=\"#4、重启查看效果\" class=\"headerlink\" title=\"4、重启查看效果\"></a>4、重启查看效果</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">reboot\n&#x2F;usr&#x2F;sbin&#x2F;sestatus -v\nfree -h</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-33-11-image.png\" alt=\"\"></p>\n<h2 id=\"5、设置用户\"><a href=\"#5、设置用户\" class=\"headerlink\" title=\"5、设置用户\"></a>5、设置用户</h2><p>CentOS7不能使用root用户安装</p>\n<p>添加用户:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">adduser rke -G docker</code></pre>\n<p>给新添加的用户设置密码:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">passwd rke</code></pre>\n<p>中途需要输入2次密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-38-29-image.png\" alt=\"\"></p>\n<p>确认新用户是否有权限:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">su rke\ndocker ps -a</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-40-07-image.png\" alt=\"\"></p>\n<h2 id=\"6、设置SSH\"><a href=\"#6、设置SSH\" class=\"headerlink\" title=\"6、设置SSH\"></a>6、设置SSH</h2><p>这个地方要给全部的机器配置ssh包括自己注意在<mark>新用户</mark>下操作:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">ssh-keygen\nssh-copy-id rke@172.17.8.101\nssh-copy-id rke@172.17.8.102\nssh-copy-id rke@172.17.8.103</code></pre>\n<p>第一个红框位置输入yes第二个红框位置输入密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-17-46-31-image.png\" alt=\"\"></p>\n<h1 id=\"编辑rke-yaml\"><a href=\"#编辑rke-yaml\" class=\"headerlink\" title=\"编辑rke.yaml\"></a>编辑rke.yaml</h1><p>仅在主节点,在<mark>新用户</mark>下操作</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi rke.yaml</code></pre>\n<p>rke.yaml内容里面的IP换成各自的IP哦</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">nodes:\n - address: 172.17.8.101\n user: rke\n role: [controlplane, worker, etcd]\n - address: 172.17.8.102\n user: rke\n role: [controlplane, worker, etcd]\n - address: 172.17.8.103\n user: rke\n role: [worker]\n\nservices:\n etcd:\n snapshot: true\n creation: 6h\n retention: 24h\n\n# 当使用外部 TLS 终止,并且使用 ingress-nginx v0.22或以上版本时,必须。\ningress:\n provider: nginx\n options:\n use-forwarded-headers: “true”\nded-headers: “true”</code></pre>\n<h1 id=\"安装集群\"><a href=\"#安装集群\" class=\"headerlink\" title=\"安装集群\"></a>安装集群</h1><p>也是在<mark>新用户</mark>下操作:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">rke up --config rke.yaml</code></pre>\n<p>这步执行时间较长,多等一会,需要下载很多镜像~~~~</p>\n<p>运行完成后执行 </p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">mkdir ~&#x2F;.kube &amp;&amp; mv kube_config_rke.yaml ~&#x2F;.kube&#x2F;config</code></pre>\n<p>最后,执行下面的命令确认集群安装完成</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get node</code></pre>\n<h1 id=\"安装kubernetes-Dashboard\"><a href=\"#安装kubernetes-Dashboard\" class=\"headerlink\" title=\"安装kubernetes Dashboard\"></a>安装kubernetes Dashboard</h1><p>依然是在新用户下:</p>\n<p>切换到~目录下</p>\n<h2 id=\"1、获取dashboard的yaml文件\"><a href=\"#1、获取dashboard的yaml文件\" class=\"headerlink\" title=\"1、获取dashboard的yaml文件\"></a>1、获取dashboard的yaml文件</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">wget https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;kubernetes&#x2F;dashboard&#x2F;v2.0.4&#x2F;aio&#x2F;deploy&#x2F;recommended.yaml</code></pre>\n<h2 id=\"2、修改文件\"><a href=\"#2、修改文件\" class=\"headerlink\" title=\"2、修改文件\"></a>2、修改文件</h2><p>修改service部分默认service是ClusterIP类型这里改称NodePort类型是集群外部能否访问</p>\n<p>下面标红框的地方为新增加的:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-19-41-19-image.png\" alt=\"\"></p>\n<h2 id=\"3、执行yaml文件\"><a href=\"#3、执行yaml文件\" class=\"headerlink\" title=\"3、执行yaml文件\"></a>3、执行yaml文件</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f recommended.yaml</code></pre>\n<h2 id=\"4、查看服务状态\"><a href=\"#4、查看服务状态\" class=\"headerlink\" title=\"4、查看服务状态\"></a>4、查看服务状态</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl get all -n kubernetes-dashboard</code></pre>\n<p>下面红框的可以看出服务已经运行了</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-19-47-43-image.png\" alt=\"\"></p>\n<h2 id=\"5、接下来浏览器访问\"><a href=\"#5、接下来浏览器访问\" class=\"headerlink\" title=\"5、接下来浏览器访问\"></a>5、接下来浏览器访问</h2><p>IP30010端口就是你在第二步中添加的输入网址后点击高级继续访问就出现下面的页面了</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-19-48-18-image.png\" alt=\"\"></p>\n<h2 id=\"6、创建登录用户信息\"><a href=\"#6、创建登录用户信息\" class=\"headerlink\" title=\"6、创建登录用户信息\"></a>6、创建登录用户信息</h2><p>创建文件admin-role.yaml内容如下</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">kind: ClusterRoleBinding\napiVersion: rbac.authorization.k8s.io&#x2F;v1\nmetadata:\n name: admin\n annotations:\n rbac.authorization.kubernetes.io&#x2F;autoupdate: &quot;true&quot;\nroleRef:\n kind: ClusterRole\n name: cluster-admin\n apiGroup: rbac.authorization.k8s.io\nsubjects:\n- kind: ServiceAccount\n name: admin\n namespace: kube-system\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: admin\n namespace: kube-system\n labels:\n kubernetes.io&#x2F;cluster-service: &quot;true&quot;\n addonmanager.kubernetes.io&#x2F;mode: Reconcile</code></pre>\n<p>将其执行到集群中:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl apply -f admin-role.yaml</code></pre>\n<h2 id=\"7、获取token\"><a href=\"#7、获取token\" class=\"headerlink\" title=\"7、获取token\"></a>7、获取token</h2><p>查看kubernetes-dashboard下面的secret</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-20-50-13-image.png\" alt=\"\"></p>\n<p>在执行下面的命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">kubectl -n kube-system describe secret 红框的名字</code></pre>\n<p>红框内就是token</p>\n<p><img src=\"https://img.huangge1199.cn/blog/inRKE/2022-05-04-20-50-57-image.png\" alt=\"\"></p>\n","categories":[{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"PhpStorm自动上传修改的内容到服务器","slug":"phpDeploy","date":"2022-04-30T08:40:05.000Z","updated":"2022-09-22T07:39:53.156Z","comments":true,"path":"/post/phpDeploy/","link":"","excerpt":"","content":"<h1 id=\"前言\"><a href=\"#前言\" class=\"headerlink\" title=\"前言\"></a>前言</h1><p>今天在修改WordPress时发现利用宝塔的在线编辑好麻烦找到方法确无法直接跳过去于是乎我把代码下载到本地了本来想着利用编辑器来修改就可以跳转了没想到呀PhpStorm给了我一个大惊喜原来它只要配置好久可以直接在本地修改WordPress刷新就可以直接看到效果。</p>\n<p>接下来,我就详细的说明一下配置的步骤</p>\n<h1 id=\"配置步骤\"><a href=\"#配置步骤\" class=\"headerlink\" title=\"配置步骤\"></a>配置步骤</h1><h2 id=\"1、设置连接\"><a href=\"#1、设置连接\" class=\"headerlink\" title=\"1、设置连接\"></a>1、设置连接</h2><p>打开File—&gt;Setting</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-16-52-00-image.png\" alt=\"\"></p>\n<p>左侧Build,Execution,Deployment—&gt;Deployment然后右侧加号添加配置选择SFTP</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-16-54-56-image.png\" alt=\"\"></p>\n<p>弹出的窗口内输入配置的名称,可随意输入,方便记住就好</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-14-03-image.png\" alt=\"\"></p>\n<p>点击红框的位置添加ssh连接</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-12-36-image.png\" alt=\"\"></p>\n<p>在弹出的窗口点击 加号,右边配置</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-20-22-image.png\" alt=\"\"></p>\n<p>点击OK后ssh会自动添加上同时再把IP加入到下面的红框内</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-32-37-image.png\" alt=\"\"></p>\n<h2 id=\"2、设置文件映射关系\"><a href=\"#2、设置文件映射关系\" class=\"headerlink\" title=\"2、设置文件映射关系\"></a>2、设置文件映射关系</h2><p>点击mapping将服务器上项目的根目录添加到Deployment Path中如果点击OK</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-35-23-image.png\" alt=\"\"></p>\n<h2 id=\"3、设置自动上传\"><a href=\"#3、设置自动上传\" class=\"headerlink\" title=\"3、设置自动上传\"></a>3、设置自动上传</h2><p>在PhpStorm中依次点击Tool—&gt;Deployment—&gt;Options…</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-42-16-image.png\" alt=\"\"></p>\n<p>在弹出的窗口中将红框下拉框设置成第二个之后只要按Ctrl+S就可将修改的代码上传到服务器上</p>\n<p><img src=\"https://img.huangge1199.cn/blog/phpDeploy/2022-04-30-20-44-58-image.png\" alt=\"\"></p>\n","categories":[{"name":"PHP","slug":"PHP","permalink":"https://hexo.huangge1199.cn/categories/PHP/"}],"tags":[{"name":"PHP","slug":"PHP","permalink":"https://hexo.huangge1199.cn/tags/PHP/"}]},{"title":"设计模式总结与对比(作业)","slug":"designPattern","date":"2022-04-28T02:13:09.000Z","updated":"2022-09-22T07:39:52.866Z","comments":true,"path":"/post/designPattern/","link":"","excerpt":"","content":"<h1 id=\"1、设计模式的初衷是什么有哪些设计原则\"><a href=\"#1、设计模式的初衷是什么有哪些设计原则\" class=\"headerlink\" title=\"1、设计模式的初衷是什么有哪些设计原则\"></a>1、设计模式的初衷是什么有哪些设计原则</h1><ul>\n<li>开闭原则</li>\n<li>依赖倒置原则</li>\n<li>单一职责原则</li>\n<li>接口隔离原则</li>\n<li>迪米特原则</li>\n<li>里氏替换原则</li>\n<li>合成复用原则 </li>\n</ul>\n<h1 id=\"2、列举至少4种单例模式被破坏的场景并给出解决方案\"><a href=\"#2、列举至少4种单例模式被破坏的场景并给出解决方案\" class=\"headerlink\" title=\"2、列举至少4种单例模式被破坏的场景并给出解决方案\"></a>2、列举至少4种单例模式被破坏的场景并给出解决方案</h1><ul>\n<li><p>多线程</p>\n<p>解决办法:</p>\n<ul>\n<li><p>改写DCL双重锁的写法</p>\n</li>\n<li><p>使用静态内部类的写法</p>\n</li>\n</ul>\n</li>\n<li><p>指令重排</p>\n<p>解决办法加volite关键字</p>\n</li>\n<li><p>克隆</p>\n<p>解决办法在单例对象中重写clone()方法</p>\n</li>\n<li><p>反序列化</p>\n<p>解决方案反序列化的时候重新readResolve()方法,将返回值设置为单例对象</p>\n</li>\n<li><p>反射</p>\n<p>解决方法:</p>\n<ul>\n<li>在构造方法中检查单例对象,如果已构建则抛出异常</li>\n<li>将单例的实现方式改为枚举式单例</li>\n</ul>\n</li>\n</ul>\n<h1 id=\"3、一句话总结单例模式、原型模式、建造者模式、代理模式、策略模式和责任链模式\"><a href=\"#3、一句话总结单例模式、原型模式、建造者模式、代理模式、策略模式和责任链模式\" class=\"headerlink\" title=\"3、一句话总结单例模式、原型模式、建造者模式、代理模式、策略模式和责任链模式\"></a>3、一句话总结单例模式、原型模式、建造者模式、代理模式、策略模式和责任链模式</h1><ul>\n<li><p>单例模式世界上只有一个Tom</p>\n</li>\n<li><p>原型模式:拔一根猴毛,吹出千万个</p>\n</li>\n<li><p>建造者模式:高配中配与低配,相选哪配就哪配</p>\n</li>\n<li><p>代理模式:没有资源没有时间,得找媒婆来帮忙</p>\n</li>\n<li><p>策略模式:条条大路通北京,具体哪条你来定</p>\n</li>\n<li><p>责任链模式:各人自扫门前雪,莫管他人瓦上霜</p>\n</li>\n</ul>\n","categories":[{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"}]},{"title":"建造者模式","slug":"builder","date":"2022-04-26T09:10:11.000Z","updated":"2022-09-22T07:39:52.805Z","comments":true,"path":"/post/builder/","link":"","excerpt":"","content":"<h1 id=\"定义\"><a href=\"#定义\" class=\"headerlink\" title=\"定义\"></a>定义</h1><p>建造者模式是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示</p>\n<p>特征:用户只需指定需要建造的类型就可以获得对象,建造过程及细节不需要了解</p>\n<p>属于创建型模式</p>\n<h1 id=\"设计中四个角色\"><a href=\"#设计中四个角色\" class=\"headerlink\" title=\"设计中四个角色\"></a>设计中四个角色</h1><ul>\n<li>产品Product要创建的产品类对象</li>\n<li>建造者抽象Builder建造者的抽象类规范产品对象的各个组成部分的构建一般由子类实现具体的建造过程</li>\n<li>建造者ConcreBuilder具体的Builder类根据不同的业务逻辑具体化对象的各个组成部分的创建</li>\n<li>调用者Director调用具体的建造者来创建对象的各个部分在指导者中不涉及具体产品的信息只负责保证对象各部分完整创建或按某种顺序创建</li>\n</ul>\n<h1 id=\"适用场景\"><a href=\"#适用场景\" class=\"headerlink\" title=\"适用场景\"></a>适用场景</h1><ul>\n<li>相同的方法,不同的执行顺序,产生不同的结果时</li>\n<li>多个部件或零件,都可以装配到一个对象中,但是产生的结果又不同时</li>\n<li>产品类非常复杂,或者产品类中的调用顺序不同产生不同的作用</li>\n<li>当初始化一个对象特别复杂,参数多,而且很多参数都具有默认值时</li>\n</ul>\n<h1 id=\"优点\"><a href=\"#优点\" class=\"headerlink\" title=\"优点\"></a>优点</h1><ul>\n<li>封装性好,创建和使用分离</li>\n<li>拓展性好,建造类之间独立、一定程度上解耦 <h1 id=\"缺点\"><a href=\"#缺点\" class=\"headerlink\" title=\"缺点\"></a>缺点</h1></li>\n<li>产生多余的Builder对象</li>\n<li>产品内部发生变化,建造者都要修改,成本较大</li>\n</ul>\n<h1 id=\"建造者模式和工厂模式的区别\"><a href=\"#建造者模式和工厂模式的区别\" class=\"headerlink\" title=\"建造者模式和工厂模式的区别\"></a>建造者模式和工厂模式的区别</h1><ol>\n<li>建造者模式更加注重方法的调用顺序,工厂模式注重于创建对象。</li>\n<li>创建对象的力度不同,建造者模式创建复杂的对象,由各种复杂的部件组成,工厂模式创建出来的都一样。</li>\n<li>关注点:工厂模式模式只需要把对象创建出来就可以了,而建造者模式中不仅要创建出这个对象,还要知道这个对象由哪些部件组成。</li>\n<li>建造者模式根据建造过程中的顺序不一样,最终的对象部件组成也不一样。</li>\n</ol>\n","categories":[{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}]},{"title":"原型模式","slug":"prototype","date":"2022-04-26T07:12:44.000Z","updated":"2022-09-22T07:39:53.179Z","comments":true,"path":"/post/prototype/","link":"","excerpt":"","content":"<h1 id=\"定义\"><a href=\"#定义\" class=\"headerlink\" title=\"定义\"></a>定义</h1><p>原型模式时指原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象,属于创建型模式</p>\n<h1 id=\"应用场景\"><a href=\"#应用场景\" class=\"headerlink\" title=\"应用场景\"></a>应用场景</h1><ul>\n<li>类初始化消耗资源较多 </li>\n<li>new产生的一个对象需要非常繁琐的过程数据准备、访问权限等 </li>\n<li>构造函数比较复杂 </li>\n<li>循环体中生成大量对象时</li>\n</ul>\n<h1 id=\"优点\"><a href=\"#优点\" class=\"headerlink\" title=\"优点\"></a>优点</h1><ul>\n<li>性能优良Java自带的原型模式是基于内存二进制流的拷贝比直接new一个对象性能上提升了许多</li>\n<li>可以使用深克隆方式保存对象的状态,使用原型模式将对象复制一份并将其状态保存起来,简化了创建过程</li>\n</ul>\n<h1 id=\"缺点\"><a href=\"#缺点\" class=\"headerlink\" title=\"缺点\"></a>缺点</h1><ul>\n<li>必须配备克隆(或者可拷贝)方法</li>\n<li>当对已有类进行改造的时候,需要修改代码,违反了开闭原则。</li>\n<li>深拷贝、浅拷贝需要运用得当</li>\n</ul>\n<h1 id=\"克隆破坏单例模式\"><a href=\"#克隆破坏单例模式\" class=\"headerlink\" title=\"克隆破坏单例模式\"></a>克隆破坏单例模式</h1><p>如果我们克隆的目标对象是单例的对象,深克隆就会破坏单例。<br>解决办法可以禁止深克隆。要么你的单例类不实现Cloneable接口要么我们重写<br>clone()方法在clone方法中返回单例对象即可</p>\n","categories":[{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}]},{"title":"单例模式","slug":"singleton","date":"2022-04-26T06:44:05.000Z","updated":"2022-09-22T07:39:53.205Z","comments":true,"path":"/post/singleton/","link":"","excerpt":"","content":"<h1 id=\"定义\"><a href=\"#定义\" class=\"headerlink\" title=\"定义\"></a>定义</h1><p>确保一个类在任何情况下都绝对只有一个实例,并提供一个全局访问点</p>\n<h1 id=\"饿汉式单例\"><a href=\"#饿汉式单例\" class=\"headerlink\" title=\"饿汉式单例\"></a>饿汉式单例</h1><p>优点:执行效率高、性能高、没有融合的锁</p>\n<p>缺点:某些情况下,可能会造成内存浪费</p>\n<h2 id=\"常规写法\"><a href=\"#常规写法\" class=\"headerlink\" title=\"常规写法\"></a>常规写法</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class HungrySingleton &#123;\n\n private static final HungrySingleton hungrySingleton &#x3D; new HungrySingleton();\n\n private HungrySingleton() &#123;\n &#125;\n\n public static HungrySingleton getInstance() &#123;\n return hungrySingleton;\n &#125;\n&#125;</code></pre>\n<h2 id=\"利用静态代码块的写法\"><a href=\"#利用静态代码块的写法\" class=\"headerlink\" title=\"利用静态代码块的写法\"></a>利用静态代码块的写法</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class HungryStaticSingleton &#123;\n private static final HungryStaticSingleton hungrySingleton;\n\n static &#123;\n hungrySingleton &#x3D; new HungryStaticSingleton();\n &#125;\n\n private HungryStaticSingleton() &#123;\n &#125;\n\n public static HungryStaticSingleton getInstance() &#123;\n return hungrySingleton;\n &#125;\n&#125;</code></pre>\n<h1 id=\"懒汉式单例\"><a href=\"#懒汉式单例\" class=\"headerlink\" title=\"懒汉式单例\"></a>懒汉式单例</h1><h2 id=\"常规写法-1\"><a href=\"#常规写法-1\" class=\"headerlink\" title=\"常规写法\"></a>常规写法</h2><p>优点:节省了内存,线程安全</p>\n<p>缺点:性能低</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class LazySimpleSingletion &#123;\n private static LazySimpleSingletion instance;\n private LazySimpleSingletion()&#123;&#125;\n\n public synchronized static LazySimpleSingletion getInstance()&#123;\n if(instance &#x3D;&#x3D; null)&#123;\n instance &#x3D; new LazySimpleSingletion();\n &#125;\n return instance;\n &#125;\n&#125;</code></pre>\n<h2 id=\"双重检查\"><a href=\"#双重检查\" class=\"headerlink\" title=\"双重检查\"></a>双重检查</h2><p>优点:性能高了,线程安全了<br>缺点:可读性难度加大,不够优雅</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class LazyDoubleCheckSingleton &#123;\n private volatile static LazyDoubleCheckSingleton instance;\n\n private LazyDoubleCheckSingleton() &#123;\n &#125;\n\n public static LazyDoubleCheckSingleton getInstance() &#123;\n &#x2F;&#x2F;检查是否要阻塞\n if (instance &#x3D;&#x3D; null) &#123;\n synchronized (LazyDoubleCheckSingleton.class) &#123;\n &#x2F;&#x2F;检查是否要重新创建实例\n if (instance &#x3D;&#x3D; null) &#123;\n instance &#x3D; new LazyDoubleCheckSingleton();\n &#x2F;&#x2F;指令重排序的问题\n &#125;\n &#125;\n &#125;\n return instance;\n &#125;\n&#125;</code></pre>\n<h2 id=\"静态内部类单例\"><a href=\"#静态内部类单例\" class=\"headerlink\" title=\"静态内部类单例\"></a>静态内部类单例</h2><p>优点写法优雅利用了Java本身语法特点性能高避免了内存浪费,不能被反射破坏</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class LazyStaticInnerClassSingleton &#123;\n\n private LazyStaticInnerClassSingleton() &#123;\n if (LazyHolder.INSTANCE !&#x3D; null) &#123;\n throw new RuntimeException(&quot;不允许非法访问&quot;);\n &#125;\n &#125;\n\n private static LazyStaticInnerClassSingleton getInstance() &#123;\n return LazyHolder.INSTANCE;\n &#125;\n\n private static class LazyHolder &#123;\n private static final LazyStaticInnerClassSingleton INSTANCE &#x3D; new LazyStaticInnerClassSingleton();\n &#125;\n\n&#125;</code></pre>\n<h1 id=\"注册式单例\"><a href=\"#注册式单例\" class=\"headerlink\" title=\"注册式单例\"></a>注册式单例</h1><h2 id=\"枚举单例\"><a href=\"#枚举单例\" class=\"headerlink\" title=\"枚举单例\"></a>枚举单例</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public enum EnumSingleton &#123;\n INSTANCE;\n\n private Object data;\n\n public Object getData() &#123;\n return data;\n &#125;\n\n public void setData(Object data) &#123;\n this.data &#x3D; data;\n &#125;\n\n public static EnumSingleton getInstance() &#123;\n return INSTANCE;\n &#125;\n&#125;</code></pre>\n<h2 id=\"容器化单例\"><a href=\"#容器化单例\" class=\"headerlink\" title=\"容器化单例\"></a>容器化单例</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class ContainerSingleton &#123;\n\n private ContainerSingleton() &#123;\n &#125;\n\n private static Map&lt;String, Object&gt; ioc &#x3D; new ConcurrentHashMap&lt;String, Object&gt;();\n\n public static Object getInstance(String className) &#123;\n Object instance &#x3D; null;\n if (!ioc.containsKey(className)) &#123;\n try &#123;\n instance &#x3D; Class.forName(className).newInstance();\n ioc.put(className, instance);\n &#125; catch (Exception e) &#123;\n e.printStackTrace();\n &#125;\n return instance;\n &#125; else &#123;\n return ioc.get(className);\n &#125;\n &#125;\n\n&#125;</code></pre>\n<h1 id=\"序列化单例\"><a href=\"#序列化单例\" class=\"headerlink\" title=\"序列化单例\"></a>序列化单例</h1><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class SeriableSingleton implements Serializable &#123;\n \n public final static SeriableSingleton INSTANCE &#x3D; new SeriableSingleton();\n\n private SeriableSingleton() &#123;\n &#125;\n\n public static SeriableSingleton getInstance() &#123;\n return INSTANCE;\n &#125;\n\n private Object readResolve() &#123;\n return INSTANCE;\n &#125;\n\n&#125;</code></pre>\n<h1 id=\"线程\"><a href=\"#线程\" class=\"headerlink\" title=\"线程\"></a>线程</h1><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public class ThreadLocalSingleton &#123;\n private static final ThreadLocal&lt;ThreadLocalSingleton&gt; threadLocaLInstance &#x3D;\n new ThreadLocal&lt;ThreadLocalSingleton&gt;() &#123;\n @Override\n protected ThreadLocalSingleton initialValue() &#123;\n return new ThreadLocalSingleton();\n &#125;\n &#125;;\n\n private ThreadLocalSingleton() &#123;\n &#125;\n\n public static ThreadLocalSingleton getInstance() &#123;\n return threadLocaLInstance.get();\n &#125;\n&#125;CE;\n &#125;\n\n&#125;</code></pre>\n<h1 id=\"破坏单例模式的场景和解决方案\"><a href=\"#破坏单例模式的场景和解决方案\" class=\"headerlink\" title=\"破坏单例模式的场景和解决方案\"></a>破坏单例模式的场景和解决方案</h1><h2 id=\"1、指令重排使懒汉式模式失效\"><a href=\"#1、指令重排使懒汉式模式失效\" class=\"headerlink\" title=\"1、指令重排使懒汉式模式失效\"></a>1、指令重排使懒汉式模式失效</h2><p>解决办法:加<code>volatile</code>关键字</p>\n<h2 id=\"2、反射\"><a href=\"#2、反射\" class=\"headerlink\" title=\"2、反射\"></a>2、反射</h2><p>解决办法:弄一个全局变量标记是否实例化过,如果实例化过,抛异常</p>\n<h2 id=\"3、克隆\"><a href=\"#3、克隆\" class=\"headerlink\" title=\"3、克隆\"></a>3、克隆</h2><p>解决办法:重新克隆方法,调用时直接返回已经实例化的对象</p>\n<h2 id=\"4、序列化\"><a href=\"#4、序列化\" class=\"headerlink\" title=\"4、序列化\"></a>4、序列化</h2><p>解决办法:在反序列化时的回调方法 readResolve()中返回单例对象</p>\n","categories":[{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"}]},{"title":"docker-compose安装Redis","slug":"iRedisByDC","date":"2022-04-24T08:53:43.000Z","updated":"2022-09-22T07:39:52.915Z","comments":true,"path":"/post/iRedisByDC/","link":"","excerpt":"","content":"<h1 id=\"1、拉取镜像\"><a href=\"#1、拉取镜像\" class=\"headerlink\" title=\"1、拉取镜像\"></a>1、拉取镜像</h1><p>执行下面的命令拉取redis的docker镜像</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull redis</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iRedisByDC/2022-04-24-16-57-51-image.png\" alt=\"\"></p>\n<h1 id=\"2、编写docker-compose-yml文件\"><a href=\"#2、编写docker-compose-yml文件\" class=\"headerlink\" title=\"2、编写docker-compose.yml文件\"></a>2、编写docker-compose.yml文件</h1><p>内容如下:</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">version: &#39;3&#39;\nservices:\n redis:\n restart: always\n image: redis\n container_name: redis\n ports:\n - 50020:6379\n environment:\n TZ: Asia&#x2F;Shanghai\n volumes:\n - .&#x2F;data:&#x2F;data\n - .&#x2F;conf&#x2F;redis.conf:&#x2F;etc&#x2F;redis.conf\n privileged: true</code></pre>\n<h1 id=\"3、创建目录文件\"><a href=\"#3、创建目录文件\" class=\"headerlink\" title=\"3、创建目录文件\"></a>3、创建目录文件</h1><p>根据docker-compose.yml文件创建对应目录文件</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">pwd\nmkdir data\nmkdir conf\nll</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iRedisByDC/2022-04-24-17-04-13-image.png\" alt=\"\"></p>\n<h1 id=\"4、编写Redis的配置文件\"><a href=\"#4、编写Redis的配置文件\" class=\"headerlink\" title=\"4、编写Redis的配置文件\"></a>4、编写Redis的配置文件</h1><p>在conf目录下创建redis.conf文件文件内容如下</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\"># Redis configuration file example.\n#\n# Note that in order to read the configuration file, Redis must be\n# started with the file path as first argument:\n#\n# .&#x2F;redis-server &#x2F;path&#x2F;to&#x2F;redis.conf\n\n# Note on units: when memory size is needed, it is possible to specify\n# it in the usual form of 1k 5GB 4M and so forth:\n#\n# 1k &#x3D;&gt; 1000 bytes\n# 1kb &#x3D;&gt; 1024 bytes\n# 1m &#x3D;&gt; 1000000 bytes\n# 1mb &#x3D;&gt; 1024*1024 bytes\n# 1g &#x3D;&gt; 1000000000 bytes\n# 1gb &#x3D;&gt; 1024*1024*1024 bytes\n#\n# units are case insensitive so 1GB 1Gb 1gB are all the same.\n\n################################## INCLUDES ###################################\n\n# Include one or more other config files here. This is useful if you\n# have a standard template that goes to all Redis servers but also need\n# to customize a few per-server settings. Include files can include\n# other files, so use this wisely.\n#\n# Note that option &quot;include&quot; won&#39;t be rewritten by command &quot;CONFIG REWRITE&quot;\n# from admin or Redis Sentinel. Since Redis always uses the last processed\n# line as value of a configuration directive, you&#39;d better put includes\n# at the beginning of this file to avoid overwriting config change at runtime.\n#\n# If instead you are interested in using includes to override configuration\n# options, it is better to use include as the last line.\n#\n# include &#x2F;path&#x2F;to&#x2F;local.conf\n# include &#x2F;path&#x2F;to&#x2F;other.conf\n\n################################## MODULES #####################################\n\n# Load modules at startup. If the server is not able to load modules\n# it will abort. It is possible to use multiple loadmodule directives.\n#\n# loadmodule &#x2F;path&#x2F;to&#x2F;my_module.so\n# loadmodule &#x2F;path&#x2F;to&#x2F;other_module.so\n\n################################## NETWORK #####################################\n\n# By default, if no &quot;bind&quot; configuration directive is specified, Redis listens\n# for connections from all available network interfaces on the host machine.\n# It is possible to listen to just one or multiple selected interfaces using\n# the &quot;bind&quot; configuration directive, followed by one or more IP addresses.\n# Each address can be prefixed by &quot;-&quot;, which means that redis will not fail to\n# start if the address is not available. Being not available only refers to\n# addresses that does not correspond to any network interfece. Addresses that\n# are already in use will always fail, and unsupported protocols will always BE\n# silently skipped.\n#\n# Examples:\n#\n# bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses\n# bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6\n# bind * -::* # like the default, all available interfaces\n#\n# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the\n# internet, binding to all the interfaces is dangerous and will expose the\n# instance to everybody on the internet. So by default we uncomment the\n# following bind directive, that will force Redis to listen only on the\n# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis\n# will only be able to accept client connections from the same host that it is\n# running on).\n#\n# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES\n# JUST COMMENT OUT THE FOLLOWING LINE.\n# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# bind 127.0.0.1 -::1\n\n# Protected mode is a layer of security protection, in order to avoid that\n# Redis instances left open on the internet are accessed and exploited.\n#\n# When protected mode is on and if:\n#\n# 1) The server is not binding explicitly to a set of addresses using the\n# &quot;bind&quot; directive.\n# 2) No password is configured.\n#\n# The server only accepts connections from clients connecting from the\n# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain\n# sockets.\n#\n# By default protected mode is enabled. You should disable it only if\n# you are sure you want clients from other hosts to connect to Redis\n# even if no authentication is configured, nor a specific set of interfaces\n# are explicitly listed using the &quot;bind&quot; directive.\nprotected-mode no\n\n# Accept connections on the specified port, default is 6379 (IANA #815344).\n# If port 0 is specified Redis will not listen on a TCP socket.\nport 6379\n\n# TCP listen() backlog.\n#\n# In high requests-per-second environments you need a high backlog in order\n# to avoid slow clients connection issues. Note that the Linux kernel\n# will silently truncate it to the value of &#x2F;proc&#x2F;sys&#x2F;net&#x2F;core&#x2F;somaxconn so\n# make sure to raise both the value of somaxconn and tcp_max_syn_backlog\n# in order to get the desired effect.\ntcp-backlog 511\n\n# Unix socket.\n#\n# Specify the path for the Unix socket that will be used to listen for\n# incoming connections. There is no default, so Redis will not listen\n# on a unix socket when not specified.\n#\n# unixsocket &#x2F;run&#x2F;redis.sock\n# unixsocketperm 700\n\n# Close the connection after a client is idle for N seconds (0 to disable)\ntimeout 0\n\n# TCP keepalive.\n#\n# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence\n# of communication. This is useful for two reasons:\n#\n# 1) Detect dead peers.\n# 2) Force network equipment in the middle to consider the connection to be\n# alive.\n#\n# On Linux, the specified value (in seconds) is the period used to send ACKs.\n# Note that to close the connection the double of the time is needed.\n# On other kernels the period depends on the kernel configuration.\n#\n# A reasonable value for this option is 300 seconds, which is the new\n# Redis default starting with Redis 3.2.1.\ntcp-keepalive 300\n\n################################# TLS&#x2F;SSL #####################################\n\n# By default, TLS&#x2F;SSL is disabled. To enable it, the &quot;tls-port&quot; configuration\n# directive can be used to define TLS-listening ports. To enable TLS on the\n# default port, use:\n#\n# port 0\n# tls-port 6379\n\n# Configure a X.509 certificate and private key to use for authenticating the\n# server to connected clients, masters or cluster peers. These files should be\n# PEM formatted.\n#\n# tls-cert-file redis.crt \n# tls-key-file redis.key\n#\n# If the key file is encrypted using a passphrase, it can be included here\n# as well.\n#\n# tls-key-file-pass secret\n\n# Normally Redis uses the same certificate for both server functions (accepting\n# connections) and client functions (replicating from a master, establishing\n# cluster bus connections, etc.).\n#\n# Sometimes certificates are issued with attributes that designate them as\n# client-only or server-only certificates. In that case it may be desired to use\n# different certificates for incoming (server) and outgoing (client)\n# connections. To do that, use the following directives:\n#\n# tls-client-cert-file client.crt\n# tls-client-key-file client.key\n#\n# If the key file is encrypted using a passphrase, it can be included here\n# as well.\n#\n# tls-client-key-file-pass secret\n\n# Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange:\n#\n# tls-dh-params-file redis.dh\n\n# Configure a CA certificate(s) bundle or directory to authenticate TLS&#x2F;SSL\n# clients and peers. Redis requires an explicit configuration of at least one\n# of these, and will not implicitly use the system wide configuration.\n#\n# tls-ca-cert-file ca.crt\n# tls-ca-cert-dir &#x2F;etc&#x2F;ssl&#x2F;certs\n\n# By default, clients (including replica servers) on a TLS port are required\n# to authenticate using valid client side certificates.\n#\n# If &quot;no&quot; is specified, client certificates are not required and not accepted.\n# If &quot;optional&quot; is specified, client certificates are accepted and must be\n# valid if provided, but are not required.\n#\n# tls-auth-clients no\n# tls-auth-clients optional\n\n# By default, a Redis replica does not attempt to establish a TLS connection\n# with its master.\n#\n# Use the following directive to enable TLS on replication links.\n#\n# tls-replication yes\n\n# By default, the Redis Cluster bus uses a plain TCP connection. To enable\n# TLS for the bus protocol, use the following directive:\n#\n# tls-cluster yes\n\n# By default, only TLSv1.2 and TLSv1.3 are enabled and it is highly recommended\n# that older formally deprecated versions are kept disabled to reduce the attack surface.\n# You can explicitly specify TLS versions to support.\n# Allowed values are case insensitive and include &quot;TLSv1&quot;, &quot;TLSv1.1&quot;, &quot;TLSv1.2&quot;,\n# &quot;TLSv1.3&quot; (OpenSSL &gt;&#x3D; 1.1.1) or any combination.\n# To enable only TLSv1.2 and TLSv1.3, use:\n#\n# tls-protocols &quot;TLSv1.2 TLSv1.3&quot;\n\n# Configure allowed ciphers. See the ciphers(1ssl) manpage for more information\n# about the syntax of this string.\n#\n# Note: this configuration applies only to &lt;&#x3D; TLSv1.2.\n#\n# tls-ciphers DEFAULT:!MEDIUM\n\n# Configure allowed TLSv1.3 ciphersuites. See the ciphers(1ssl) manpage for more\n# information about the syntax of this string, and specifically for TLSv1.3\n# ciphersuites.\n#\n# tls-ciphersuites TLS_CHACHA20_POLY1305_SHA256\n\n# When choosing a cipher, use the server&#39;s preference instead of the client\n# preference. By default, the server follows the client&#39;s preference.\n#\n# tls-prefer-server-ciphers yes\n\n# By default, TLS session caching is enabled to allow faster and less expensive\n# reconnections by clients that support it. Use the following directive to disable\n# caching.\n#\n# tls-session-caching no\n\n# Change the default number of TLS sessions cached. A zero value sets the cache\n# to unlimited size. The default size is 20480.\n#\n# tls-session-cache-size 5000\n\n# Change the default timeout of cached TLS sessions. The default timeout is 300\n# seconds.\n#\n# tls-session-cache-timeout 60\n\n################################# GENERAL #####################################\n\n# By default Redis does not run as a daemon. Use &#39;yes&#39; if you need it.\n# Note that Redis will write a pid file in &#x2F;var&#x2F;run&#x2F;redis.pid when daemonized.\n# When Redis is supervised by upstart or systemd, this parameter has no impact.\ndaemonize no\n\n# If you run Redis from upstart or systemd, Redis can interact with your\n# supervision tree. Options:\n# supervised no - no supervision interaction\n# supervised upstart - signal upstart by putting Redis into SIGSTOP mode\n# requires &quot;expect stop&quot; in your upstart job config\n# supervised systemd - signal systemd by writing READY&#x3D;1 to $NOTIFY_SOCKET\n# on startup, and updating Redis status on a regular\n# basis.\n# supervised auto - detect upstart or systemd method based on\n# UPSTART_JOB or NOTIFY_SOCKET environment variables\n# Note: these supervision methods only signal &quot;process is ready.&quot;\n# They do not enable continuous pings back to your supervisor.\n#\n# The default is &quot;no&quot;. To run under upstart&#x2F;systemd, you can simply uncomment\n# the line below:\n#\n# supervised auto\n\n# If a pid file is specified, Redis writes it where specified at startup\n# and removes it at exit.\n#\n# When the server runs non daemonized, no pid file is created if none is\n# specified in the configuration. When the server is daemonized, the pid file\n# is used even if not specified, defaulting to &quot;&#x2F;var&#x2F;run&#x2F;redis.pid&quot;.\n#\n# Creating a pid file is best effort: if Redis is not able to create it\n# nothing bad happens, the server will start and run normally.\n#\n# Note that on modern Linux systems &quot;&#x2F;run&#x2F;redis.pid&quot; is more conforming\n# and should be used instead.\npidfile &#x2F;var&#x2F;run&#x2F;redis_6379.pid\n\n# Specify the server verbosity level.\n# This can be one of:\n# debug (a lot of information, useful for development&#x2F;testing)\n# verbose (many rarely useful info, but not a mess like the debug level)\n# notice (moderately verbose, what you want in production probably)\n# warning (only very important &#x2F; critical messages are logged)\nloglevel notice\n\n# Specify the log file name. Also the empty string can be used to force\n# Redis to log on the standard output. Note that if you use standard\n# output for logging but daemonize, logs will be sent to &#x2F;dev&#x2F;null\nlogfile &quot;&quot;\n\n# To enable logging to the system logger, just set &#39;syslog-enabled&#39; to yes,\n# and optionally update the other syslog parameters to suit your needs.\n# syslog-enabled no\n\n# Specify the syslog identity.\n# syslog-ident redis\n\n# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.\n# syslog-facility local0\n\n# To disable the built in crash log, which will possibly produce cleaner core\n# dumps when they are needed, uncomment the following:\n#\n# crash-log-enabled no\n\n# To disable the fast memory check that&#39;s run as part of the crash log, which\n# will possibly let redis terminate sooner, uncomment the following:\n#\n# crash-memcheck-enabled no\n\n# Set the number of databases. The default database is DB 0, you can select\n# a different one on a per-connection basis using SELECT &lt;dbid&gt; where\n# dbid is a number between 0 and &#39;databases&#39;-1\ndatabases 16\n\n# By default Redis shows an ASCII art logo only when started to log to the\n# standard output and if the standard output is a TTY and syslog logging is\n# disabled. Basically this means that normally a logo is displayed only in\n# interactive sessions.\n#\n# However it is possible to force the pre-4.0 behavior and always show a\n# ASCII art logo in startup logs by setting the following option to yes.\nalways-show-logo no\n\n# By default, Redis modifies the process title (as seen in &#39;top&#39; and &#39;ps&#39;) to\n# provide some runtime information. It is possible to disable this and leave\n# the process name as executed by setting the following to no.\nset-proc-title yes\n\n# When changing the process title, Redis uses the following template to construct\n# the modified title.\n#\n# Template variables are specified in curly brackets. The following variables are\n# supported:\n#\n# &#123;title&#125; Name of process as executed if parent, or type of child process.\n# &#123;listen-addr&#125; Bind address or &#39;*&#39; followed by TCP or TLS port listening on, or\n# Unix socket if only that&#39;s available.\n# &#123;server-mode&#125; Special mode, i.e. &quot;[sentinel]&quot; or &quot;[cluster]&quot;.\n# &#123;port&#125; TCP port listening on, or 0.\n# &#123;tls-port&#125; TLS port listening on, or 0.\n# &#123;unixsocket&#125; Unix domain socket listening on, or &quot;&quot;.\n# &#123;config-file&#125; Name of configuration file used.\n#\nproc-title-template &quot;&#123;title&#125; &#123;listen-addr&#125; &#123;server-mode&#125;&quot;\n\n################################ SNAPSHOTTING ################################\n\n# Save the DB to disk.\n#\n# save &lt;seconds&gt; &lt;changes&gt;\n#\n# Redis will save the DB if both the given number of seconds and the given\n# number of write operations against the DB occurred.\n#\n# Snapshotting can be completely disabled with a single empty string argument\n# as in following example:\n#\n# save &quot;&quot;\n#\n# Unless specified otherwise, by default Redis will save the DB:\n# * After 3600 seconds (an hour) if at least 1 key changed\n# * After 300 seconds (5 minutes) if at least 100 keys changed\n# * After 60 seconds if at least 10000 keys changed\n#\n# You can set these explicitly by uncommenting the three following lines.\n#\n# save 3600 1\n# save 300 100\n# save 60 10000\n\n# By default Redis will stop accepting writes if RDB snapshots are enabled\n# (at least one save point) and the latest background save failed.\n# This will make the user aware (in a hard way) that data is not persisting\n# on disk properly, otherwise chances are that no one will notice and some\n# disaster will happen.\n#\n# If the background saving process will start working again Redis will\n# automatically allow writes again.\n#\n# However if you have setup your proper monitoring of the Redis server\n# and persistence, you may want to disable this feature so that Redis will\n# continue to work as usual even if there are problems with disk,\n# permissions, and so forth.\nstop-writes-on-bgsave-error yes\n\n# Compress string objects using LZF when dump .rdb databases?\n# By default compression is enabled as it&#39;s almost always a win.\n# If you want to save some CPU in the saving child set it to &#39;no&#39; but\n# the dataset will likely be bigger if you have compressible values or keys.\nrdbcompression yes\n\n# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.\n# This makes the format more resistant to corruption but there is a performance\n# hit to pay (around 10%) when saving and loading RDB files, so you can disable it\n# for maximum performances.\n#\n# RDB files created with checksum disabled have a checksum of zero that will\n# tell the loading code to skip the check.\nrdbchecksum yes\n\n# Enables or disables full sanitation checks for ziplist and listpack etc when\n# loading an RDB or RESTORE payload. This reduces the chances of a assertion or\n# crash later on while processing commands.\n# Options:\n# no - Never perform full sanitation\n# yes - Always perform full sanitation\n# clients - Perform full sanitation only for user connections.\n# Excludes: RDB files, RESTORE commands received from the master\n# connection, and client connections which have the\n# skip-sanitize-payload ACL flag.\n# The default should be &#39;clients&#39; but since it currently affects cluster\n# resharding via MIGRATE, it is temporarily set to &#39;no&#39; by default.\n#\n# sanitize-dump-payload no\n\n# The filename where to dump the DB\ndbfilename dump.rdb\n\n# Remove RDB files used by replication in instances without persistence\n# enabled. By default this option is disabled, however there are environments\n# where for regulations or other security concerns, RDB files persisted on\n# disk by masters in order to feed replicas, or stored on disk by replicas\n# in order to load them for the initial synchronization, should be deleted\n# ASAP. Note that this option ONLY WORKS in instances that have both AOF\n# and RDB persistence disabled, otherwise is completely ignored.\n#\n# An alternative (and sometimes better) way to obtain the same effect is\n# to use diskless replication on both master and replicas instances. However\n# in the case of replicas, diskless is not always an option.\nrdb-del-sync-files no\n\n# The working directory.\n#\n# The DB will be written inside this directory, with the filename specified\n# above using the &#39;dbfilename&#39; configuration directive.\n#\n# The Append Only File will also be created inside this directory.\n#\n# Note that you must specify a directory here, not a file name.\ndir .&#x2F;\n\n################################# REPLICATION #################################\n\n# Master-Replica replication. Use replicaof to make a Redis instance a copy of\n# another Redis server. A few things to understand ASAP about Redis replication.\n#\n# +------------------+ +---------------+\n# | Master | ---&gt; | Replica |\n# | (receive writes) | | (exact copy) |\n# +------------------+ +---------------+\n#\n# 1) Redis replication is asynchronous, but you can configure a master to\n# stop accepting writes if it appears to be not connected with at least\n# a given number of replicas.\n# 2) Redis replicas are able to perform a partial resynchronization with the\n# master if the replication link is lost for a relatively small amount of\n# time. You may want to configure the replication backlog size (see the next\n# sections of this file) with a sensible value depending on your needs.\n# 3) Replication is automatic and does not need user intervention. After a\n# network partition replicas automatically try to reconnect to masters\n# and resynchronize with them.\n#\n# replicaof &lt;masterip&gt; &lt;masterport&gt;\n\n# If the master is password protected (using the &quot;requirepass&quot; configuration\n# directive below) it is possible to tell the replica to authenticate before\n# starting the replication synchronization process, otherwise the master will\n# refuse the replica request.\n#\n# masterauth &lt;master-password&gt;\n#\n# However this is not enough if you are using Redis ACLs (for Redis version\n# 6 or greater), and the default user is not capable of running the PSYNC\n# command and&#x2F;or other commands needed for replication. In this case it&#39;s\n# better to configure a special user to use with replication, and specify the\n# masteruser configuration as such:\n#\n# masteruser &lt;username&gt;\n#\n# When masteruser is specified, the replica will authenticate against its\n# master using the new AUTH form: AUTH &lt;username&gt; &lt;password&gt;.\n\n# When a replica loses its connection with the master, or when the replication\n# is still in progress, the replica can act in two different ways:\n#\n# 1) if replica-serve-stale-data is set to &#39;yes&#39; (the default) the replica will\n# still reply to client requests, possibly with out of date data, or the\n# data set may just be empty if this is the first synchronization.\n#\n# 2) If replica-serve-stale-data is set to &#39;no&#39; the replica will reply with\n# an error &quot;SYNC with master in progress&quot; to all commands except:\n# INFO, REPLICAOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, SUBSCRIBE,\n# UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, COMMAND, POST,\n# HOST and LATENCY.\n#\nreplica-serve-stale-data yes\n\n# You can configure a replica instance to accept writes or not. Writing against\n# a replica instance may be useful to store some ephemeral data (because data\n# written on a replica will be easily deleted after resync with the master) but\n# may also cause problems if clients are writing to it because of a\n# misconfiguration.\n#\n# Since Redis 2.6 by default replicas are read-only.\n#\n# Note: read only replicas are not designed to be exposed to untrusted clients\n# on the internet. It&#39;s just a protection layer against misuse of the instance.\n# Still a read only replica exports by default all the administrative commands\n# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve\n# security of read only replicas using &#39;rename-command&#39; to shadow all the\n# administrative &#x2F; dangerous commands.\nreplica-read-only yes\n\n# Replication SYNC strategy: disk or socket.\n#\n# New replicas and reconnecting replicas that are not able to continue the\n# replication process just receiving differences, need to do what is called a\n# &quot;full synchronization&quot;. An RDB file is transmitted from the master to the\n# replicas.\n#\n# The transmission can happen in two different ways:\n#\n# 1) Disk-backed: The Redis master creates a new process that writes the RDB\n# file on disk. Later the file is transferred by the parent\n# process to the replicas incrementally.\n# 2) Diskless: The Redis master creates a new process that directly writes the\n# RDB file to replica sockets, without touching the disk at all.\n#\n# With disk-backed replication, while the RDB file is generated, more replicas\n# can be queued and served with the RDB file as soon as the current child\n# producing the RDB file finishes its work. With diskless replication instead\n# once the transfer starts, new replicas arriving will be queued and a new\n# transfer will start when the current one terminates.\n#\n# When diskless replication is used, the master waits a configurable amount of\n# time (in seconds) before starting the transfer in the hope that multiple\n# replicas will arrive and the transfer can be parallelized.\n#\n# With slow disks and fast (large bandwidth) networks, diskless replication\n# works better.\nrepl-diskless-sync no\n\n# When diskless replication is enabled, it is possible to configure the delay\n# the server waits in order to spawn the child that transfers the RDB via socket\n# to the replicas.\n#\n# This is important since once the transfer starts, it is not possible to serve\n# new replicas arriving, that will be queued for the next RDB transfer, so the\n# server waits a delay in order to let more replicas arrive.\n#\n# The delay is specified in seconds, and by default is 5 seconds. To disable\n# it entirely just set it to 0 seconds and the transfer will start ASAP.\nrepl-diskless-sync-delay 5\n\n# -----------------------------------------------------------------------------\n# WARNING: RDB diskless load is experimental. Since in this setup the replica\n# does not immediately store an RDB on disk, it may cause data loss during\n# failovers. RDB diskless load + Redis modules not handling I&#x2F;O reads may also\n# cause Redis to abort in case of I&#x2F;O errors during the initial synchronization\n# stage with the master. Use only if you know what you are doing.\n# -----------------------------------------------------------------------------\n#\n# Replica can load the RDB it reads from the replication link directly from the\n# socket, or store the RDB to a file and read that file after it was completely\n# received from the master.\n#\n# In many cases the disk is slower than the network, and storing and loading\n# the RDB file may increase replication time (and even increase the master&#39;s\n# Copy on Write memory and salve buffers).\n# However, parsing the RDB file directly from the socket may mean that we have\n# to flush the contents of the current database before the full rdb was\n# received. For this reason we have the following options:\n#\n# &quot;disabled&quot; - Don&#39;t use diskless load (store the rdb file to the disk first)\n# &quot;on-empty-db&quot; - Use diskless load only when it is completely safe.\n# &quot;swapdb&quot; - Keep a copy of the current db contents in RAM while parsing\n# the data directly from the socket. note that this requires\n# sufficient memory, if you don&#39;t have it, you risk an OOM kill.\nrepl-diskless-load disabled\n\n# Replicas send PINGs to server in a predefined interval. It&#39;s possible to\n# change this interval with the repl_ping_replica_period option. The default\n# value is 10 seconds.\n#\n# repl-ping-replica-period 10\n\n# The following option sets the replication timeout for:\n#\n# 1) Bulk transfer I&#x2F;O during SYNC, from the point of view of replica.\n# 2) Master timeout from the point of view of replicas (data, pings).\n# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).\n#\n# It is important to make sure that this value is greater than the value\n# specified for repl-ping-replica-period otherwise a timeout will be detected\n# every time there is low traffic between the master and the replica. The default\n# value is 60 seconds.\n#\n# repl-timeout 60\n\n# Disable TCP_NODELAY on the replica socket after SYNC?\n#\n# If you select &quot;yes&quot; Redis will use a smaller number of TCP packets and\n# less bandwidth to send data to replicas. But this can add a delay for\n# the data to appear on the replica side, up to 40 milliseconds with\n# Linux kernels using a default configuration.\n#\n# If you select &quot;no&quot; the delay for data to appear on the replica side will\n# be reduced but more bandwidth will be used for replication.\n#\n# By default we optimize for low latency, but in very high traffic conditions\n# or when the master and replicas are many hops away, turning this to &quot;yes&quot; may\n# be a good idea.\nrepl-disable-tcp-nodelay no\n\n# Set the replication backlog size. The backlog is a buffer that accumulates\n# replica data when replicas are disconnected for some time, so that when a\n# replica wants to reconnect again, often a full resync is not needed, but a\n# partial resync is enough, just passing the portion of data the replica\n# missed while disconnected.\n#\n# The bigger the replication backlog, the longer the replica can endure the\n# disconnect and later be able to perform a partial resynchronization.\n#\n# The backlog is only allocated if there is at least one replica connected.\n#\n# repl-backlog-size 1mb\n\n# After a master has no connected replicas for some time, the backlog will be\n# freed. The following option configures the amount of seconds that need to\n# elapse, starting from the time the last replica disconnected, for the backlog\n# buffer to be freed.\n#\n# Note that replicas never free the backlog for timeout, since they may be\n# promoted to masters later, and should be able to correctly &quot;partially\n# resynchronize&quot; with other replicas: hence they should always accumulate backlog.\n#\n# A value of 0 means to never release the backlog.\n#\n# repl-backlog-ttl 3600\n\n# The replica priority is an integer number published by Redis in the INFO\n# output. It is used by Redis Sentinel in order to select a replica to promote\n# into a master if the master is no longer working correctly.\n#\n# A replica with a low priority number is considered better for promotion, so\n# for instance if there are three replicas with priority 10, 100, 25 Sentinel\n# will pick the one with priority 10, that is the lowest.\n#\n# However a special priority of 0 marks the replica as not able to perform the\n# role of master, so a replica with priority of 0 will never be selected by\n# Redis Sentinel for promotion.\n#\n# By default the priority is 100.\nreplica-priority 100\n\n# -----------------------------------------------------------------------------\n# By default, Redis Sentinel includes all replicas in its reports. A replica\n# can be excluded from Redis Sentinel&#39;s announcements. An unannounced replica\n# will be ignored by the &#39;sentinel replicas &lt;master&gt;&#39; command and won&#39;t be\n# exposed to Redis Sentinel&#39;s clients.\n#\n# This option does not change the behavior of replica-priority. Even with\n# replica-announced set to &#39;no&#39;, the replica can be promoted to master. To\n# prevent this behavior, set replica-priority to 0.\n#\n# replica-announced yes\n\n# It is possible for a master to stop accepting writes if there are less than\n# N replicas connected, having a lag less or equal than M seconds.\n#\n# The N replicas need to be in &quot;online&quot; state.\n#\n# The lag in seconds, that must be &lt;&#x3D; the specified value, is calculated from\n# the last ping received from the replica, that is usually sent every second.\n#\n# This option does not GUARANTEE that N replicas will accept the write, but\n# will limit the window of exposure for lost writes in case not enough replicas\n# are available, to the specified number of seconds.\n#\n# For example to require at least 3 replicas with a lag &lt;&#x3D; 10 seconds use:\n#\n# min-replicas-to-write 3\n# min-replicas-max-lag 10\n#\n# Setting one or the other to 0 disables the feature.\n#\n# By default min-replicas-to-write is set to 0 (feature disabled) and\n# min-replicas-max-lag is set to 10.\n\n# A Redis master is able to list the address and port of the attached\n# replicas in different ways. For example the &quot;INFO replication&quot; section\n# offers this information, which is used, among other tools, by\n# Redis Sentinel in order to discover replica instances.\n# Another place where this info is available is in the output of the\n# &quot;ROLE&quot; command of a master.\n#\n# The listed IP address and port normally reported by a replica is\n# obtained in the following way:\n#\n# IP: The address is auto detected by checking the peer address\n# of the socket used by the replica to connect with the master.\n#\n# Port: The port is communicated by the replica during the replication\n# handshake, and is normally the port that the replica is using to\n# listen for connections.\n#\n# However when port forwarding or Network Address Translation (NAT) is\n# used, the replica may actually be reachable via different IP and port\n# pairs. The following two options can be used by a replica in order to\n# report to its master a specific set of IP and port, so that both INFO\n# and ROLE will report those values.\n#\n# There is no need to use both the options if you need to override just\n# the port or the IP address.\n#\n# replica-announce-ip 5.5.5.5\n# replica-announce-port 1234\n\n############################### KEYS TRACKING #################################\n\n# Redis implements server assisted support for client side caching of values.\n# This is implemented using an invalidation table that remembers, using\n# a radix key indexed by key name, what clients have which keys. In turn\n# this is used in order to send invalidation messages to clients. Please\n# check this page to understand more about the feature:\n#\n# https:&#x2F;&#x2F;redis.io&#x2F;topics&#x2F;client-side-caching\n#\n# When tracking is enabled for a client, all the read only queries are assumed\n# to be cached: this will force Redis to store information in the invalidation\n# table. When keys are modified, such information is flushed away, and\n# invalidation messages are sent to the clients. However if the workload is\n# heavily dominated by reads, Redis could use more and more memory in order\n# to track the keys fetched by many clients.\n#\n# For this reason it is possible to configure a maximum fill value for the\n# invalidation table. By default it is set to 1M of keys, and once this limit\n# is reached, Redis will start to evict keys in the invalidation table\n# even if they were not modified, just to reclaim memory: this will in turn\n# force the clients to invalidate the cached values. Basically the table\n# maximum size is a trade off between the memory you want to spend server\n# side to track information about who cached what, and the ability of clients\n# to retain cached objects in memory.\n#\n# If you set the value to 0, it means there are no limits, and Redis will\n# retain as many keys as needed in the invalidation table.\n# In the &quot;stats&quot; INFO section, you can find information about the number of\n# keys in the invalidation table at every given moment.\n#\n# Note: when key tracking is used in broadcasting mode, no memory is used\n# in the server side so this setting is useless.\n#\n# tracking-table-max-keys 1000000\n\n################################## SECURITY ###################################\n\n# Warning: since Redis is pretty fast, an outside user can try up to\n# 1 million passwords per second against a modern box. This means that you\n# should use very strong passwords, otherwise they will be very easy to break.\n# Note that because the password is really a shared secret between the client\n# and the server, and should not be memorized by any human, the password\n# can be easily a long string from &#x2F;dev&#x2F;urandom or whatever, so by using a\n# long and unguessable password no brute force attack will be possible.\n\n# Redis ACL users are defined in the following format:\n#\n# user &lt;username&gt; ... acl rules ...\n#\n# For example:\n#\n# user worker +@list +@connection ~jobs:* on &gt;ffa9203c493aa99\n#\n# The special username &quot;default&quot; is used for new connections. If this user\n# has the &quot;nopass&quot; rule, then new connections will be immediately authenticated\n# as the &quot;default&quot; user without the need of any password provided via the\n# AUTH command. Otherwise if the &quot;default&quot; user is not flagged with &quot;nopass&quot;\n# the connections will start in not authenticated state, and will require\n# AUTH (or the HELLO command AUTH option) in order to be authenticated and\n# start to work.\n#\n# The ACL rules that describe what a user can do are the following:\n#\n# on Enable the user: it is possible to authenticate as this user.\n# off Disable the user: it&#39;s no longer possible to authenticate\n# with this user, however the already authenticated connections\n# will still work.\n# skip-sanitize-payload RESTORE dump-payload sanitation is skipped.\n# sanitize-payload RESTORE dump-payload is sanitized (default).\n# +&lt;command&gt; Allow the execution of that command\n# -&lt;command&gt; Disallow the execution of that command\n# +@&lt;category&gt; Allow the execution of all the commands in such category\n# with valid categories are like @admin, @set, @sortedset, ...\n# and so forth, see the full list in the server.c file where\n# the Redis command table is described and defined.\n# The special category @all means all the commands, but currently\n# present in the server, and that will be loaded in the future\n# via modules.\n# +&lt;command&gt;|subcommand Allow a specific subcommand of an otherwise\n# disabled command. Note that this form is not\n# allowed as negative like -DEBUG|SEGFAULT, but\n# only additive starting with &quot;+&quot;.\n# allcommands Alias for +@all. Note that it implies the ability to execute\n# all the future commands loaded via the modules system.\n# nocommands Alias for -@all.\n# ~&lt;pattern&gt; Add a pattern of keys that can be mentioned as part of\n# commands. For instance ~* allows all the keys. The pattern\n# is a glob-style pattern like the one of KEYS.\n# It is possible to specify multiple patterns.\n# allkeys Alias for ~*\n# resetkeys Flush the list of allowed keys patterns.\n# &amp;&lt;pattern&gt; Add a glob-style pattern of Pub&#x2F;Sub channels that can be\n# accessed by the user. It is possible to specify multiple channel\n# patterns.\n# allchannels Alias for &amp;*\n# resetchannels Flush the list of allowed channel patterns.\n# &gt;&lt;password&gt; Add this password to the list of valid password for the user.\n# For example &gt;mypass will add &quot;mypass&quot; to the list.\n# This directive clears the &quot;nopass&quot; flag (see later).\n# &lt;&lt;password&gt; Remove this password from the list of valid passwords.\n# nopass All the set passwords of the user are removed, and the user\n# is flagged as requiring no password: it means that every\n# password will work against this user. If this directive is\n# used for the default user, every new connection will be\n# immediately authenticated with the default user without\n# any explicit AUTH command required. Note that the &quot;resetpass&quot;\n# directive will clear this condition.\n# resetpass Flush the list of allowed passwords. Moreover removes the\n# &quot;nopass&quot; status. After &quot;resetpass&quot; the user has no associated\n# passwords and there is no way to authenticate without adding\n# some password (or setting it as &quot;nopass&quot; later).\n# reset Performs the following actions: resetpass, resetkeys, off,\n# -@all. The user returns to the same state it has immediately\n# after its creation.\n#\n# ACL rules can be specified in any order: for instance you can start with\n# passwords, then flags, or key patterns. However note that the additive\n# and subtractive rules will CHANGE MEANING depending on the ordering.\n# For instance see the following example:\n#\n# user alice on +@all -DEBUG ~* &gt;somepassword\n#\n# This will allow &quot;alice&quot; to use all the commands with the exception of the\n# DEBUG command, since +@all added all the commands to the set of the commands\n# alice can use, and later DEBUG was removed. However if we invert the order\n# of two ACL rules the result will be different:\n#\n# user alice on -DEBUG +@all ~* &gt;somepassword\n#\n# Now DEBUG was removed when alice had yet no commands in the set of allowed\n# commands, later all the commands are added, so the user will be able to\n# execute everything.\n#\n# Basically ACL rules are processed left-to-right.\n#\n# For more information about ACL configuration please refer to\n# the Redis web site at https:&#x2F;&#x2F;redis.io&#x2F;topics&#x2F;acl\n\n# ACL LOG\n#\n# The ACL Log tracks failed commands and authentication events associated\n# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked \n# by ACLs. The ACL Log is stored in memory. You can reclaim memory with \n# ACL LOG RESET. Define the maximum entry length of the ACL Log below.\nacllog-max-len 128\n\n# Using an external ACL file\n#\n# Instead of configuring users here in this file, it is possible to use\n# a stand-alone file just listing users. The two methods cannot be mixed:\n# if you configure users here and at the same time you activate the external\n# ACL file, the server will refuse to start.\n#\n# The format of the external ACL user file is exactly the same as the\n# format that is used inside redis.conf to describe users.\n#\n# aclfile &#x2F;etc&#x2F;redis&#x2F;users.acl\n\n# IMPORTANT NOTE: starting with Redis 6 &quot;requirepass&quot; is just a compatibility\n# layer on top of the new ACL system. The option effect will be just setting\n# the password for the default user. Clients will still authenticate using\n# AUTH &lt;password&gt; as usually, or more explicitly with AUTH default &lt;password&gt;\n# if they follow the new protocol: both will work.\n#\n# The requirepass is not compatable with aclfile option and the ACL LOAD\n# command, these will cause requirepass to be ignored.\n#\nrequirepass huangge1199\n\n# New users are initialized with restrictive permissions by default, via the\n# equivalent of this ACL rule &#39;off resetkeys -@all&#39;. Starting with Redis 6.2, it\n# is possible to manage access to Pub&#x2F;Sub channels with ACL rules as well. The\n# default Pub&#x2F;Sub channels permission if new users is controlled by the \n# acl-pubsub-default configuration directive, which accepts one of these values:\n#\n# allchannels: grants access to all Pub&#x2F;Sub channels\n# resetchannels: revokes access to all Pub&#x2F;Sub channels\n#\n# To ensure backward compatibility while upgrading Redis 6.0, acl-pubsub-default\n# defaults to the &#39;allchannels&#39; permission.\n#\n# Future compatibility note: it is very likely that in a future version of Redis\n# the directive&#39;s default of &#39;allchannels&#39; will be changed to &#39;resetchannels&#39; in\n# order to provide better out-of-the-box Pub&#x2F;Sub security. Therefore, it is\n# recommended that you explicitly define Pub&#x2F;Sub permissions for all users\n# rather then rely on implicit default values. Once you&#39;ve set explicit\n# Pub&#x2F;Sub for all existing users, you should uncomment the following line.\n#\n# acl-pubsub-default resetchannels\n\n# Command renaming (DEPRECATED).\n#\n# ------------------------------------------------------------------------\n# WARNING: avoid using this option if possible. Instead use ACLs to remove\n# commands from the default user, and put them only in some admin user you\n# create for administrative purposes.\n# ------------------------------------------------------------------------\n#\n# It is possible to change the name of dangerous commands in a shared\n# environment. For instance the CONFIG command may be renamed into something\n# hard to guess so that it will still be available for internal-use tools\n# but not available for general clients.\n#\n# Example:\n#\n# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52\n#\n# It is also possible to completely kill a command by renaming it into\n# an empty string:\n#\n# rename-command CONFIG &quot;&quot;\n#\n# Please note that changing the name of commands that are logged into the\n# AOF file or transmitted to replicas may cause problems.\n\n################################### CLIENTS ####################################\n\n# Set the max number of connected clients at the same time. By default\n# this limit is set to 10000 clients, however if the Redis server is not\n# able to configure the process file limit to allow for the specified limit\n# the max number of allowed clients is set to the current file limit\n# minus 32 (as Redis reserves a few file descriptors for internal uses).\n#\n# Once the limit is reached Redis will close all the new connections sending\n# an error &#39;max number of clients reached&#39;.\n#\n# IMPORTANT: When Redis Cluster is used, the max number of connections is also\n# shared with the cluster bus: every node in the cluster will use two\n# connections, one incoming and another outgoing. It is important to size the\n# limit accordingly in case of very large clusters.\n#\n# maxclients 10000\n\n############################## MEMORY MANAGEMENT ################################\n\n# Set a memory usage limit to the specified amount of bytes.\n# When the memory limit is reached Redis will try to remove keys\n# according to the eviction policy selected (see maxmemory-policy).\n#\n# If Redis can&#39;t remove keys according to the policy, or if the policy is\n# set to &#39;noeviction&#39;, Redis will start to reply with errors to commands\n# that would use more memory, like SET, LPUSH, and so on, and will continue\n# to reply to read-only commands like GET.\n#\n# This option is usually useful when using Redis as an LRU or LFU cache, or to\n# set a hard memory limit for an instance (using the &#39;noeviction&#39; policy).\n#\n# WARNING: If you have replicas attached to an instance with maxmemory on,\n# the size of the output buffers needed to feed the replicas are subtracted\n# from the used memory count, so that network problems &#x2F; resyncs will\n# not trigger a loop where keys are evicted, and in turn the output\n# buffer of replicas is full with DELs of keys evicted triggering the deletion\n# of more keys, and so forth until the database is completely emptied.\n#\n# In short... if you have replicas attached it is suggested that you set a lower\n# limit for maxmemory so that there is some free RAM on the system for replica\n# output buffers (but this is not needed if the policy is &#39;noeviction&#39;).\n#\n# maxmemory &lt;bytes&gt;\n\n# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory\n# is reached. You can select one from the following behaviors:\n#\n# volatile-lru -&gt; Evict using approximated LRU, only keys with an expire set.\n# allkeys-lru -&gt; Evict any key using approximated LRU.\n# volatile-lfu -&gt; Evict using approximated LFU, only keys with an expire set.\n# allkeys-lfu -&gt; Evict any key using approximated LFU.\n# volatile-random -&gt; Remove a random key having an expire set.\n# allkeys-random -&gt; Remove a random key, any key.\n# volatile-ttl -&gt; Remove the key with the nearest expire time (minor TTL)\n# noeviction -&gt; Don&#39;t evict anything, just return an error on write operations.\n#\n# LRU means Least Recently Used\n# LFU means Least Frequently Used\n#\n# Both LRU, LFU and volatile-ttl are implemented using approximated\n# randomized algorithms.\n#\n# Note: with any of the above policies, when there are no suitable keys for\n# eviction, Redis will return an error on write operations that require\n# more memory. These are usually commands that create new keys, add data or\n# modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,\n# SORT (due to the STORE argument), and EXEC (if the transaction includes any\n# command that requires memory).\n#\n# The default is:\n#\n# maxmemory-policy noeviction\n\n# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated\n# algorithms (in order to save memory), so you can tune it for speed or\n# accuracy. By default Redis will check five keys and pick the one that was\n# used least recently, you can change the sample size using the following\n# configuration directive.\n#\n# The default of 5 produces good enough results. 10 Approximates very closely\n# true LRU but costs more CPU. 3 is faster but not very accurate.\n#\n# maxmemory-samples 5\n\n# Eviction processing is designed to function well with the default setting.\n# If there is an unusually large amount of write traffic, this value may need to\n# be increased. Decreasing this value may reduce latency at the risk of \n# eviction processing effectiveness\n# 0 &#x3D; minimum latency, 10 &#x3D; default, 100 &#x3D; process without regard to latency\n#\n# maxmemory-eviction-tenacity 10\n\n# Starting from Redis 5, by default a replica will ignore its maxmemory setting\n# (unless it is promoted to master after a failover or manually). It means\n# that the eviction of keys will be just handled by the master, sending the\n# DEL commands to the replica as keys evict in the master side.\n#\n# This behavior ensures that masters and replicas stay consistent, and is usually\n# what you want, however if your replica is writable, or you want the replica\n# to have a different memory setting, and you are sure all the writes performed\n# to the replica are idempotent, then you may change this default (but be sure\n# to understand what you are doing).\n#\n# Note that since the replica by default does not evict, it may end using more\n# memory than the one set via maxmemory (there are certain buffers that may\n# be larger on the replica, or data structures may sometimes take more memory\n# and so forth). So make sure you monitor your replicas and make sure they\n# have enough memory to never hit a real out-of-memory condition before the\n# master hits the configured maxmemory setting.\n#\n# replica-ignore-maxmemory yes\n\n# Redis reclaims expired keys in two ways: upon access when those keys are\n# found to be expired, and also in background, in what is called the\n# &quot;active expire key&quot;. The key space is slowly and interactively scanned\n# looking for expired keys to reclaim, so that it is possible to free memory\n# of keys that are expired and will never be accessed again in a short time.\n#\n# The default effort of the expire cycle will try to avoid having more than\n# ten percent of expired keys still in memory, and will try to avoid consuming\n# more than 25% of total memory and to add latency to the system. However\n# it is possible to increase the expire &quot;effort&quot; that is normally set to\n# &quot;1&quot;, to a greater value, up to the value &quot;10&quot;. At its maximum value the\n# system will use more CPU, longer cycles (and technically may introduce\n# more latency), and will tolerate less already expired keys still present\n# in the system. It&#39;s a tradeoff between memory, CPU and latency.\n#\n# active-expire-effort 1\n\n############################# LAZY FREEING ####################################\n\n# Redis has two primitives to delete keys. One is called DEL and is a blocking\n# deletion of the object. It means that the server stops processing new commands\n# in order to reclaim all the memory associated with an object in a synchronous\n# way. If the key deleted is associated with a small object, the time needed\n# in order to execute the DEL command is very small and comparable to most other\n# O(1) or O(log_N) commands in Redis. However if the key is associated with an\n# aggregated value containing millions of elements, the server can block for\n# a long time (even seconds) in order to complete the operation.\n#\n# For the above reasons Redis also offers non blocking deletion primitives\n# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and\n# FLUSHDB commands, in order to reclaim memory in background. Those commands\n# are executed in constant time. Another thread will incrementally free the\n# object in the background as fast as possible.\n#\n# DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.\n# It&#39;s up to the design of the application to understand when it is a good\n# idea to use one or the other. However the Redis server sometimes has to\n# delete keys or flush the whole database as a side effect of other operations.\n# Specifically Redis deletes objects independently of a user call in the\n# following scenarios:\n#\n# 1) On eviction, because of the maxmemory and maxmemory policy configurations,\n# in order to make room for new data, without going over the specified\n# memory limit.\n# 2) Because of expire: when a key with an associated time to live (see the\n# EXPIRE command) must be deleted from memory.\n# 3) Because of a side effect of a command that stores data on a key that may\n# already exist. For example the RENAME command may delete the old key\n# content when it is replaced with another one. Similarly SUNIONSTORE\n# or SORT with STORE option may delete existing keys. The SET command\n# itself removes any old content of the specified key in order to replace\n# it with the specified string.\n# 4) During replication, when a replica performs a full resynchronization with\n# its master, the content of the whole database is removed in order to\n# load the RDB file just transferred.\n#\n# In all the above cases the default is to delete objects in a blocking way,\n# like if DEL was called. However you can configure each case specifically\n# in order to instead release memory in a non-blocking way like if UNLINK\n# was called, using the following configuration directives.\n\nlazyfree-lazy-eviction no\nlazyfree-lazy-expire no\nlazyfree-lazy-server-del no\nreplica-lazy-flush no\n\n# It is also possible, for the case when to replace the user code DEL calls\n# with UNLINK calls is not easy, to modify the default behavior of the DEL\n# command to act exactly like UNLINK, using the following configuration\n# directive:\n\nlazyfree-lazy-user-del no\n\n# FLUSHDB, FLUSHALL, and SCRIPT FLUSH support both asynchronous and synchronous\n# deletion, which can be controlled by passing the [SYNC|ASYNC] flags into the\n# commands. When neither flag is passed, this directive will be used to determine\n# if the data should be deleted asynchronously.\n\nlazyfree-lazy-user-flush no\n\n################################ THREADED I&#x2F;O #################################\n\n# Redis is mostly single threaded, however there are certain threaded\n# operations such as UNLINK, slow I&#x2F;O accesses and other things that are\n# performed on side threads.\n#\n# Now it is also possible to handle Redis clients socket reads and writes\n# in different I&#x2F;O threads. Since especially writing is so slow, normally\n# Redis users use pipelining in order to speed up the Redis performances per\n# core, and spawn multiple instances in order to scale more. Using I&#x2F;O\n# threads it is possible to easily speedup two times Redis without resorting\n# to pipelining nor sharding of the instance.\n#\n# By default threading is disabled, we suggest enabling it only in machines\n# that have at least 4 or more cores, leaving at least one spare core.\n# Using more than 8 threads is unlikely to help much. We also recommend using\n# threaded I&#x2F;O only if you actually have performance problems, with Redis\n# instances being able to use a quite big percentage of CPU time, otherwise\n# there is no point in using this feature.\n#\n# So for instance if you have a four cores boxes, try to use 2 or 3 I&#x2F;O\n# threads, if you have a 8 cores, try to use 6 threads. In order to\n# enable I&#x2F;O threads use the following configuration directive:\n#\n# io-threads 4\n#\n# Setting io-threads to 1 will just use the main thread as usual.\n# When I&#x2F;O threads are enabled, we only use threads for writes, that is\n# to thread the write(2) syscall and transfer the client buffers to the\n# socket. However it is also possible to enable threading of reads and\n# protocol parsing using the following configuration directive, by setting\n# it to yes:\n#\n# io-threads-do-reads no\n#\n# Usually threading reads doesn&#39;t help much.\n#\n# NOTE 1: This configuration directive cannot be changed at runtime via\n# CONFIG SET. Aso this feature currently does not work when SSL is\n# enabled.\n#\n# NOTE 2: If you want to test the Redis speedup using redis-benchmark, make\n# sure you also run the benchmark itself in threaded mode, using the\n# --threads option to match the number of Redis threads, otherwise you&#39;ll not\n# be able to notice the improvements.\n\n############################ KERNEL OOM CONTROL ##############################\n\n# On Linux, it is possible to hint the kernel OOM killer on what processes\n# should be killed first when out of memory.\n#\n# Enabling this feature makes Redis actively control the oom_score_adj value\n# for all its processes, depending on their role. The default scores will\n# attempt to have background child processes killed before all others, and\n# replicas killed before masters.\n#\n# Redis supports three options:\n#\n# no: Don&#39;t make changes to oom-score-adj (default).\n# yes: Alias to &quot;relative&quot; see below.\n# absolute: Values in oom-score-adj-values are written as is to the kernel.\n# relative: Values are used relative to the initial value of oom_score_adj when\n# the server starts and are then clamped to a range of -1000 to 1000.\n# Because typically the initial value is 0, they will often match the\n# absolute values.\noom-score-adj no\n\n# When oom-score-adj is used, this directive controls the specific values used\n# for master, replica and background child processes. Values range -2000 to\n# 2000 (higher means more likely to be killed).\n#\n# Unprivileged processes (not root, and without CAP_SYS_RESOURCE capabilities)\n# can freely increase their value, but not decrease it below its initial\n# settings. This means that setting oom-score-adj to &quot;relative&quot; and setting the\n# oom-score-adj-values to positive values will always succeed.\noom-score-adj-values 0 200 800\n\n\n#################### KERNEL transparent hugepage CONTROL ######################\n\n# Usually the kernel Transparent Huge Pages control is set to &quot;madvise&quot; or\n# or &quot;never&quot; by default (&#x2F;sys&#x2F;kernel&#x2F;mm&#x2F;transparent_hugepage&#x2F;enabled), in which\n# case this config has no effect. On systems in which it is set to &quot;always&quot;,\n# redis will attempt to disable it specifically for the redis process in order\n# to avoid latency problems specifically with fork(2) and CoW.\n# If for some reason you prefer to keep it enabled, you can set this config to\n# &quot;no&quot; and the kernel global to &quot;always&quot;.\n\ndisable-thp yes\n\n############################## APPEND ONLY MODE ###############################\n\n# By default Redis asynchronously dumps the dataset on disk. This mode is\n# good enough in many applications, but an issue with the Redis process or\n# a power outage may result into a few minutes of writes lost (depending on\n# the configured save points).\n#\n# The Append Only File is an alternative persistence mode that provides\n# much better durability. For instance using the default data fsync policy\n# (see later in the config file) Redis can lose just one second of writes in a\n# dramatic event like a server power outage, or a single write if something\n# wrong with the Redis process itself happens, but the operating system is\n# still running correctly.\n#\n# AOF and RDB persistence can be enabled at the same time without problems.\n# If the AOF is enabled on startup Redis will load the AOF, that is the file\n# with the better durability guarantees.\n#\n# Please check https:&#x2F;&#x2F;redis.io&#x2F;topics&#x2F;persistence for more information.\n\nappendonly no\n\n# The name of the append only file (default: &quot;appendonly.aof&quot;)\n\nappendfilename &quot;appendonly.aof&quot;\n\n# The fsync() call tells the Operating System to actually write data on disk\n# instead of waiting for more data in the output buffer. Some OS will really flush\n# data on disk, some other OS will just try to do it ASAP.\n#\n# Redis supports three different modes:\n#\n# no: don&#39;t fsync, just let the OS flush the data when it wants. Faster.\n# always: fsync after every write to the append only log. Slow, Safest.\n# everysec: fsync only one time every second. Compromise.\n#\n# The default is &quot;everysec&quot;, as that&#39;s usually the right compromise between\n# speed and data safety. It&#39;s up to you to understand if you can relax this to\n# &quot;no&quot; that will let the operating system flush the output buffer when\n# it wants, for better performances (but if you can live with the idea of\n# some data loss consider the default persistence mode that&#39;s snapshotting),\n# or on the contrary, use &quot;always&quot; that&#39;s very slow but a bit safer than\n# everysec.\n#\n# More details please check the following article:\n# http:&#x2F;&#x2F;antirez.com&#x2F;post&#x2F;redis-persistence-demystified.html\n#\n# If unsure, use &quot;everysec&quot;.\n\n# appendfsync always\nappendfsync everysec\n# appendfsync no\n\n# When the AOF fsync policy is set to always or everysec, and a background\n# saving process (a background save or AOF log background rewriting) is\n# performing a lot of I&#x2F;O against the disk, in some Linux configurations\n# Redis may block too long on the fsync() call. Note that there is no fix for\n# this currently, as even performing fsync in a different thread will block\n# our synchronous write(2) call.\n#\n# In order to mitigate this problem it&#39;s possible to use the following option\n# that will prevent fsync() from being called in the main process while a\n# BGSAVE or BGREWRITEAOF is in progress.\n#\n# This means that while another child is saving, the durability of Redis is\n# the same as &quot;appendfsync none&quot;. In practical terms, this means that it is\n# possible to lose up to 30 seconds of log in the worst scenario (with the\n# default Linux settings).\n#\n# If you have latency problems turn this to &quot;yes&quot;. Otherwise leave it as\n# &quot;no&quot; that is the safest pick from the point of view of durability.\n\nno-appendfsync-on-rewrite no\n\n# Automatic rewrite of the append only file.\n# Redis is able to automatically rewrite the log file implicitly calling\n# BGREWRITEAOF when the AOF log size grows by the specified percentage.\n#\n# This is how it works: Redis remembers the size of the AOF file after the\n# latest rewrite (if no rewrite has happened since the restart, the size of\n# the AOF at startup is used).\n#\n# This base size is compared to the current size. If the current size is\n# bigger than the specified percentage, the rewrite is triggered. Also\n# you need to specify a minimal size for the AOF file to be rewritten, this\n# is useful to avoid rewriting the AOF file even if the percentage increase\n# is reached but it is still pretty small.\n#\n# Specify a percentage of zero in order to disable the automatic AOF\n# rewrite feature.\n\nauto-aof-rewrite-percentage 100\nauto-aof-rewrite-min-size 64mb\n\n# An AOF file may be found to be truncated at the end during the Redis\n# startup process, when the AOF data gets loaded back into memory.\n# This may happen when the system where Redis is running\n# crashes, especially when an ext4 filesystem is mounted without the\n# data&#x3D;ordered option (however this can&#39;t happen when Redis itself\n# crashes or aborts but the operating system still works correctly).\n#\n# Redis can either exit with an error when this happens, or load as much\n# data as possible (the default now) and start if the AOF file is found\n# to be truncated at the end. The following option controls this behavior.\n#\n# If aof-load-truncated is set to yes, a truncated AOF file is loaded and\n# the Redis server starts emitting a log to inform the user of the event.\n# Otherwise if the option is set to no, the server aborts with an error\n# and refuses to start. When the option is set to no, the user requires\n# to fix the AOF file using the &quot;redis-check-aof&quot; utility before to restart\n# the server.\n#\n# Note that if the AOF file will be found to be corrupted in the middle\n# the server will still exit with an error. This option only applies when\n# Redis will try to read more data from the AOF file but not enough bytes\n# will be found.\naof-load-truncated yes\n\n# When rewriting the AOF file, Redis is able to use an RDB preamble in the\n# AOF file for faster rewrites and recoveries. When this option is turned\n# on the rewritten AOF file is composed of two different stanzas:\n#\n# [RDB file][AOF tail]\n#\n# When loading, Redis recognizes that the AOF file starts with the &quot;REDIS&quot;\n# string and loads the prefixed RDB file, then continues loading the AOF\n# tail.\naof-use-rdb-preamble yes\n\n################################ LUA SCRIPTING ###############################\n\n# Max execution time of a Lua script in milliseconds.\n#\n# If the maximum execution time is reached Redis will log that a script is\n# still in execution after the maximum allowed time and will start to\n# reply to queries with an error.\n#\n# When a long running script exceeds the maximum execution time only the\n# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be\n# used to stop a script that did not yet call any write commands. The second\n# is the only way to shut down the server in the case a write command was\n# already issued by the script but the user doesn&#39;t want to wait for the natural\n# termination of the script.\n#\n# Set it to 0 or a negative value for unlimited execution without warnings.\nlua-time-limit 5000\n\n################################ REDIS CLUSTER ###############################\n\n# Normal Redis instances can&#39;t be part of a Redis Cluster; only nodes that are\n# started as cluster nodes can. In order to start a Redis instance as a\n# cluster node enable the cluster support uncommenting the following:\n#\n# cluster-enabled yes\n\n# Every cluster node has a cluster configuration file. This file is not\n# intended to be edited by hand. It is created and updated by Redis nodes.\n# Every Redis Cluster node requires a different cluster configuration file.\n# Make sure that instances running in the same system do not have\n# overlapping cluster configuration file names.\n#\n# cluster-config-file nodes-6379.conf\n\n# Cluster node timeout is the amount of milliseconds a node must be unreachable\n# for it to be considered in failure state.\n# Most other internal time limits are a multiple of the node timeout.\n#\n# cluster-node-timeout 15000\n\n# A replica of a failing master will avoid to start a failover if its data\n# looks too old.\n#\n# There is no simple way for a replica to actually have an exact measure of\n# its &quot;data age&quot;, so the following two checks are performed:\n#\n# 1) If there are multiple replicas able to failover, they exchange messages\n# in order to try to give an advantage to the replica with the best\n# replication offset (more data from the master processed).\n# Replicas will try to get their rank by offset, and apply to the start\n# of the failover a delay proportional to their rank.\n#\n# 2) Every single replica computes the time of the last interaction with\n# its master. This can be the last ping or command received (if the master\n# is still in the &quot;connected&quot; state), or the time that elapsed since the\n# disconnection with the master (if the replication link is currently down).\n# If the last interaction is too old, the replica will not try to failover\n# at all.\n#\n# The point &quot;2&quot; can be tuned by user. Specifically a replica will not perform\n# the failover if, since the last interaction with the master, the time\n# elapsed is greater than:\n#\n# (node-timeout * cluster-replica-validity-factor) + repl-ping-replica-period\n#\n# So for example if node-timeout is 30 seconds, and the cluster-replica-validity-factor\n# is 10, and assuming a default repl-ping-replica-period of 10 seconds, the\n# replica will not try to failover if it was not able to talk with the master\n# for longer than 310 seconds.\n#\n# A large cluster-replica-validity-factor may allow replicas with too old data to failover\n# a master, while a too small value may prevent the cluster from being able to\n# elect a replica at all.\n#\n# For maximum availability, it is possible to set the cluster-replica-validity-factor\n# to a value of 0, which means, that replicas will always try to failover the\n# master regardless of the last time they interacted with the master.\n# (However they&#39;ll always try to apply a delay proportional to their\n# offset rank).\n#\n# Zero is the only value able to guarantee that when all the partitions heal\n# the cluster will always be able to continue.\n#\n# cluster-replica-validity-factor 10\n\n# Cluster replicas are able to migrate to orphaned masters, that are masters\n# that are left without working replicas. This improves the cluster ability\n# to resist to failures as otherwise an orphaned master can&#39;t be failed over\n# in case of failure if it has no working replicas.\n#\n# Replicas migrate to orphaned masters only if there are still at least a\n# given number of other working replicas for their old master. This number\n# is the &quot;migration barrier&quot;. A migration barrier of 1 means that a replica\n# will migrate only if there is at least 1 other working replica for its master\n# and so forth. It usually reflects the number of replicas you want for every\n# master in your cluster.\n#\n# Default is 1 (replicas migrate only if their masters remain with at least\n# one replica). To disable migration just set it to a very large value or\n# set cluster-allow-replica-migration to &#39;no&#39;.\n# A value of 0 can be set but is useful only for debugging and dangerous\n# in production.\n#\n# cluster-migration-barrier 1\n\n# Turning off this option allows to use less automatic cluster configuration.\n# It both disables migration to orphaned masters and migration from masters\n# that became empty.\n#\n# Default is &#39;yes&#39; (allow automatic migrations).\n#\n# cluster-allow-replica-migration yes\n\n# By default Redis Cluster nodes stop accepting queries if they detect there\n# is at least a hash slot uncovered (no available node is serving it).\n# This way if the cluster is partially down (for example a range of hash slots\n# are no longer covered) all the cluster becomes, eventually, unavailable.\n# It automatically returns available as soon as all the slots are covered again.\n#\n# However sometimes you want the subset of the cluster which is working,\n# to continue to accept queries for the part of the key space that is still\n# covered. In order to do so, just set the cluster-require-full-coverage\n# option to no.\n#\n# cluster-require-full-coverage yes\n\n# This option, when set to yes, prevents replicas from trying to failover its\n# master during master failures. However the replica can still perform a\n# manual failover, if forced to do so.\n#\n# This is useful in different scenarios, especially in the case of multiple\n# data center operations, where we want one side to never be promoted if not\n# in the case of a total DC failure.\n#\n# cluster-replica-no-failover no\n\n# This option, when set to yes, allows nodes to serve read traffic while the\n# the cluster is in a down state, as long as it believes it owns the slots. \n#\n# This is useful for two cases. The first case is for when an application \n# doesn&#39;t require consistency of data during node failures or network partitions.\n# One example of this is a cache, where as long as the node has the data it\n# should be able to serve it. \n#\n# The second use case is for configurations that don&#39;t meet the recommended \n# three shards but want to enable cluster mode and scale later. A \n# master outage in a 1 or 2 shard configuration causes a read&#x2F;write outage to the\n# entire cluster without this option set, with it set there is only a write outage.\n# Without a quorum of masters, slot ownership will not change automatically. \n#\n# cluster-allow-reads-when-down no\n\n# In order to setup your cluster make sure to read the documentation\n# available at https:&#x2F;&#x2F;redis.io web site.\n\n########################## CLUSTER DOCKER&#x2F;NAT support ########################\n\n# In certain deployments, Redis Cluster nodes address discovery fails, because\n# addresses are NAT-ted or because ports are forwarded (the typical case is\n# Docker and other containers).\n#\n# In order to make Redis Cluster working in such environments, a static\n# configuration where each node knows its public address is needed. The\n# following four options are used for this scope, and are:\n#\n# * cluster-announce-ip\n# * cluster-announce-port\n# * cluster-announce-tls-port\n# * cluster-announce-bus-port\n#\n# Each instructs the node about its address, client ports (for connections\n# without and with TLS) and cluster message bus port. The information is then\n# published in the header of the bus packets so that other nodes will be able to\n# correctly map the address of the node publishing the information.\n#\n# If cluster-tls is set to yes and cluster-announce-tls-port is omitted or set\n# to zero, then cluster-announce-port refers to the TLS port. Note also that\n# cluster-announce-tls-port has no effect if cluster-tls is set to no.\n#\n# If the above options are not used, the normal Redis Cluster auto-detection\n# will be used instead.\n#\n# Note that when remapped, the bus port may not be at the fixed offset of\n# clients port + 10000, so you can specify any port and bus-port depending\n# on how they get remapped. If the bus-port is not set, a fixed offset of\n# 10000 will be used as usual.\n#\n# Example:\n#\n# cluster-announce-ip 10.1.1.5\n# cluster-announce-tls-port 6379\n# cluster-announce-port 0\n# cluster-announce-bus-port 6380\n\n################################## SLOW LOG ###################################\n\n# The Redis Slow Log is a system to log queries that exceeded a specified\n# execution time. The execution time does not include the I&#x2F;O operations\n# like talking with the client, sending the reply and so forth,\n# but just the time needed to actually execute the command (this is the only\n# stage of command execution where the thread is blocked and can not serve\n# other requests in the meantime).\n#\n# You can configure the slow log with two parameters: one tells Redis\n# what is the execution time, in microseconds, to exceed in order for the\n# command to get logged, and the other parameter is the length of the\n# slow log. When a new command is logged the oldest one is removed from the\n# queue of logged commands.\n\n# The following time is expressed in microseconds, so 1000000 is equivalent\n# to one second. Note that a negative number disables the slow log, while\n# a value of zero forces the logging of every command.\nslowlog-log-slower-than 10000\n\n# There is no limit to this length. Just be aware that it will consume memory.\n# You can reclaim memory used by the slow log with SLOWLOG RESET.\nslowlog-max-len 128\n\n################################ LATENCY MONITOR ##############################\n\n# The Redis latency monitoring subsystem samples different operations\n# at runtime in order to collect data related to possible sources of\n# latency of a Redis instance.\n#\n# Via the LATENCY command this information is available to the user that can\n# print graphs and obtain reports.\n#\n# The system only logs operations that were performed in a time equal or\n# greater than the amount of milliseconds specified via the\n# latency-monitor-threshold configuration directive. When its value is set\n# to zero, the latency monitor is turned off.\n#\n# By default latency monitoring is disabled since it is mostly not needed\n# if you don&#39;t have latency issues, and collecting data has a performance\n# impact, that while very small, can be measured under big load. Latency\n# monitoring can easily be enabled at runtime using the command\n# &quot;CONFIG SET latency-monitor-threshold &lt;milliseconds&gt;&quot; if needed.\nlatency-monitor-threshold 0\n\n############################# EVENT NOTIFICATION ##############################\n\n# Redis can notify Pub&#x2F;Sub clients about events happening in the key space.\n# This feature is documented at https:&#x2F;&#x2F;redis.io&#x2F;topics&#x2F;notifications\n#\n# For instance if keyspace events notification is enabled, and a client\n# performs a DEL operation on key &quot;foo&quot; stored in the Database 0, two\n# messages will be published via Pub&#x2F;Sub:\n#\n# PUBLISH __keyspace@0__:foo del\n# PUBLISH __keyevent@0__:del foo\n#\n# It is possible to select the events that Redis will notify among a set\n# of classes. Every class is identified by a single character:\n#\n# K Keyspace events, published with __keyspace@&lt;db&gt;__ prefix.\n# E Keyevent events, published with __keyevent@&lt;db&gt;__ prefix.\n# g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...\n# $ String commands\n# l List commands\n# s Set commands\n# h Hash commands\n# z Sorted set commands\n# x Expired events (events generated every time a key expires)\n# e Evicted events (events generated when a key is evicted for maxmemory)\n# t Stream commands\n# d Module key type events\n# m Key-miss events (Note: It is not included in the &#39;A&#39; class)\n# A Alias for g$lshzxetd, so that the &quot;AKE&quot; string means all the events\n# (Except key-miss events which are excluded from &#39;A&#39; due to their\n# unique nature).\n#\n# The &quot;notify-keyspace-events&quot; takes as argument a string that is composed\n# of zero or multiple characters. The empty string means that notifications\n# are disabled.\n#\n# Example: to enable list and generic events, from the point of view of the\n# event name, use:\n#\n# notify-keyspace-events Elg\n#\n# Example 2: to get the stream of the expired keys subscribing to channel\n# name __keyevent@0__:expired use:\n#\n# notify-keyspace-events Ex\n#\n# By default all notifications are disabled because most users don&#39;t need\n# this feature and the feature has some overhead. Note that if you don&#39;t\n# specify at least one of K or E, no events will be delivered.\nnotify-keyspace-events &quot;&quot;\n\n############################### GOPHER SERVER #################################\n\n# Redis contains an implementation of the Gopher protocol, as specified in\n# the RFC 1436 (https:&#x2F;&#x2F;www.ietf.org&#x2F;rfc&#x2F;rfc1436.txt).\n#\n# The Gopher protocol was very popular in the late &#39;90s. It is an alternative\n# to the web, and the implementation both server and client side is so simple\n# that the Redis server has just 100 lines of code in order to implement this\n# support.\n#\n# What do you do with Gopher nowadays? Well Gopher never *really* died, and\n# lately there is a movement in order for the Gopher more hierarchical content\n# composed of just plain text documents to be resurrected. Some want a simpler\n# internet, others believe that the mainstream internet became too much\n# controlled, and it&#39;s cool to create an alternative space for people that\n# want a bit of fresh air.\n#\n# Anyway for the 10nth birthday of the Redis, we gave it the Gopher protocol\n# as a gift.\n#\n# --- HOW IT WORKS? ---\n#\n# The Redis Gopher support uses the inline protocol of Redis, and specifically\n# two kind of inline requests that were anyway illegal: an empty request\n# or any request that starts with &quot;&#x2F;&quot; (there are no Redis commands starting\n# with such a slash). Normal RESP2&#x2F;RESP3 requests are completely out of the\n# path of the Gopher protocol implementation and are served as usual as well.\n#\n# If you open a connection to Redis when Gopher is enabled and send it\n# a string like &quot;&#x2F;foo&quot;, if there is a key named &quot;&#x2F;foo&quot; it is served via the\n# Gopher protocol.\n#\n# In order to create a real Gopher &quot;hole&quot; (the name of a Gopher site in Gopher\n# talking), you likely need a script like the following:\n#\n# https:&#x2F;&#x2F;github.com&#x2F;antirez&#x2F;gopher2redis\n#\n# --- SECURITY WARNING ---\n#\n# If you plan to put Redis on the internet in a publicly accessible address\n# to server Gopher pages MAKE SURE TO SET A PASSWORD to the instance.\n# Once a password is set:\n#\n# 1. The Gopher server (when enabled, not by default) will still serve\n# content via Gopher.\n# 2. However other commands cannot be called before the client will\n# authenticate.\n#\n# So use the &#39;requirepass&#39; option to protect your instance.\n#\n# Note that Gopher is not currently supported when &#39;io-threads-do-reads&#39;\n# is enabled.\n#\n# To enable Gopher support, uncomment the following line and set the option\n# from no (the default) to yes.\n#\n# gopher-enabled no\n\n############################### ADVANCED CONFIG ###############################\n\n# Hashes are encoded using a memory efficient data structure when they have a\n# small number of entries, and the biggest entry does not exceed a given\n# threshold. These thresholds can be configured using the following directives.\nhash-max-ziplist-entries 512\nhash-max-ziplist-value 64\n\n# Lists are also encoded in a special way to save a lot of space.\n# The number of entries allowed per internal list node can be specified\n# as a fixed maximum size or a maximum number of elements.\n# For a fixed maximum size, use -5 through -1, meaning:\n# -5: max size: 64 Kb &lt;-- not recommended for normal workloads\n# -4: max size: 32 Kb &lt;-- not recommended\n# -3: max size: 16 Kb &lt;-- probably not recommended\n# -2: max size: 8 Kb &lt;-- good\n# -1: max size: 4 Kb &lt;-- good\n# Positive numbers mean store up to _exactly_ that number of elements\n# per list node.\n# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),\n# but if your use case is unique, adjust the settings as necessary.\nlist-max-ziplist-size -2\n\n# Lists may also be compressed.\n# Compress depth is the number of quicklist ziplist nodes from *each* side of\n# the list to *exclude* from compression. The head and tail of the list\n# are always uncompressed for fast push&#x2F;pop operations. Settings are:\n# 0: disable all list compression\n# 1: depth 1 means &quot;don&#39;t start compressing until after 1 node into the list,\n# going from either the head or tail&quot;\n# So: [head]-&gt;node-&gt;node-&gt;...-&gt;node-&gt;[tail]\n# [head], [tail] will always be uncompressed; inner nodes will compress.\n# 2: [head]-&gt;[next]-&gt;node-&gt;node-&gt;...-&gt;node-&gt;[prev]-&gt;[tail]\n# 2 here means: don&#39;t compress head or head-&gt;next or tail-&gt;prev or tail,\n# but compress all nodes between them.\n# 3: [head]-&gt;[next]-&gt;[next]-&gt;node-&gt;node-&gt;...-&gt;node-&gt;[prev]-&gt;[prev]-&gt;[tail]\n# etc.\nlist-compress-depth 0\n\n# Sets have a special encoding in just one case: when a set is composed\n# of just strings that happen to be integers in radix 10 in the range\n# of 64 bit signed integers.\n# The following configuration setting sets the limit in the size of the\n# set in order to use this special memory saving encoding.\nset-max-intset-entries 512\n\n# Similarly to hashes and lists, sorted sets are also specially encoded in\n# order to save a lot of space. This encoding is only used when the length and\n# elements of a sorted set are below the following limits:\nzset-max-ziplist-entries 128\nzset-max-ziplist-value 64\n\n# HyperLogLog sparse representation bytes limit. The limit includes the\n# 16 bytes header. When an HyperLogLog using the sparse representation crosses\n# this limit, it is converted into the dense representation.\n#\n# A value greater than 16000 is totally useless, since at that point the\n# dense representation is more memory efficient.\n#\n# The suggested value is ~ 3000 in order to have the benefits of\n# the space efficient encoding without slowing down too much PFADD,\n# which is O(N) with the sparse encoding. The value can be raised to\n# ~ 10000 when CPU is not a concern, but space is, and the data set is\n# composed of many HyperLogLogs with cardinality in the 0 - 15000 range.\nhll-sparse-max-bytes 3000\n\n# Streams macro node max size &#x2F; items. The stream data structure is a radix\n# tree of big nodes that encode multiple items inside. Using this configuration\n# it is possible to configure how big a single node can be in bytes, and the\n# maximum number of items it may contain before switching to a new node when\n# appending new stream entries. If any of the following settings are set to\n# zero, the limit is ignored, so for instance it is possible to set just a\n# max entries limit by setting max-bytes to 0 and max-entries to the desired\n# value.\nstream-node-max-bytes 4096\nstream-node-max-entries 100\n\n# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in\n# order to help rehashing the main Redis hash table (the one mapping top-level\n# keys to values). The hash table implementation Redis uses (see dict.c)\n# performs a lazy rehashing: the more operation you run into a hash table\n# that is rehashing, the more rehashing &quot;steps&quot; are performed, so if the\n# server is idle the rehashing is never complete and some more memory is used\n# by the hash table.\n#\n# The default is to use this millisecond 10 times every second in order to\n# actively rehash the main dictionaries, freeing memory when possible.\n#\n# If unsure:\n# use &quot;activerehashing no&quot; if you have hard latency requirements and it is\n# not a good thing in your environment that Redis can reply from time to time\n# to queries with 2 milliseconds delay.\n#\n# use &quot;activerehashing yes&quot; if you don&#39;t have such hard requirements but\n# want to free memory asap when possible.\nactiverehashing yes\n\n# The client output buffer limits can be used to force disconnection of clients\n# that are not reading data from the server fast enough for some reason (a\n# common reason is that a Pub&#x2F;Sub client can&#39;t consume messages as fast as the\n# publisher can produce them).\n#\n# The limit can be set differently for the three different classes of clients:\n#\n# normal -&gt; normal clients including MONITOR clients\n# replica -&gt; replica clients\n# pubsub -&gt; clients subscribed to at least one pubsub channel or pattern\n#\n# The syntax of every client-output-buffer-limit directive is the following:\n#\n# client-output-buffer-limit &lt;class&gt; &lt;hard limit&gt; &lt;soft limit&gt; &lt;soft seconds&gt;\n#\n# A client is immediately disconnected once the hard limit is reached, or if\n# the soft limit is reached and remains reached for the specified number of\n# seconds (continuously).\n# So for instance if the hard limit is 32 megabytes and the soft limit is\n# 16 megabytes &#x2F; 10 seconds, the client will get disconnected immediately\n# if the size of the output buffers reach 32 megabytes, but will also get\n# disconnected if the client reaches 16 megabytes and continuously overcomes\n# the limit for 10 seconds.\n#\n# By default normal clients are not limited because they don&#39;t receive data\n# without asking (in a push way), but just after a request, so only\n# asynchronous clients may create a scenario where data is requested faster\n# than it can read.\n#\n# Instead there is a default limit for pubsub and replica clients, since\n# subscribers and replicas receive data in a push fashion.\n#\n# Both the hard or the soft limit can be disabled by setting them to zero.\nclient-output-buffer-limit normal 0 0 0\nclient-output-buffer-limit replica 256mb 64mb 60\nclient-output-buffer-limit pubsub 32mb 8mb 60\n\n# Client query buffers accumulate new commands. They are limited to a fixed\n# amount by default in order to avoid that a protocol desynchronization (for\n# instance due to a bug in the client) will lead to unbound memory usage in\n# the query buffer. However you can configure it here if you have very special\n# needs, such us huge multi&#x2F;exec requests or alike.\n#\n# client-query-buffer-limit 1gb\n\n# In the Redis protocol, bulk requests, that are, elements representing single\n# strings, are normally limited to 512 mb. However you can change this limit\n# here, but must be 1mb or greater\n#\n# proto-max-bulk-len 512mb\n\n# Redis calls an internal function to perform many background tasks, like\n# closing connections of clients in timeout, purging expired keys that are\n# never requested, and so forth.\n#\n# Not all tasks are performed with the same frequency, but Redis checks for\n# tasks to perform according to the specified &quot;hz&quot; value.\n#\n# By default &quot;hz&quot; is set to 10. Raising the value will use more CPU when\n# Redis is idle, but at the same time will make Redis more responsive when\n# there are many keys expiring at the same time, and timeouts may be\n# handled with more precision.\n#\n# The range is between 1 and 500, however a value over 100 is usually not\n# a good idea. Most users should use the default of 10 and raise this up to\n# 100 only in environments where very low latency is required.\nhz 10\n\n# Normally it is useful to have an HZ value which is proportional to the\n# number of clients connected. This is useful in order, for instance, to\n# avoid too many clients are processed for each background task invocation\n# in order to avoid latency spikes.\n#\n# Since the default HZ value by default is conservatively set to 10, Redis\n# offers, and enables by default, the ability to use an adaptive HZ value\n# which will temporarily raise when there are many connected clients.\n#\n# When dynamic HZ is enabled, the actual configured HZ will be used\n# as a baseline, but multiples of the configured HZ value will be actually\n# used as needed once more clients are connected. In this way an idle\n# instance will use very little CPU time while a busy instance will be\n# more responsive.\ndynamic-hz yes\n\n# When a child rewrites the AOF file, if the following option is enabled\n# the file will be fsync-ed every 32 MB of data generated. This is useful\n# in order to commit the file to the disk more incrementally and avoid\n# big latency spikes.\naof-rewrite-incremental-fsync yes\n\n# When redis saves RDB file, if the following option is enabled\n# the file will be fsync-ed every 32 MB of data generated. This is useful\n# in order to commit the file to the disk more incrementally and avoid\n# big latency spikes.\nrdb-save-incremental-fsync yes\n\n# Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good\n# idea to start with the default settings and only change them after investigating\n# how to improve the performances and how the keys LFU change over time, which\n# is possible to inspect via the OBJECT FREQ command.\n#\n# There are two tunable parameters in the Redis LFU implementation: the\n# counter logarithm factor and the counter decay time. It is important to\n# understand what the two parameters mean before changing them.\n#\n# The LFU counter is just 8 bits per key, it&#39;s maximum value is 255, so Redis\n# uses a probabilistic increment with logarithmic behavior. Given the value\n# of the old counter, when a key is accessed, the counter is incremented in\n# this way:\n#\n# 1. A random number R between 0 and 1 is extracted.\n# 2. A probability P is calculated as 1&#x2F;(old_value*lfu_log_factor+1).\n# 3. The counter is incremented only if R &lt; P.\n#\n# The default lfu-log-factor is 10. This is a table of how the frequency\n# counter changes with a different number of accesses with different\n# logarithmic factors:\n#\n# +--------+------------+------------+------------+------------+------------+\n# | factor | 100 hits | 1000 hits | 100K hits | 1M hits | 10M hits |\n# +--------+------------+------------+------------+------------+------------+\n# | 0 | 104 | 255 | 255 | 255 | 255 |\n# +--------+------------+------------+------------+------------+------------+\n# | 1 | 18 | 49 | 255 | 255 | 255 |\n# +--------+------------+------------+------------+------------+------------+\n# | 10 | 10 | 18 | 142 | 255 | 255 |\n# +--------+------------+------------+------------+------------+------------+\n# | 100 | 8 | 11 | 49 | 143 | 255 |\n# +--------+------------+------------+------------+------------+------------+\n#\n# NOTE: The above table was obtained by running the following commands:\n#\n# redis-benchmark -n 1000000 incr foo\n# redis-cli object freq foo\n#\n# NOTE 2: The counter initial value is 5 in order to give new objects a chance\n# to accumulate hits.\n#\n# The counter decay time is the time, in minutes, that must elapse in order\n# for the key counter to be divided by two (or decremented if it has a value\n# less &lt;&#x3D; 10).\n#\n# The default value for the lfu-decay-time is 1. A special value of 0 means to\n# decay the counter every time it happens to be scanned.\n#\n# lfu-log-factor 10\n# lfu-decay-time 1\n\n########################### ACTIVE DEFRAGMENTATION #######################\n#\n# What is active defragmentation?\n# -------------------------------\n#\n# Active (online) defragmentation allows a Redis server to compact the\n# spaces left between small allocations and deallocations of data in memory,\n# thus allowing to reclaim back memory.\n#\n# Fragmentation is a natural process that happens with every allocator (but\n# less so with Jemalloc, fortunately) and certain workloads. Normally a server\n# restart is needed in order to lower the fragmentation, or at least to flush\n# away all the data and create it again. However thanks to this feature\n# implemented by Oran Agra for Redis 4.0 this process can happen at runtime\n# in a &quot;hot&quot; way, while the server is running.\n#\n# Basically when the fragmentation is over a certain level (see the\n# configuration options below) Redis will start to create new copies of the\n# values in contiguous memory regions by exploiting certain specific Jemalloc\n# features (in order to understand if an allocation is causing fragmentation\n# and to allocate it in a better place), and at the same time, will release the\n# old copies of the data. This process, repeated incrementally for all the keys\n# will cause the fragmentation to drop back to normal values.\n#\n# Important things to understand:\n#\n# 1. This feature is disabled by default, and only works if you compiled Redis\n# to use the copy of Jemalloc we ship with the source code of Redis.\n# This is the default with Linux builds.\n#\n# 2. You never need to enable this feature if you don&#39;t have fragmentation\n# issues.\n#\n# 3. Once you experience fragmentation, you can enable this feature when\n# needed with the command &quot;CONFIG SET activedefrag yes&quot;.\n#\n# The configuration parameters are able to fine tune the behavior of the\n# defragmentation process. If you are not sure about what they mean it is\n# a good idea to leave the defaults untouched.\n\n# Enabled active defragmentation\n# activedefrag no\n\n# Minimum amount of fragmentation waste to start active defrag\n# active-defrag-ignore-bytes 100mb\n\n# Minimum percentage of fragmentation to start active defrag\n# active-defrag-threshold-lower 10\n\n# Maximum percentage of fragmentation at which we use maximum effort\n# active-defrag-threshold-upper 100\n\n# Minimal effort for defrag in CPU percentage, to be used when the lower\n# threshold is reached\n# active-defrag-cycle-min 1\n\n# Maximal effort for defrag in CPU percentage, to be used when the upper\n# threshold is reached\n# active-defrag-cycle-max 25\n\n# Maximum number of set&#x2F;hash&#x2F;zset&#x2F;list fields that will be processed from\n# the main dictionary scan\n# active-defrag-max-scan-fields 1000\n\n# Jemalloc background thread for purging will be enabled by default\njemalloc-bg-thread yes\n\n# It is possible to pin different threads and processes of Redis to specific\n# CPUs in your system, in order to maximize the performances of the server.\n# This is useful both in order to pin different Redis threads in different\n# CPUs, but also in order to make sure that multiple Redis instances running\n# in the same host will be pinned to different CPUs.\n#\n# Normally you can do this using the &quot;taskset&quot; command, however it is also\n# possible to this via Redis configuration directly, both in Linux and FreeBSD.\n#\n# You can pin the server&#x2F;IO threads, bio threads, aof rewrite child process, and\n# the bgsave child process. The syntax to specify the cpu list is the same as\n# the taskset command:\n#\n# Set redis server&#x2F;io threads to cpu affinity 0,2,4,6:\n# server_cpulist 0-7:2\n#\n# Set bio threads to cpu affinity 1,3:\n# bio_cpulist 1,3\n#\n# Set aof rewrite child process to cpu affinity 8,9,10,11:\n# aof_rewrite_cpulist 8-11\n#\n# Set bgsave child process to cpu affinity 1,10,11\n# bgsave_cpulist 1,10-11\n\n# In some cases redis will emit warnings and even refuse to start if it detects\n# that the system is in bad state, it is possible to suppress these warnings\n# by setting the following config which takes a space delimited list of warnings\n# to suppress\n#\n# ignore-warnings ARM64-COW-BUG</code></pre>\n<h1 id=\"5、启动Redis容器\"><a href=\"#5、启动Redis容器\" class=\"headerlink\" title=\"5、启动Redis容器\"></a>5、启动Redis容器</h1><p>执行命令启动redis容器</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker-compose up -d</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iRedisByDC/2022-04-24-17-10-52-image.png\" alt=\"\"></p>\n<h1 id=\"6、远程连接验证结果\"><a href=\"#6、远程连接验证结果\" class=\"headerlink\" title=\"6、远程连接验证结果\"></a>6、远程连接验证结果</h1><p>信息填完点击OK</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iRedisByDC/2022-04-24-17-12-56-image.png\" alt=\"\"></p>\n<p>点击左侧对呀的连接右侧出现redis服务器信息则为安装成功</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iRedisByDC/2022-04-24-17-14-15-image.png\" alt=\"\"></p>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"docker-compose安装MySQL","slug":"iMySQLByDC","date":"2022-04-24T07:57:49.000Z","updated":"2022-09-22T07:39:52.893Z","comments":true,"path":"/post/iMySQLByDC/","link":"","excerpt":"","content":"<p>docker中安装MySQL</p>\n<p>本教程以MySQL5.7版本为例编写如需其他版本可自行前往docker hub网站查找对应的镜像安装可能回和本教程有一定出入清自行处理。<br>如遇问题也可以在评论中回复,本人会尽快给与回复</p>\n<h1 id=\"1、拉取镜像\"><a href=\"#1、拉取镜像\" class=\"headerlink\" title=\"1、拉取镜像\"></a>1、拉取镜像</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull mysql:5.7</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iMySQLByDC/img.png\" alt=\"img.png\"></p>\n<h1 id=\"2、编写docker-compose-yml文件\"><a href=\"#2、编写docker-compose-yml文件\" class=\"headerlink\" title=\"2、编写docker-compose.yml文件\"></a>2、编写docker-compose.yml文件</h1><p>内容如下:</p>\n<pre class=\"line-numbers language-yaml\" data-language=\"yaml\"><code class=\"language-yaml\">version: &#39;3&#39;\nservices:\n mysql:\n container_name: mysql\n image: mysql:5.7\n environment:\n - MYSQL_ROOT_PASSWORD&#x3D;此处为root密码自行设置\n - TZ&#x3D;Asia&#x2F;Shanghai\n volumes: \n - .&#x2F;conf:&#x2F;etc&#x2F;mysql\n - .&#x2F;data:&#x2F;var&#x2F;lib&#x2F;mysql\n - .&#x2F;init:&#x2F;docker-entrypoint-initdb.d&#x2F;\n ports: \n - 50010:3306\n restart: always</code></pre>\n<h1 id=\"3、创建目录文件\"><a href=\"#3、创建目录文件\" class=\"headerlink\" title=\"3、创建目录文件\"></a>3、创建目录文件</h1><p>根据docker-compose.yml文件创建对应目录文件</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iMySQLByDC/2022-04-24-16-20-33-image.png\" alt=\"\"></p>\n<h1 id=\"4、编写MySQL的配置文件\"><a href=\"#4、编写MySQL的配置文件\" class=\"headerlink\" title=\"4、编写MySQL的配置文件\"></a>4、编写MySQL的配置文件</h1><p>在conf目录下创建my.cnf文件文件内容如下</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">[mysqld]\nlower_case_table_names&#x3D;1\ninnodb_force_recovery &#x3D; 0\n\nlog-bin&#x3D;&#x2F;var&#x2F;lib&#x2F;mysql&#x2F;mysql-bin\nbinlog-format&#x3D;ROW\nserver_id&#x3D;1</code></pre>\n<h1 id=\"5、启动MySQL容器\"><a href=\"#5、启动MySQL容器\" class=\"headerlink\" title=\"5、启动MySQL容器\"></a>5、启动MySQL容器</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker-compose up -d</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iMySQLByDC/2022-04-24-16-30-32-image.png\" alt=\"\"></p>\n<h1 id=\"6、远程连接验证结果\"><a href=\"#6、远程连接验证结果\" class=\"headerlink\" title=\"6、远程连接验证结果\"></a>6、远程连接验证结果</h1><p><img src=\"https://img.huangge1199.cn/blog/iMySQLByDC/2022-04-24-16-45-29-image.png\" alt=\"\"></p>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"}]},{"title":"用docker-compose安装nginx","slug":"iNginxByDC","date":"2022-04-24T07:36:52.000Z","updated":"2022-09-22T07:39:52.901Z","comments":true,"path":"/post/iNginxByDC/","link":"","excerpt":"","content":"<p>docker中安装nginx</p>\n<h1 id=\"1、查找nginx镜像\"><a href=\"#1、查找nginx镜像\" class=\"headerlink\" title=\"1、查找nginx镜像\"></a>1、查找nginx镜像</h1><p>通过<a href=\"https://hub.docker.com/\">Docker Hub网站查询nginx镜像</a>,选择下面的官方镜像</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-00-46-47-image.png\" alt=\"\"></p>\n<h1 id=\"2、下载镜像\"><a href=\"#2、下载镜像\" class=\"headerlink\" title=\"2、下载镜像\"></a>2、下载镜像</h1><p>3.1页面点进去后在右上方有docker拉取命令</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-00-47-51-image.png\" alt=\"\"></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull nginx</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-01-03-03-image.png\" alt=\"\"></p>\n<h1 id=\"3、编写docker-compose-yml\"><a href=\"#3、编写docker-compose-yml\" class=\"headerlink\" title=\"3、编写docker-compose.yml\"></a>3、编写docker-compose.yml</h1><p>docker-compose.yml内容如下</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">version: &#39;3&#39;\nservices:\n nginx: \n container_name: nginx #生成的容器名\n image: nginx:latest #镜像\n environment:\n - TZ&#x3D;Asia&#x2F;Shanghai #时间\n volumes: \n - .&#x2F;html:&#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html #nginx静态页位置\n - .&#x2F;conf&#x2F;nginx.conf:&#x2F;etc&#x2F;nginx&#x2F;nginx.conf #配置文件\n - .&#x2F;conf.d:&#x2F;etc&#x2F;nginx&#x2F;conf.d #配置文件\n - .&#x2F;logs:&#x2F;var&#x2F;log&#x2F;nginx #日志\n ports: \n - 80:80\n - 443:443\n restart: always</code></pre>\n<h1 id=\"4、创建目录以及nginx配置文件\"><a href=\"#4、创建目录以及nginx配置文件\" class=\"headerlink\" title=\"4、创建目录以及nginx配置文件\"></a>4、创建目录以及nginx配置文件</h1><p>根据docker-compose.yml建立文件目录并编写相关文件</p>\n<p>目录:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-20-43-55-image.png\" alt=\"\"></p>\n<p>conf/nginx.conf</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">user nginx;\nworker_processes auto;\n\nerror_log &#x2F;var&#x2F;log&#x2F;nginx&#x2F;error.log notice;\npid &#x2F;var&#x2F;run&#x2F;nginx.pid;\n\n\nevents &#123;\n worker_connections 1024;\n&#125;\n\n\nhttp &#123;\n include &#x2F;etc&#x2F;nginx&#x2F;mime.types;\n default_type application&#x2F;octet-stream;\n\n log_format main &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;\n &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;\n &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;\n\n access_log &#x2F;var&#x2F;log&#x2F;nginx&#x2F;access.log main;\n\n sendfile on;\n #tcp_nopush on;\n\n keepalive_timeout 65;\n\n #gzip on;\n\n include &#x2F;etc&#x2F;nginx&#x2F;conf.d&#x2F;*.conf;\n&#125;</code></pre>\n<p>conf.d/default.conf</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">server &#123;\n listen 80;\n listen [::]:80;\n server_name localhost;\n\n #access_log &#x2F;var&#x2F;log&#x2F;nginx&#x2F;host.access.log main;\n\n location &#x2F; &#123;\n root &#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html;\n index index.html index.htm;\n &#125;\n\n #error_page 404 &#x2F;404.html;\n\n # redirect server error pages to the static page &#x2F;50x.html\n #\n error_page 500 502 503 504 &#x2F;50x.html;\n location &#x3D; &#x2F;50x.html &#123;\n root &#x2F;usr&#x2F;share&#x2F;nginx&#x2F;html;\n &#125;\n\n # proxy the PHP scripts to Apache listening on 127.0.0.1:80\n #\n #location ~ \\.php$ &#123;\n # proxy_pass http:&#x2F;&#x2F;127.0.0.1;\n #&#125;\n\n # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n #\n #location ~ \\.php$ &#123;\n # root html;\n # fastcgi_pass 127.0.0.1:9000;\n # fastcgi_index index.php;\n # fastcgi_param SCRIPT_FILENAME &#x2F;scripts$fastcgi_script_name;\n # include fastcgi_params;\n #&#125;\n\n # deny access to .htaccess files, if Apache&#39;s document root\n # concurs with nginx&#39;s one\n #\n #location ~ &#x2F;\\.ht &#123;\n # deny all;\n #&#125;\n&#125;</code></pre>\n<p>html/50x.html</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Error&lt;&#x2F;title&gt;\n&lt;style&gt;\nhtml &#123; color-scheme: light dark; &#125;\nbody &#123; width: 35em; margin: 0 auto;\nfont-family: Tahoma, Verdana, Arial, sans-serif; &#125;\n&lt;&#x2F;style&gt;\n&lt;&#x2F;head&gt;\n&lt;body&gt;\n&lt;h1&gt;An error occurred.&lt;&#x2F;h1&gt;\n&lt;p&gt;Sorry, the page you are looking for is currently unavailable.&lt;br&#x2F;&gt;\nPlease try again later.&lt;&#x2F;p&gt;\n&lt;p&gt;If you are the system administrator of this resource then you should check\nthe error log for details.&lt;&#x2F;p&gt;\n&lt;p&gt;&lt;em&gt;Faithfully yours, nginx.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;\n&lt;&#x2F;body&gt;\n&lt;&#x2F;html&gt;</code></pre>\n<p>html/index.html</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Welcome to nginx!&lt;&#x2F;title&gt;\n&lt;style&gt;\nhtml &#123; color-scheme: light dark; &#125;\nbody &#123; width: 35em; margin: 0 auto;\nfont-family: Tahoma, Verdana, Arial, sans-serif; &#125;\n&lt;&#x2F;style&gt;\n&lt;&#x2F;head&gt;\n&lt;body&gt;\n&lt;h1&gt;Welcome to nginx!&lt;&#x2F;h1&gt;\n&lt;p&gt;If you see this page, the nginx web server is successfully installed and\nworking. Further configuration is required.&lt;&#x2F;p&gt;\n\n&lt;p&gt;For online documentation and support please refer to\n&lt;a href&#x3D;&quot;http:&#x2F;&#x2F;nginx.org&#x2F;&quot;&gt;nginx.org&lt;&#x2F;a&gt;.&lt;br&#x2F;&gt;\nCommercial support is available at\n&lt;a href&#x3D;&quot;http:&#x2F;&#x2F;nginx.com&#x2F;&quot;&gt;nginx.com&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;\n\n&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;\n&lt;&#x2F;body&gt;\n&lt;&#x2F;html&gt;</code></pre>\n<h1 id=\"5、docker-compose启动nginx\"><a href=\"#5、docker-compose启动nginx\" class=\"headerlink\" title=\"5、docker-compose启动nginx\"></a>5、docker-compose启动nginx</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">cd nginx&#x2F;\nll\ndocker-compose up -d</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-19-59-02-image.png\" alt=\"\"></p>\n<h1 id=\"6、验证nginx正常启动\"><a href=\"#6、验证nginx正常启动\" class=\"headerlink\" title=\"6、验证nginx正常启动\"></a>6、验证nginx正常启动</h1><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker ps -a</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-21-20-12-55-image.png\" alt=\"\"></p>\n<p>然后在浏览器中输入IP出现欢迎界面安装完成</p>\n<p><img src=\"https://img.huangge1199.cn/blog/iNginxByDC/2022-04-24-15-34-45-image.png\" alt=\"\"></p>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"docker-compose安装","slug":"dockerComposeInstall","date":"2022-04-24T07:12:03.000Z","updated":"2022-09-22T07:39:52.867Z","comments":true,"path":"/post/dockerComposeInstall/","link":"","excerpt":"","content":"<p>docker-compose安装</p>\n<p>按照官方来即可,<a href=\"https://docs.docker.com/compose/install/\">docker-compose安装文档</a></p>\n<p>按照自己的系统来安装:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerComposeInstall/2022-04-21-00-36-46-image.png\" alt=\"\"></p>\n<h1 id=\"1、下载docker-compose\"><a href=\"#1、下载docker-compose\" class=\"headerlink\" title=\"1、下载docker-compose\"></a>1、下载docker-compose</h1><p>下面两个二选一,建议国内源,速度快</p>\n<p>官方:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo curl -L &quot;https:&#x2F;&#x2F;github.com&#x2F;docker&#x2F;compose&#x2F;releases&#x2F;download&#x2F;1.29.2&#x2F;docker-compose-$(uname -s)-$(uname -m)&quot; -o &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose</code></pre>\n<p>国内源:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">curl -L https:&#x2F;&#x2F;get.daocloud.io&#x2F;docker&#x2F;compose&#x2F;releases&#x2F;download&#x2F;1.29.2&#x2F;docker-compose-&#96;uname -s&#96;-&#96;uname -m&#96; &gt; &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerComposeInstall/2022-04-21-00-40-56-image.png\" alt=\"\"></p>\n<h1 id=\"2、授予权限\"><a href=\"#2、授予权限\" class=\"headerlink\" title=\"2、授予权限\"></a>2、授予权限</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">sudo chmod +x &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose\nsudo ln -s &#x2F;usr&#x2F;local&#x2F;bin&#x2F;docker-compose &#x2F;usr&#x2F;bin&#x2F;docker-compose</code></pre>\n<h1 id=\"3、验证\"><a href=\"#3、验证\" class=\"headerlink\" title=\"3、验证\"></a>3、验证</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker-compose --version</code></pre>\n<p>输入命令后,出现版本号,则为安装成功</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerComposeInstall/2022-04-21-00-44-14-image.png\" alt=\"\"></p>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"}]},{"title":"docker安装","slug":"dockerInstall","date":"2022-04-24T05:59:34.000Z","updated":"2022-09-22T07:39:52.872Z","comments":true,"path":"/post/dockerInstall/","link":"","excerpt":"","content":"<p>安装docker</p>\n<p>这部分基本就是按照docker官网的来<a href=\"https://docs.docker.com/engine/install/centos/\">centos安装docker文档</a></p>\n<h1 id=\"1、卸载旧版本docker\"><a href=\"#1、卸载旧版本docker\" class=\"headerlink\" title=\"1、卸载旧版本docker\"></a>1、卸载旧版本docker</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">yum remove docker \\\n docker-client \\\n docker-client-latest \\\n docker-common \\\n docker-latest \\\n docker-latest-logrotate \\\n docker-logrotate \\\n docker-engine</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-20-23-44-07-image.png\" alt=\"\"></p>\n<h1 id=\"2、设置docker软件源\"><a href=\"#2、设置docker软件源\" class=\"headerlink\" title=\"2、设置docker软件源\"></a>2、设置docker软件源</h1><p>下面官网软件源和阿里软件源二选一,个人建议用阿里的,国内的速度快</p>\n<p>官网软件源 :速度慢,可以考虑阿里的</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">yum install -y yum-utils\nyum-config-manager \\\n --add-repo \\\n https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-20-23-47-39-image.png\" alt=\"\"></p>\n<p>阿里软件源:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-21-00-00-59-image.png\" alt=\"\"></p>\n<h1 id=\"3、安装docker\"><a href=\"#3、安装docker\" class=\"headerlink\" title=\"3、安装docker\"></a>3、安装docker</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">yum install docker-ce docker-ce-cli containerd.io</code></pre>\n<p>命令输入后,中途出现下面的内容,输入<code>y</code>,然后按回车确认</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-20-23-50-06-image.png\" alt=\"\"></p>\n<p>中途出现下面的内容,输入<code>y</code>,然后按回车确认</p>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-21-00-05-16-image.png\" alt=\"\"></p>\n<h1 id=\"4、更改docker仓库地址用Docker中国区官方替换掉要不之后拉取镜像速度太慢了\"><a href=\"#4、更改docker仓库地址用Docker中国区官方替换掉要不之后拉取镜像速度太慢了\" class=\"headerlink\" title=\"4、更改docker仓库地址用Docker中国区官方替换掉要不之后拉取镜像速度太慢了\"></a>4、更改docker仓库地址用Docker中国区官方替换掉要不之后拉取镜像速度太慢了</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi &#x2F;etc&#x2F;docker&#x2F;daemon.json</code></pre>\n<p>daemon.json内容</p>\n<pre class=\"line-numbers language-json\" data-language=\"json\"><code class=\"language-json\">&#123;\n &quot;registry-mirrors&quot;: [&quot;https:&#x2F;&#x2F;registry.docker-cn.com&quot;]\n&#125;</code></pre>\n<h1 id=\"5、启动docker\"><a href=\"#5、启动docker\" class=\"headerlink\" title=\"5、启动docker\"></a>5、启动docker</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">systemctl start docker</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-21-00-22-21-image.png\" alt=\"\"></p>\n<h1 id=\"6、设置开机启动docker\"><a href=\"#6、设置开机启动docker\" class=\"headerlink\" title=\"6、设置开机启动docker\"></a>6、设置开机启动docker</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">systemctl enable docker</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/dockerInstall/2022-04-21-00-22-43-image.png\" alt=\"\"></p>\n<h1 id=\"7、验证\"><a href=\"#7、验证\" class=\"headerlink\" title=\"7、验证\"></a>7、验证</h1><p>通过查询docker版本确认docker是否正常启动</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker -v</code></pre>\n<p>执行命令后正常显示docker版本则为安装启动成功</p>\n","categories":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"}],"tags":[{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"}]},{"title":"力扣459:重复的子字符串","slug":"repeatedSubstringPattern","date":"2022-04-18T07:53:15.000Z","updated":"2024-04-25T08:10:09.106Z","comments":true,"path":"/post/repeatedSubstringPattern/","link":"","excerpt":"","content":"<p>今天刷力扣发现一道有趣的题,这道题目很普通,但是解法确可以偷懒</p>\n<p>原题链接:<a href=\"https://leetcode-cn.com/problems/repeated-substring-pattern/\">力扣459:重复的子字符串</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个非空的字符串<meta charset=\"UTF-8\" />&nbsp;<code>s</code>&nbsp;,检查是否可以通过由它的一个子串重复多次构成。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> s = \"abab\"\n<strong>输出:</strong> true\n<strong>解释:</strong> 可由子串 \"ab\" 重复两次构成。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> s = \"aba\"\n<strong>输出:</strong> false\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong> s = \"abcabcabcabc\"\n<strong>输出:</strong> true\n<strong>解释:</strong> 可由子串 \"abc\" 重复四次构成。 (或子串 \"abcabc\" 重复两次构成。)\n</pre>\n\n<p>&nbsp;</p>\n\n<p><b>提示:</b></p>\n\n<p><meta charset=\"UTF-8\" /></p>\n\n<p><ul>\n <li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>\n <li><code>s</code>&nbsp;由小写英文字母组成</li>\n</ul></p>\n<div><div>Related Topics</div><div><li>字符串</li><li>字符串匹配</li></div></div><br>\n\n# 个人解法\n\n想法既然要判断字符串是否由一个子串重复多次构成那么如果结果是肯定的这个字符串的长\n度一定能够整除子串的长度。\n\n所以我首先做一个循环找到可能作为子串重复的字符串在其基础上判断是否满足循环结束\n后都没有找到满足的那么结果肯定就是false了。\n\n接下来我们考虑循环内部的逻辑如果一个子串可以满足子串重复多次组成当前的字符串那么按\n照子串的长度分割每一部分都是相同的。接下来就是重点了重点怎么判断这些部分\n都相同\n\n<div style=\"color: red\">\n假设满足条件<br/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s = \"abdfs\"<br/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent = s1+s2+s3+s4+....sns1...sn都是s<br/>\n根据上面的字符串以及子串作说明<br/>\n可以分为两步判断\n<ol style=\"color: green\">\n<li>s1和sn相同</li>\n<li>s2s3s4...sn和s1s2s3....s(n-1)相同</li>\n</ol>\n2中s2=s1s3=s2.....sn=s(n-1)这样一来s1,s2,s3....sn就都相同了\n</div>\n\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean repeatedSubstringPattern(String s) &#123;\n int lens &#x3D; s.length();\n for (int i &#x3D; 1; i &lt; lens; i++) &#123;\n if (lens % i &#x3D;&#x3D; 0) &#123;\n if (s.substring(0, i).equals(s.substring(lens - i))\n &amp;&amp; s.substring(i).equals(s.substring(0, lens - i))) &#123;\n return true;\n &#125;\n &#125;\n &#125;\n return false;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def repeatedSubstringPattern(self, s: str) -&gt; bool:\n for i in range(1, len(s)):\n if len(s) % i &#x3D;&#x3D; 0:\n if s[0:i] &#x3D;&#x3D; s[len(s)-i:len(s)] and s[0:len(s)-i] &#x3D;&#x3D; s[i:len(s)]:\n return True\n return False</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣204:计数质数","slug":"leetcode204","date":"2022-04-12T03:04:35.000Z","updated":"2022-09-22T07:39:53.089Z","comments":true,"path":"/post/leetcode204/","link":"","excerpt":"","content":"<p>今天遇到一个有趣的题目,求小于给定非负整数的质数的数量</p>\n<p>原题链接:<a href=\"https://leetcode-cn.com/problems/count-primes/\">力扣204. 计数质数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定整数 <code>n</code> ,返回 <em>所有小于非负整数 <code>n</code> 的质数的数量</em> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 10\n<strong>输出:</strong>4\n<strong>解释:</strong>小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 0\n<strong>输出:</strong>0\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 1\n<strong>输出</strong>0\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>0 <= n <= 5 * 10<sup>6</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>数学</li><li>枚举</li><li>数论</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>思路:</p>\n<p>这题我最开始想的比较简单直接从0开始遍历到给定数字遍历过程中判断是否是质数</p>\n<p>java代码如下</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countPrimes(int n) &#123;\n if (n &lt;&#x3D; 2) &#123;\n return 0;\n &#125;\n int count &#x3D; 1;\n for (int i &#x3D; 3; i &lt; n; i++) &#123;\n if (isPrime(i)) &#123;\n count++;\n &#125;\n &#125;\n return count;\n &#125;\n &#x2F;**\n * 判断是否是质数\n *\n * @param num 数字\n * @return true质数、false不是质数\n *&#x2F;\n private boolean isPrime(int num) &#123;\n if (num &lt; 2) &#123;\n return false;\n &#125;\n if (num &#x3D;&#x3D; 2) &#123;\n return true;\n &#125;\n for (int i &#x3D; 2; i * i &lt;&#x3D; num; i++) &#123;\n if (num % i &#x3D;&#x3D; 0) &#123;\n return false;\n &#125;\n &#125;\n return true;\n &#125;\n&#125;</code></pre>\n<p>这种办法虽然例子过了,但是最后提交时却是超时了</p>\n<p>接下来,我又仔细的想了想,之后想到了一种办法,通过了,然后看了看题解,发现这完全就是埃拉托斯特<br>尼筛法,简称埃氏筛,也称素数筛,是一种简单且历史悠久的筛法,用来找出一定范围内所有的素数。</p>\n<p>这种算法就是给出要筛数值的范围n从2开始遍历直到 $\\sqrt{2}$ 。从2开始把小于n并且是其倍数的标记上<br>然后按顺序是3和2一样的步骤不过要判断下是否被标记过因为被标记的不是质数</p>\n<p>我在维基百科上看到了这个小动画,就是这个算法的整体步骤了</p>\n<iframe frameborder=0 border=0 height=369 width=445 src=\"https://img.huangge1199.cn/blog/leetcode204/Sieve_of_Eratosthenes_animation.gif\"></iframe>\n\n<p>下面是我的java代码</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countPrimes(int n) &#123;\n if (n &lt;&#x3D; 2) &#123;\n return 0;\n &#125;\n boolean[] nums &#x3D; new boolean[n + 1];\n Arrays.fill(nums, true);\n nums[0] &#x3D; false;\n nums[1] &#x3D; false;\n int count &#x3D; 0;\n int max &#x3D; (int) Math.sqrt(n);\n for (int i &#x3D; 2; i &lt; n; i++) &#123;\n if (nums[i]) &#123;\n count++;\n if (i &gt; max) &#123;\n continue;\n &#125;\n for (int j &#x3D; i; j * i &lt; n; j++) &#123;\n nums[j * i] &#x3D; false;\n &#125;\n &#125;\n &#125;\n return count;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣357:统计各位数字都不同的数字个数","slug":"day20220411","date":"2022-04-11T06:54:43.000Z","updated":"2024-04-25T08:10:09.101Z","comments":true,"path":"/post/day20220411/","link":"","excerpt":"","content":"<p>2022年04月11日 力扣每日一题 </p>\n<p><a href=\"https://leetcode-cn.com/problems/count-numbers-with-unique-digits/\">357:统计各位数字都不同的数字个数</a></p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个整数 <code>n</code> ,统计并返回各位数字都不同的数字 <code>x</code> 的个数,其中 <code>0 &lt;= x &lt; 10<sup>n</sup></code><sup>&nbsp;</sup>。</p>\n<div class=\"original__bRMd\">\n<div>\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 2\n<strong>输出:</strong>91\n<strong>解释:</strong>答案应为除去 <code>11、22、33、44、55、66、77、88、99 </code>外,在 0 ≤ x < 100 范围内的所有数字。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 0\n<strong>输出:</strong>1\n</pre>\n\n</div>\n</div>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>0 <= n <= 8</code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数学</li><li>动态规划</li><li>回溯</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>思路:</p>\n<p>今天这题在我看来就是一个排列组合的问题,首先我们先考虑下边界,</p>\n<ul>\n<li><p>n == 0 时只有一种结果0</p>\n</li>\n<li><p>n == 1 时0~9共10种情况</p>\n</li>\n<li><p>其他值由两部分组成满位的数即首位不为0以及比它少一位的全部情况</p>\n<ul>\n<li>考虑到首位不能为0因此首位只能是1~9</li>\n<li>接下来的位置与前面的数字不能重复但是可以为0</li>\n</ul>\n<p>总体来说首位不为0的情况个数是<code>9*9*8*。。。。</code></p>\n</li>\n</ul>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countNumbersWithUniqueDigits(int n) &#123;\n if (n &#x3D;&#x3D; 0) &#123;\n return 1;\n &#125;\n if (n &#x3D;&#x3D; 1) &#123;\n return 10;\n &#125;\n int sub &#x3D; 9;\n int count &#x3D; 10;\n int mul &#x3D; 9;\n for (int i &#x3D; 2; i &lt;&#x3D; n; i++) &#123;\n count +&#x3D; mul * sub;\n mul *&#x3D; sub;\n sub--;\n &#125;\n return count;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def countNumbersWithUniqueDigits(self, n: int) -&gt; int:\n if n &#x3D;&#x3D; 0:\n return 1\n if n &#x3D;&#x3D; 1:\n return 10\n sub &#x3D; 9\n count &#x3D; 10\n mul &#x3D; 9\n for i in range(2, n + 1):\n count +&#x3D; mul * sub\n mul *&#x3D; sub\n sub -&#x3D; 1\n return count</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"darwin是什么","slug":"darwin","date":"2022-03-30T01:16:32.000Z","updated":"2022-09-22T07:39:52.829Z","comments":true,"path":"/post/darwin/","link":"","excerpt":"","content":"<p>今天在学习NPS时看到服务端启动命令时它的分类是linux|darwin和windows两种之前没有见过darwin实在是好奇。<br>通过网络的查找,学习到了以下知识:</p>\n<ul>\n<li>Darwin 是一个由苹果公司Apple Inc.)开发的 UNIX 操作系统</li>\n<li>自2000年后Darwin 是苹果所有操作系统的基础,包括 macOS原名 Mac OS X ,后缩写为 OS X至 WWDC 2016 改名为 macOS、iOS、watchOS 和 tvOS。</li>\n<li>Darwin是xnu架构的实现基本可以视作Mac的命令行部分。而xnu是乔布斯结合mach和bsd做出来的操作系统架构是他被踢出苹果自己开next公司时发明的当时叫nextstep后来被买回苹果</li>\n</ul>\n","categories":[{"name":"it百科","slug":"it百科","permalink":"https://hexo.huangge1199.cn/categories/it%E7%99%BE%E7%A7%91/"}],"tags":[{"name":"it百科","slug":"it百科","permalink":"https://hexo.huangge1199.cn/tags/it%E7%99%BE%E7%A7%91/"}]},{"title":"Autowired注解警告的解决办法","slug":"autowiredWaring","date":"2022-03-28T03:20:43.000Z","updated":"2022-09-22T07:39:52.763Z","comments":true,"path":"/post/autowiredWaring/","link":"","excerpt":"","content":"<h1 id=\"AutoWired-在idea报警告\"><a href=\"#AutoWired-在idea报警告\" class=\"headerlink\" title=\"@AutoWired 在idea报警告\"></a>@AutoWired 在idea报警告</h1><p>近期,发现@AutoWired注解在idea中总是报警告</p>\n<h2 id=\"java代码\"><a href=\"#java代码\" class=\"headerlink\" title=\"java代码\"></a>java代码</h2><p>如下:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\npublic class UserController &#123;\n\n @Autowired\n private UserService userService;\n\n&#125;</code></pre>\n<h2 id=\"警告内容\"><a href=\"#警告内容\" class=\"headerlink\" title=\"警告内容\"></a>警告内容</h2><p>如下:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/autowiredWaring/2022-03-28-11-30-49-1648438205(1\" alt=\"\">.png)</p>\n<h2 id=\"解决办法\"><a href=\"#解决办法\" class=\"headerlink\" title=\"解决办法\"></a>解决办法</h2><p>于是乎关联性的在网上找了找资料用以下的写法不会报警告同时这种写法也是spring官方推荐的写法代码如下</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\npublic class UserController &#123;\n\n private final UserService userService;\n\n public UserController(UserService userService)&#123;\n this.userService &#x3D; userService;\n &#125;\n\n&#125;</code></pre>\n<h2 id=\"Lombok优雅写法\"><a href=\"#Lombok优雅写法\" class=\"headerlink\" title=\"Lombok优雅写法\"></a>Lombok优雅写法</h2><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\n@RequiredArgsConstructor(onConstructor &#x3D; @__(@Autowired))\npublic clas UserController &#123;\n &#x2F;&#x2F;这里必须是final,若不使用final,用@NotNull注解也是可以的\n private final UserService userService;\n\n&#125;</code></pre>\n<h1 id=\"拓展学习\"><a href=\"#拓展学习\" class=\"headerlink\" title=\"拓展学习\"></a>拓展学习</h1><p>由此我这边拓展到了spring的三种依赖注入方式</p>\n<ul>\n<li><p>Field Injection</p>\n</li>\n<li><p>Constructor Injection</p>\n</li>\n<li><p>Setter Injection</p>\n</li>\n</ul>\n<h2 id=\"Field-Injection\"><a href=\"#Field-Injection\" class=\"headerlink\" title=\"Field Injection\"></a>Field Injection</h2><p><code>@Autowired</code>注解的一大使用场景就是<code>Field Injection</code>。</p>\n<p>具体形式如下:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\npublic class UserController &#123;\n\n @Autowired\n private UserService userService;\n\n&#125;</code></pre>\n<p>这种注入方式通过Java的反射机制实现所以private的成员也可以被注入具体的对象。</p>\n<h2 id=\"Constructor-Injection\"><a href=\"#Constructor-Injection\" class=\"headerlink\" title=\"Constructor Injection\"></a>Constructor Injection</h2><p><code>Constructor Injection</code>是构造器注入,是我们日常最为推荐的一种使用方式。</p>\n<p>具体形式如下:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\npublic class UserController &#123;\n\n private final UserService userService;\n\n public UserController(UserService userService)&#123;\n this.userService &#x3D; userService;\n &#125;\n\n&#125;</code></pre>\n<p>这种注入方式很直接通过对象构建的时候建立关系所以这种方式对对象创建的顺序会有要求当然Spring会为你搞定这样的先后顺序除非你出现循环依赖然后就会抛出异常。</p>\n<h2 id=\"Setter-Injection\"><a href=\"#Setter-Injection\" class=\"headerlink\" title=\"Setter Injection\"></a>Setter Injection</h2><p><code>Setter Injection</code>也会用到<code>@Autowired</code>注解,但使用方式与<code>Field Injection</code>有所不同,<code>Field Injection</code>是用在成员变量上,而<code>Setter Injection</code>的时候是用在成员变量的Setter函数上。</p>\n<p>具体形式如下:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">@Controller\npublic class UserController &#123;\n\n private UserService userService;\n\n @Autowired\n public void setUserService(UserService userService)&#123;\n this.userService &#x3D; userService;\n &#125;\n&#125;</code></pre>\n<p>这种注入方式也很好理解就是通过调用成员变量的set方法来注入想要使用的依赖对象。</p>\n<h2 id=\"三种依赖注入方式比较\"><a href=\"#三种依赖注入方式比较\" class=\"headerlink\" title=\"三种依赖注入方式比较\"></a>三种依赖注入方式比较</h2><div class=\"table-container\">\n<table>\n<thead>\n<tr>\n<th>注入方式</th>\n<th>可靠性</th>\n<th>可维护性</th>\n<th>可测试性</th>\n<th>灵活性</th>\n<th>循环关系的检测</th>\n<th>性能影响</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Field</td>\n<td>不可靠</td>\n<td>低</td>\n<td>差</td>\n<td>很灵活</td>\n<td>不检测</td>\n<td>启动快</td>\n</tr>\n<tr>\n<td>Constructor</td>\n<td>可靠</td>\n<td>高</td>\n<td>好</td>\n<td>不灵活</td>\n<td>自动检测</td>\n<td>启动慢</td>\n</tr>\n<tr>\n<td>Setter</td>\n<td>不可靠</td>\n<td>低</td>\n<td>好</td>\n<td>很灵活</td>\n<td>不检测</td>\n<td>启动快</td>\n</tr>\n</tbody>\n</table>\n</div>\n<h1 id=\"参考:\"><a href=\"#参考:\" class=\"headerlink\" title=\"参考:\"></a>参考:</h1><ol>\n<li><p><a href=\"https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-constructor-injection\">https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-constructor-injection</a></p>\n</li>\n<li><p><a href=\"https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-setter-injection\">https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-setter-injection</a></p>\n</li>\n<li><p><a href=\"https://blog.csdn.net/weixin_43203497/article/details/104193350\">利用Lombok编写优雅的spring依赖注入代码,去掉繁人的@Autowired_路遥知码农的博客-CSDN博客_lombok 依赖注入</a></p>\n</li>\n<li><p><a href=\"https://segmentfault.com/a/1190000040914633\">https://segmentfault.com/a/1190000040914633</a></p>\n</li>\n</ol>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"}]},{"title":"influxdb安装centos7","slug":"influxdbInstall","date":"2022-03-12T10:14:53.000Z","updated":"2022-09-22T07:39:53.074Z","comments":true,"path":"/post/influxdbInstall/","link":"","excerpt":"","content":"<h1 id=\"1、获取安装包\"><a href=\"#1、获取安装包\" class=\"headerlink\" title=\"1、获取安装包\"></a>1、获取安装包</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">wget https:&#x2F;&#x2F;dl.influxdata.com&#x2F;influxdb&#x2F;releases&#x2F;influxdb-1.8.10.x86_64.rpm</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/influxdbInstall/2022-03-12-18-28-41-image.png\" alt=\"\"></p>\n<h1 id=\"2、安装\"><a href=\"#2、安装\" class=\"headerlink\" title=\"2、安装\"></a>2、安装</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">yum localinstall influxdb-1.8.10.x86_64.rpm</code></pre>\n<h1 id=\"3、配置\"><a href=\"#3、配置\" class=\"headerlink\" title=\"3、配置\"></a>3、配置</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vim &#x2F;etc&#x2F;influxdb&#x2F;influxdb.conf</code></pre>\n<p>用户名密码(非必须)</p>\n<p><img src=\"https://img.huangge1199.cn/blog/influxdbInstall/2022-03-12-18-41-44-image.png\" alt=\"\"></p>\n<p>开启influx功能</p>\n<p><img src=\"https://img.huangge1199.cn/blog/influxdbInstall/2022-03-12-18-42-25-image.png\" alt=\"\"></p>\n<h1 id=\"4、启动服务\"><a href=\"#4、启动服务\" class=\"headerlink\" title=\"4、启动服务\"></a>4、启动服务</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">systemctl start influxdb</code></pre>\n<h1 id=\"5、启动\"><a href=\"#5、启动\" class=\"headerlink\" title=\"5、启动\"></a>5、启动</h1><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">influx</code></pre>\n<p>在客户端工具窗口中执行以下语句设置用户名和密码(非必须):</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 创建管理员权限的用户\nCREATE USER root WITH PASSWORD &#39;root&#39; WITH ALL PRIVILEGES</code></pre>\n<h1 id=\"6、验证\"><a href=\"#6、验证\" class=\"headerlink\" title=\"6、验证\"></a>6、验证</h1><p>用其他机器远程连接:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">influx -host ip地址 -port 端口号</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/influxdbInstall/2022-03-12-18-54-58-image.png\" alt=\"\"></p>\n<p>这里创建数据库时报错,是因为我这边配置了用户名和密码,需要连接时带上用户名和密码才行</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">iinflux -host ip地址 -port 端口号 -username 用户名 -password 密码</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/influxdbInstall/2022-03-12-18-56-23-image.png\" alt=\"\"></p>\n","categories":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"}]},{"title":"力扣590:N 叉树的后序遍历","slug":"day20220312","date":"2022-03-12T02:10:45.000Z","updated":"2024-04-25T08:10:09.100Z","comments":true,"path":"/post/day20220312/","link":"","excerpt":"","content":"<p>2022年03月12日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个 n&nbsp;叉树的根节点<meta charset=\"UTF-8\" />&nbsp;<code>root</code>&nbsp;,返回 <em>其节点值的<strong> 后序遍历</strong></em> 。</p>\n\n<p>n 叉树 在输入中按层序遍历进行序列化表示,每组子节点由空值 <code>null</code> 分隔(请参见示例)。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img src=\"https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png\" style=\"height: 193px; width: 300px;\" /></p>\n\n<pre>\n<strong>输入:</strong>root = [1,null,3,2,4,null,5,6]\n<strong>输出:</strong>[5,6,3,2,4,1]\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png\" style=\"height: 269px; width: 296px;\" /></p>\n\n<pre>\n<strong>输入:</strong>root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n<strong>输出:</strong>[2,6,14,11,7,3,12,8,4,13,9,10,5,1]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n <li>节点总数在范围 <code>[0, 10<sup>4</sup>]</code> 内</li>\n <li><code>0 &lt;= Node.val &lt;= 10<sup>4</sup></code></li>\n <li>n 叉树的高度小于或等于 <code>1000</code></li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><p><strong>进阶:</strong>递归法很简单,你可以使用迭代法完成此题吗?</p></p>\n<div><div>Related Topics</div><div><li>栈</li><li>树</li><li>深度优先搜索</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>思路:</p>\n<p>  这题简单,只需要递归做就好了,对于每一个节点,先存叶子节点,然后存根节点</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.ArrayList;\nimport java.util.List;\n\n&#x2F;*\n&#x2F;&#x2F; Definition for a Node.\nclass Node &#123;\n public int val;\n public List&lt;Node&gt; children;\n\n public Node() &#123;&#125;\n\n public Node(int _val) &#123;\n val &#x3D; _val;\n &#125;\n\n public Node(int _val, List&lt;Node&gt; _children) &#123;\n val &#x3D; _val;\n children &#x3D; _children;\n &#125;\n&#125;;\n*&#x2F;\n\nclass Solution &#123;\n public List&lt;Integer&gt; postorder(Node root) &#123;\n list &#x3D; new ArrayList&lt;&gt;();\n dfs(root);\n return list;\n &#125;\n List&lt;Integer&gt; list;\n private void dfs(Node root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return;\n &#125;\n if (root.children.size() &#x3D;&#x3D; 0) &#123;\n list.add(root.val);\n return;\n &#125;\n for (Node node : root.children) &#123;\n dfs(node);\n &#125;\n list.add(root.val);\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">&quot;&quot;&quot;\n# Definition for a Node.\nclass Node:\n def __init__(self, val&#x3D;None, children&#x3D;None):\n self.val &#x3D; val\n self.children &#x3D; children\n&quot;&quot;&quot;\nfrom typing import List\n\n\nclass Solution:\n def postorder(self, root: &#39;Node&#39;) -&gt; List[int]:\n arr &#x3D; []\n\n def dfs(root1: &#39;Node&#39;):\n if root1 is None:\n return\n if len(root1.children)&#x3D;&#x3D;0:\n arr.append(root1.val)\n return\n for node in root1.children:\n dfs(node)\n arr.append(root1.val)\n dfs(root)\n return arr</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"推理界的3月11号","slug":"mystery0311","date":"2022-03-11T06:33:56.000Z","updated":"2022-09-22T07:39:53.100Z","comments":true,"path":"/post/mystery0311/","link":"","excerpt":"","content":"<p>今天是3月11日在推理界今天在历史上的意义</p>\n<ul>\n<li>《东方杂志》中国第一期开始连载连载《毒美人》118周年</li>\n<li>小说林社中国出版《福尔摩斯再生案》第一册118周年</li>\n<li>克里斯蒂安娜·布兰德英国诞辰115周年</li>\n<li>梦野久作日本逝世86周年</li>\n<li>厄尔·斯坦利·加德纳美国逝世52周年</li>\n<li>弗瑞德里克·布朗美国逝世50周年</li>\n</ul>\n<h1 id=\"克里斯蒂安娜·布兰德\"><a href=\"#克里斯蒂安娜·布兰德\" class=\"headerlink\" title=\"克里斯蒂安娜·布兰德\"></a>克里斯蒂安娜·布兰德</h1><p>  克里斯蒂安娜·布兰德Christianna Brand1907.3.111988.12.17),英国侦探小说作家,儿童文学作家。</p>\n<p>  克里斯蒂安娜·布兰德1907年出生于马来亚原名为玛丽·克里斯蒂安娜·刘易斯Mary Christianna Lewis早年在印度生活。她从事过很多工作包括模特、舞蹈演员、店员和家庭教师。</p>\n<p>  1941年她创作了第一本以查尔斯·沃斯为主角的侦探小说《高跟鞋之死》Death in High Heels当时她还只是一个销售员。同年她笔下的英国著名探长考克瑞尔在《晕头转向》Heads You Lose一书中初次登场之后考克瑞尔先后七次出现在布兰德的作品中考克瑞尔探长是她塑造最成功的侦探形象以他为主角的侦探小说《绿色危机》Green for Danger也是布兰德最有名的小说。这部作品描写的是二次大战中一所医院中发生的故事一名邮递员被送往手术室不料却因麻醉过度而死。考克瑞尔探长亲自赶来调查却不料护士长玛丽恩·贝茨也惨遭杀害……《绿色危机》自1944年出版之后至今仍不断再版。1946年《绿色危机》被EagleLion公司拍成电影由阿拉斯泰尔·希姆饰演探长获得巨大成功。</p>\n<p>  由于《绿色危机》的成功1946年克里斯蒂安娜·布兰德加入了英国侦探作家俱乐部自此她的创作生涯一发不可收拾接连发表了多部小说。</p>\n<p>  上世纪50年代末开始克里斯蒂安娜·布兰德开始专注于撰写各种不同类型的作品和短篇小说。她曾获得三次埃德加奖提名短篇小说《杯中的毒药》Poison in the Cup1969年2月《埃勒里·奎因神秘杂志》、《Twist for Twist》1967年5月《埃勒里·奎因神秘杂志》以及一个有关苏格兰谋杀案的《天堂知道谁》Heaven Knows Who1960年。</p>\n<p>  1972到1973年间克里斯蒂安娜·布兰德以其杰出的成就被推选为英国犯罪作家协会主席。</p>\n<p>  克里斯蒂安娜·布兰德曾经使用过的笔名还有玛丽·安·阿希、安娜贝尔·琼斯、玛丽·罗兰和查娜·汤姆森。她的作品被称为“黄金时代最后的侦探小说”克里斯蒂安娜·布兰德的作品善于在活泼、幽默的情节以及吸引人的诡计中寻求平衡她在1988年去世享年81岁。</p>\n<h1 id=\"梦野久作\"><a href=\"#梦野久作\" class=\"headerlink\" title=\"梦野久作\"></a>梦野久作</h1><p>  日本著名幻想文学作家、变格派推理大师。</p>\n<p>  本名杉山直树,后改名杉山泰道。</p>\n<p>  曾用笔名有海若蓝平、香俱土三鸟、土原耕作、萌圆、杉山萌圆、沙门萌圆、萌圆山人、萌圆生、萌圆泰道、朴平、白木朴平、三鸟山人、香椎村人、青杉居士、外人某氏、钝骨生、TS生、T生等。</p>\n<p>  一九二六年,梦野久作在《妖鼓》投稿前,曾拿给父亲过目,父亲看过后说“就像梦野久作所写的小说”。 所谓“梦野久作”是博多地区的方言,意指精神恍惚、成天做白日梦的人。曾有数十个笔名的他自此以后便固定使用了这四个字为其笔名。</p>\n<p>  梦野久作有“妖怪作家”之称其所属的“变格派”讲究人性的怪奇、丑恶、战栗心理的唯美面使得推理小说充满了文学艺术气息。其代表作《脑髓地狱》1935年被称为日本推理小说的四大奇书之一。</p>\n<h2 id=\"生平年表\"><a href=\"#生平年表\" class=\"headerlink\" title=\"生平年表\"></a>生平年表</h2><p>  一八八九年一月四日生于九州福冈市。父亲杉山茂丸是右派教父、玄洋社头目头山满的盟友。直树出生後就由祖父母养育。</p>\n<p>  一八九一年开始学习四书诵读。亲生母亲与父亲离婚另嫁高桥家。</p>\n<p>  一八九二年开始学习能乐。熟读四书,遂有神童之称。</p>\n<p>  一八九五年,进入小学就读,身体虚弱瘦小,多由祖父教授学习。求知欲旺盛,具有绘画方面的天赋。</p>\n<p>  一八九九年,大名寻常小学毕业。进入高等小学就学。</p>\n<p>  一九零二年三月二十日,祖父因中风并发肺炎去世。</p>\n<p>  一九零三年三月,高等小学毕业,四月进入福冈县立中学修猷馆就读。</p>\n<p>  一九零八年三月福冈县立修猷馆中学毕业,十二月一日,以一年志愿兵身份入近卫步兵第一连队,在部队中担任小队长,颇受士兵们的信赖。</p>\n<p>  一九一零年,退伍之后,进入中央大学附属补习班,准备入学考。<br>  <br>  一九一一年,进入庆应大学文科系就读。</p>\n<p>  一九一二年,同父异母之弟五郎去世。二月二十六日,奉命成为陆军步兵少尉。十一月八日,继祖母去世。</p>\n<p>  一九一三年,因为弟弟的猝死,父亲遂令其从庆应大学休学。三月时,依父亲之命前往福冈县糟屋郡香椎村唐原经营果园。</p>\n<p>  一九一五年,于东京本乡的喜福寺剃发为僧。将直树改名为泰道。</p>\n<p>  一九一六年,以行脚僧身份从京都走到吉野山。</p>\n<p>  一九一七年被父亲叫回农园,还俗,继承杉山家业。从本年起,在父亲所组织的右派团体台华社机关杂志《黑白》发表有关谣曲与时事的评论之外,还撰写小说。这段期间使用的笔名有沙门萌圆、杉山萌圆、萌圆泰道等。</p>\n<p>  一九一八年二月二十五日,与镰田昌一的女儿阿仓结婚。连载《冀望日本青年》等。</p>\n<p>  一九一九年,长男龙丸出生。成为九州岛日报记者,开始于家庭专栏发表童话至一九二六年。</p>\n<p>  一九二零年,三十一岁,在父亲所投资之九州日报社当社会新闻记者,一九二二年在该报家庭版陆续发表童谣,所使用的笔名有梅若蓝平、香具上三鸟、上原耕作、三鸟山人等。并以萌圆泰道之笔名,将《吴井娘次》改名为《蜡人偶》连载。</p>\n<p>  一九二一年,移居福冈市荒户町。次男铁儿出生。</p>\n<p>  一九二二年,以杉山萌圆为笔名出版《白发小僧》长篇童话集。</p>\n<p>  一九二三年,九月因关东大地震,以九州岛日报社震灾特派记者身份发表《火烧后细见记》与《东京震灾素描》。</p>\n<p>  一九二四年,辞去九州岛日报社的工作,十月,以杉山泰道名义之《侏儒》,应徵博文馆的推理小说征选活动,获得佳作奖(没出版)。</p>\n<p>  一九二五年四月,再度任职九州日报社。三男参绿出生。</p>\n<p>  一九二六年是梦野久作生涯的转换年,正月开始撰写《脑髓地狱》初稿《狂人的解放治疗》,五月辞去报社工作,十月以初次使用梦野久作之笔名,《新青年》之侦探小说徵文之《妖鼓》,入选二等奖(没有一等奖),由此篇被公认之迟来的处女作,梦野久作登上推理文坛。其笔名是取自福冈博多地区的方言,指精神恍惚,经常寻找梦幻的人。</p>\n<p>  一九二七年二月,停止创作《狂人的解放治疗》初稿,创作短篇连载《乡村事件》。</p>\n<p>  一九二八年,陆续发表《人脸》、《死后之恋》、《瓶装地狱》等。</p>\n<p>  一九二九年,出版《梦野久作集》。陆续发表《押绘的奇迹》、《铁锤》、《飞翔于空中的洋伞》。</p>\n<p>  一九三零年五月,奉命担任妻子老家的福冈市黑门邮局局长。陆续发表《复仇》、《童贞》。</p>\n<p>  一九三一年,陆续发表《椰果》、《犬神博士》、《自白心理》等。</p>\n<p>  一九三二年,出版《押绘的奇迹》。陆续发表《斜坑》、《幽灵与推进机》、《狂气地狱》。</p>\n<p>  一九三三年,一月出版《暗黑公使》,四月出版《冰涯》,五月出版《瓶装地狱》,陆续发表《不冒烟的烟囱》、《爆弹太平记》、《白菊》等。</p>\n<p>  一九三四年,八月辞去黑门邮局局长一职。陆续发表《名君臣之》、《山羊胡编辑长》、《难船小僧》、《杀人直播》、《木魂》、《少女地狱》等。</p>\n<p>  一九三五年,一月出版《脑髓地狱》。三月出版《梅津只园翁传》。七月十九日,父亲茂丸因脑溢血猝死于曲町自宅(享年七十二岁)。十月,借帮父亲举行葬礼之便,携妻子至日本各地旅行。十二月,出版《近世快人传》。陆续发表《微笑哑女》、《超人胡夜博士》、《二重心脏》。</p>\n<p>  一九三六年,二月上京整理父亲遗物,遭遇“二二六”事件。陆续发表《人肉香肠》、《恶魔祈祷书》。三月出版《少女地狱》,十一日与访客谈话中猝死于东京(死因不详),得年四十七岁。</p>\n<p>  梦野久作有“妖怪作家”之称其所属的“变格派”讲究人性的怪奇、丑恶、战栗心理的唯美面使得推理小说充满了文学艺术气息。其代表作《脑髓地狱》1935年被称为日本推理小说的四大奇书之一。</p>\n<h1 id=\"厄尔·斯坦利·加德纳\"><a href=\"#厄尔·斯坦利·加德纳\" class=\"headerlink\" title=\"厄尔·斯坦利·加德纳\"></a>厄尔·斯坦利·加德纳</h1><p>Erle Stanley Gardner1889年7月17日美国马萨诸塞州马尔登-1970年3月11日加州Temecula</p>\n<p>其他署名:</p>\n<ul>\n<li>yle Corning</li>\n<li>A. A. Fair</li>\n<li>Charles M. Green</li>\n<li>Grant Holiday</li>\n<li>Carleton Kendrake</li>\n<li>Charles J. Kenny</li>\n<li>Robert Parr</li>\n<li>Dane Rigley</li>\n<li>Arthur Mann Sellers</li>\n<li>harles M. Stanton</li>\n<li>Les Tillray</li>\n</ul>\n<p>类型:</p>\n<ul>\n<li>大侦探</li>\n<li>私人侦探</li>\n<li>硬汉</li>\n<li>法庭</li>\n</ul>\n<p>主要系列:</p>\n<ul>\n<li>佩里·梅森Perry Mason, 1933-1973</li>\n<li>Doug Selby, D.A., 1937-1949</li>\n<li>Bertha Cool and Donald Lam, 1939-1970</li>\n</ul>\n<p>  加德纳是查尔斯·华尔特人·加德纳Charles Walter Gardner和格蕾丝·阿德尔玛·加德纳Grace Adelma Gardner之子。他的父亲是一位工程师因为工作需要到处出差他将全家搬到西海岸在加德纳十岁的时候先是搬到了俄勒冈州1902年又搬到加州奥维尔Oroville。加德纳对加州十分喜欢虽然成年之后他游历四方但是他还是将加州作为自己的家并且作为自己笔下人物的背景。</p>\n<p>  加德纳个性独立,勤奋,有想象力,二十一岁时他成为了一名律师,但是他没有进入法律学校而是在律师事务所自学以及担任律师助手,最后通过律师考试。他在洛杉矶西北部的文图拉县开业,很快他因为精明、足智多谋而赢得了声誉,他帮助很多看似不可能打赢官司的委托人获胜。</p>\n<p>  加德纳喜欢户外活动比如打猎钓鱼、射箭他成为作家之前他试过许多不同的生意三十四岁的时候他将自己的第一篇小说卖给了一家廉价杂志。他并不是一位有天赋的作家但是他通过研究那些成功作家的作品以及编辑的意见而进步神速。二三十年代他为廉价杂志创作了大量短篇小说并且塑造了一大堆人物。1933年他出版了第一部长篇小说主角便是日后著名律师侦探佩里·梅森。那时他创作速度惊人每三天便能完成一部一万单词的中篇小说以至于他无法依靠打自己要而使用口述机因此他雇请了几位秘书轮班根据他的口述完成稿件。</p>\n<p>  二次大战之后加德纳的名声让他的创作数量减少了因为他涉足其他的事务包括“最高上诉法院”Court of Last Resort这是加德纳和他人创立的一家组织主要是为了增加美国法律的公正性还有佩里·梅森系列电视片。</p>\n<p>  1912年加德纳与纳塔利·塔伯特Natalie Talbert结婚1913年他们生下女儿纳塔利·格蕾丝·加德纳Natalie Grace Gardner。1935年两人分居不过他们还是朋友也并未离婚。加德纳一直赡养他的妻子直到1968年妻子去世。同年加德纳与他长期以来的秘书艾格尼斯·简·贝斯尔Agnes Jean Bethell结婚贝斯尔被认为是梅森的秘书德拉·斯特里特Della Street的原型。1962年他获得美国侦探作家协会MWA大师奖。1970年加德纳因为癌症去世。</p>\n<h1 id=\"弗瑞德里克·布朗\"><a href=\"#弗瑞德里克·布朗\" class=\"headerlink\" title=\"弗瑞德里克·布朗\"></a>弗瑞德里克·布朗</h1><p>  弗瑞德里克·布朗Fredric Brown1906年10月29日美国俄亥俄州辛辛那提-1972年3月11日亚利桑那州图森</p>\n<p>  类型:私人侦探;硬汉</p>\n<p>  主要系列Ed and Am Hunter, 1947-1963</p>\n<p>  布朗十多岁的时候父母相继去世不得不自谋生路。二十年代他进入汉诺威学院Hanover College和辛辛那提大学Cincinnati University学习。他于1929年结婚并且搬到威斯康星州密尔沃基在那里他为几家出版社担任校对直到在《密尔沃基期刊》Milwaukee Journal找到一份固定的工作。他呆在这家杂志一直到1947年接着搬到纽约在一家廉价杂志集团担任编辑。</p>\n<p>  1938年布朗发表了第一篇小说《镍币之月》The Moon for a Nickel刊登在《斯崔特和史密斯侦探小说杂志》Street and Smiths Detective Story Magazine。从那时开始布朗成为廉价杂志的固定投稿者在不同类型的杂志上发表包括《一角侦探》Dime Mystery、《星球故事》Planet Stories、《怪异故事》Weird Tales。他在廉价小说读者中拥有一大堆拥趸。</p>\n<p>  布朗第一次普遍的成功是因为发表了第一部长篇小说《传说中的高级夜总会》The Fabulous Clipjoint1947这部作品的主角是一对叔侄组合艾德和阿姆·亨特Ed and Am Hunter。他还因此赢得了1984年的埃德加奖。布朗的的经济状况得到改善他搬到纽约成为一名高级编辑。同时他和第一任妻子海伦Helen离婚。</p>\n<p>  他接下来的侦探小说也非常成功包括《死亡套环》The Dead Ringer1948、《尖叫的米米》The Screaming Mimi1949。1949年末他遇到了伊丽莎白·查利尔Elizabeth Charlier二人结婚后搬到新墨西哥州的陶斯。廉价小说集团倒闭之后布朗成为了一名受欢迎的犯罪小说家。随着电视在娱乐业中所占的份量越来越重布朗也将他的小说改编为电视片。</p>\n<p>  布朗的身体一直不好而且他偶尔酗酒对身体健康更是无益。因为呼吸疾病布朗和妻子在1954年搬到亚利桑那州图森。尽管他为一些报酬很高的杂志写作诸如《花花公子》Playboy但是他已经在走下坡。他的最后一部长篇小说《墨菲太太的内衣裤》Mrs. Murphys Underpants1963已经不是水准之作。他还写了一些短篇小说但是他全职写作的时代已经过去。1972年布朗因为肺气肿去世。(ellry)</p>\n","categories":[{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"}],"tags":[{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"力扣2049:统计最高分的节点数目","slug":"day20220311","date":"2022-03-11T04:05:16.000Z","updated":"2022-09-22T07:39:52.862Z","comments":true,"path":"/post/day20220311/","link":"","excerpt":"","content":"<p>2022年03月11日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一棵根节点为 <code>0</code> 的 <strong>二叉树</strong> ,它总共有 <code>n</code> 个节点,节点编号为 <code>0</code> 到 <code>n - 1</code> 。同时给你一个下标从 <strong>0</strong> 开始的整数数组 <code>parents</code> 表示这棵树,其中 <code>parents[i]</code> 是节点 <code>i</code> 的父节点。由于节点 <code>0</code> 是根,所以 <code>parents[0] == -1</code> 。</p>\n\n<p>一个子树的 <strong>大小</strong> 为这个子树内节点的数目。每个节点都有一个与之关联的 <strong>分数</strong> 。求出某个节点分数的方法是,将这个节点和与它相连的边全部 <strong>删除</strong> ,剩余部分是若干个 <strong>非空</strong> 子树,这个节点的 <strong>分数</strong> 为所有这些子树 <strong>大小的乘积</strong> 。</p>\n\n<p>请你返回有 <strong>最高得分</strong> 节点的 <strong>数目</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"example-1\" src=\"https://assets.leetcode.com/uploads/2021/10/03/example-1.png\" style=\"width: 604px; height: 266px;\"></p>\n\n<pre><b>输入:</b>parents = [-1,2,0,2,0]\n<b>输出:</b>3\n<strong>解释:</strong>\n- 节点 0 的分数为3 * 1 = 3\n- 节点 1 的分数为4 = 4\n- 节点 2 的分数为1 * 1 * 2 = 2\n- 节点 3 的分数为4 = 4\n- 节点 4 的分数为4 = 4\n最高得分为 4 ,有三个节点得分为 4 (分别是节点 13 和 4 )。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"example-2\" src=\"https://assets.leetcode.com/uploads/2021/10/03/example-2.png\" style=\"width: 95px; height: 143px;\"></p>\n\n<pre><b>输入:</b>parents = [-1,2,0]\n<b>输出:</b>2\n<strong>解释:</strong>\n- 节点 0 的分数为2 = 2\n- 节点 1 的分数为2 = 2\n- 节点 2 的分数为1 * 1 = 1\n最高分数为 2 ,有两个节点分数为 2 (分别为节点 0 和 1 )。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>n == parents.length</code></li>\n <li><code>2 <= n <= 10<sup>5</sup></code></li>\n <li><code>parents[0] == -1</code></li>\n <li>对于 <code>i != 0</code> ,有 <code>0 <= parents[i] <= n - 1</code></li>\n <li><code>parents</code> 表示一棵二叉树。</li>\n</ul></p>\n<div><div>Related Topics</div><div><li>树</li><li>深度优先搜索</li><li>数组</li><li>二叉树</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>思路:</p>\n<p>  这题是要返回有 <strong>最高得分</strong>节点的 <strong>数目</strong>,那么就要将每一个节点的分数都算一遍,而每一个节点的分数,是由以下几个数的乘积,包括,该节点下左子树中节点的数目、该节点下右子树中节点的数目,以及总节点数-改节点为跟节点的树的节点数。</p>\n<p>  那么,我的解题步骤如下:</p>\n<ol>\n<li><p>我先根据题目给的parents数组分别统计每个节点的直连子节点将其存放进map中。</p>\n</li>\n<li><p>根据map运用递归求出每一个节点做为根节点的子树中的节点数将其存入counts数组中</p>\n</li>\n<li><p>接下来遍历求每一个节点的分数,并且记入最大得分及节点的数量</p>\n</li>\n</ol>\n<p>下面是java的代码解法</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n &#x2F;&#x2F; 记录每一个节点作为根节点的子树中节点的数量\n int[] counts;\n public int countHighestScoreNodes(int[] parents) &#123;\n int size &#x3D; parents.length;\n\n &#x2F;&#x2F; 记录每个节点的直接子节点\n Map&lt;Integer, List&lt;Integer&gt;&gt; map &#x3D; new HashMap&lt;&gt;();\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n map.put(i, new ArrayList&lt;&gt;());\n &#125;\n for (int i &#x3D; 1; i &lt; size; i++) &#123;\n map.get(parents[i]).add(i);\n &#125;\n\n &#x2F;&#x2F; 记录每个子节点为根节点的树中节点数\n counts &#x3D; new int[size];\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n if (counts[i] &gt; 0) &#123;\n continue;\n &#125;\n counts[i] &#x3D; dfs(map.get(i), map);\n &#125;\n\n &#x2F;&#x2F; 遍历计算每个节点的得分并统计结果\n long mul &#x3D; 1;\n for (int num : map.get(0)) &#123;\n mul *&#x3D; counts[num];\n &#125;\n int count &#x3D; 1;\n for (int i &#x3D; 1; i &lt; size; i++) &#123;\n long temp &#x3D; 1;\n for (int num : map.get(i)) &#123;\n temp *&#x3D; counts[num];\n &#125;\n temp *&#x3D; (size - counts[i]);\n if (temp &gt; mul) &#123;\n mul &#x3D; temp;\n count &#x3D; 1;\n &#125; else if (temp &#x3D;&#x3D; mul) &#123;\n count++;\n &#125;\n &#125;\n return count;\n &#125;\n &#x2F;**\n * 计算每个节点为根节点的树中节点数\n *&#x2F;\n private int dfs(List&lt;Integer&gt; list, Map&lt;Integer, List&lt;Integer&gt;&gt; map) &#123;\n if (list.size() &#x3D;&#x3D; 0) &#123;\n return 1;\n &#125;\n int count &#x3D; 1;\n for (int i : list) &#123;\n if (counts[i] &gt; 0) &#123;\n count +&#x3D; counts[i];\n &#125; else &#123;\n count +&#x3D; dfs(map.get(i), map);\n &#125;\n &#125;\n return count;\n &#125;\n&#125;</code></pre>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"maven打jar包时本地依赖包未在其中","slug":"question20220310-1","date":"2022-03-10T06:18:41.000Z","updated":"2022-09-22T07:39:53.198Z","comments":true,"path":"/post/question20220310-1/","link":"","excerpt":"","content":"<p>今天运行jar包时报错了报的内容是不存在某一个依赖包中的类经过一番排查发现这个类是下面这种形式依赖的<br><pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;dependency&gt;\n\t&lt;groupId&gt;com.oracle&lt;&#x2F;groupId&gt;\n\t&lt;artifactId&gt;ojdbc6&lt;&#x2F;artifactId&gt;\n\t&lt;version&gt;11.2.0.4&lt;&#x2F;version&gt;\n\t&lt;scope&gt;system&lt;&#x2F;scope&gt;\n\t&lt;systemPath&gt;D:&#x2F;work&#x2F;ojdbc6-11.2.0.4.jar&lt;&#x2F;systemPath&gt;\n&lt;&#x2F;dependency&gt;</code></pre><br>针对依赖包是在本地的这种情况需要在pom中添加includeSystemScope=true参考如下<br><pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;build&gt;\n\t&lt;plugins&gt;\n\t\t&lt;plugin&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-maven-plugin&lt;&#x2F;artifactId&gt;\n\t\t\t&lt;version&gt;2.1.7.RELEASE&lt;&#x2F;version&gt;\n\t\t\t&lt;configuration&gt;\n\t\t\t\t&lt;includeSystemScope&gt;true&lt;&#x2F;includeSystemScope&gt;\n\t\t\t&lt;&#x2F;configuration&gt;\n\t\t&lt;&#x2F;plugin&gt;\n\t&lt;&#x2F;plugins&gt;\n&lt;&#x2F;build&gt;</code></pre></p>\n","categories":[{"name":"问题记录","slug":"问题记录","permalink":"https://hexo.huangge1199.cn/categories/%E9%97%AE%E9%A2%98%E8%AE%B0%E5%BD%95/"}],"tags":[{"name":"maven","slug":"maven","permalink":"https://hexo.huangge1199.cn/tags/maven/"}]},{"title":"推理界的3月10号","slug":"mystery0310","date":"2022-03-10T02:40:38.000Z","updated":"2022-09-22T07:39:53.100Z","comments":true,"path":"/post/mystery0310/","link":"","excerpt":"","content":"<p>今天是3月10日在推理界历史的今天有如下事件</p>\n<ul>\n<li>古处诚二日本诞辰52周年</li>\n</ul>\n<h1 id=\"古处诚二\"><a href=\"#古处诚二\" class=\"headerlink\" title=\"古处诚二\"></a>古处诚二</h1><p>  1970年出生于褔冈县、并曾经参与航空自卫队长达六年的古处诚二2000年以自卫队基地为舞台的推理小说《Unknown》获得第十四回梅菲斯特奖其后同年再发表以地震灾难为主题的《少年们的密室》、及于翌年(2001)再以自卫队组织为主题创作了《未完成》接着更以战争为题材发表其他类型的非推理小说。2005年以《七月七日》入选直木奖候选</p>\n","categories":[{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"}],"tags":[{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"力扣589:N 叉树的前序遍历","slug":"day20220310","date":"2022-03-10T01:51:36.000Z","updated":"2024-04-25T08:10:09.098Z","comments":true,"path":"/post/day20220310/","link":"","excerpt":"","content":"<p>2022年03月10日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个 n&nbsp;叉树的根节点 <meta charset=\"UTF-8\" />&nbsp;<code>root</code>&nbsp;,返回 <em>其节点值的<strong> 前序遍历</strong></em> 。</p>\n\n<p>n 叉树 在输入中按层序遍历进行序列化表示,每组子节点由空值 <code>null</code> 分隔(请参见示例)。</p>\n\n<p><br />\n<strong>示例 1</strong></p>\n\n<p><img src=\"https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png\" style=\"height: 193px; width: 300px;\" /></p>\n\n<pre>\n<strong>输入:</strong>root = [1,null,3,2,4,null,5,6]\n<strong>输出:</strong>[1,3,5,6,2,4]\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png\" style=\"height: 272px; width: 300px;\" /></p>\n\n<pre>\n<strong>输入:</strong>root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n<strong>输出:</strong>[1,2,3,6,7,11,14,4,8,12,5,9,13,10]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n <li>节点总数在范围<meta charset=\"UTF-8\" />&nbsp;<code>[0, 10<sup>4</sup>]</code>内</li>\n <li><code>0 &lt;= Node.val &lt;= 10<sup>4</sup></code></li>\n <li>n 叉树的高度小于或等于 <code>1000</code></li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><p><strong>进阶:</strong>递归法很简单,你可以使用迭代法完成此题吗?</p></p>\n<div><div>Related Topics</div><div><li>栈</li><li>树</li><li>深度优先搜索</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n List&lt;Integer&gt; list &#x3D; new ArrayList&lt;&gt;();\n public List&lt;Integer&gt; preorder(Node root) &#123;\n dfs(root);\n return list;\n &#125;\n void dfs(Node root) &#123;\n if (root &#x3D;&#x3D; null) &#123;\n return;\n &#125;\n list.add(root.val);\n for (Node node : root.children) &#123;\n dfs(node);\n &#125;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">&quot;&quot;&quot;\n# Definition for a Node.\nclass Node:\n def __init__(self, val&#x3D;None, children&#x3D;None):\n self.val &#x3D; val\n self.children &#x3D; children\n&quot;&quot;&quot;\nfrom typing import List\n\n\nclass Solution:\n def preorder(self, root: &#39;Node&#39;) -&gt; List[int]:\n result &#x3D; []\n\n def dfs(node):\n if node:\n result.append(node.val)\n for child in node.children:\n dfs(child)\n\n dfs(root)\n return result</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣798:得分最高的最小轮调","slug":"day20220309","date":"2022-03-09T08:42:38.000Z","updated":"2024-04-25T08:10:09.096Z","comments":true,"path":"/post/day20220309/","link":"","excerpt":"","content":"<p>2022年03月09日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个数组 <code>nums</code>,我们可以将它按一个非负整数 <code>k</code> 进行轮调,这样可以使数组变为 <code>[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]</code> 的形式。此后,任何值小于或等于其索引的项都可以记作一分。</p>\n\n<ul>\n <li>例如,数组为 <code>nums = [2,4,1,3,0]</code>,我们按 <code>k = 2</code> 进行轮调后,它将变成 <code>[1,3,0,2,4]</code>。这将记为 <code>3</code> 分,因为 <code>1 > 0</code> [不计分]、<code>3 > 1</code> [不计分]、<code>0 <= 2</code> [计 1 分]、<code>2 <= 3</code> [计 1 分]<code>4 <= 4</code> [计 1 分]。</li>\n</ul>\n\n<p>在所有可能的轮调中,返回我们所能得到的最高分数对应的轮调下标 <code>k</code> 。如果有多个答案,返回满足条件的最小的下标 <code>k</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [2,3,1,4,0]\n<strong>输出:</strong>3\n<strong>解释:</strong>\n下面列出了每个 k 的得分:\nk = 0, nums = [2,3,1,4,0], score 2\nk = 1, nums = [3,1,4,0,2], score 3\nk = 2, nums = [1,4,0,2,3], score 3\nk = 3, nums = [4,0,2,3,1], score 4\nk = 4, nums = [0,2,3,1,4], score 3\n所以我们应当选择 k = 3得分最高。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,3,0,2,4]\n<strong>输出:</strong>0\n<strong>解释:</strong>\nnums 无论怎么变化总是有 3 分。\n所以我们将选择最小的 k即 0。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n <li><code>0 <= nums[i] < nums.length</code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>前缀和</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>思路:</p>\n<p><code>arrs[k]</code>代表轮调k次的分数然后<code>[left,right]</code>区间内的值代表能得分的k值那么</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">left &#x3D; i + 1\nright &#x3D; i - nums[i]</code></pre>\n<p>考虑到超出数组范围的问题,因此,修改为</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">&#x2F;&#x2F; size为数组长度\nleft &#x3D; (i + 1) % size;\nright &#x3D; (i - nums[i] + size) % size;</code></pre>\n<p>接下来,我们要考虑<code>[left,right]</code>是否是有效区间</p>\n<ul>\n<li><p>如果是在这个区间内得分+1</p>\n</li>\n<li><p>如果不是有效区间,那么区间将拆分成<code>[0,right]</code>和<code>[left,size-1]</code>两部分,这两部分区间内得分+1</p>\n</li>\n</ul>\n<p>最后我们对数组进行设置,这部分可以使用差分实现</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int bestRotation(int[] nums) &#123;\n int size &#x3D; nums.length;\n int[] arrs &#x3D; new int[size + 1];\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n int left &#x3D; (i + 1) % size;\n int right &#x3D; (i - nums[i] + size) % size;\n if (left &gt; right) &#123;\n arrs[0]++;\n arrs[size]--;\n &#125;\n arrs[left]++;\n arrs[right + 1]--;\n &#125;\n for (int i &#x3D; 1; i &lt; size + 1; i++) &#123;\n arrs[i] +&#x3D; arrs[i - 1];\n &#125;\n int result &#x3D; 0;\n for (int i &#x3D; 1; i &lt; size + 1; i++) &#123;\n if (arrs[i] &gt; arrs[result]) &#123;\n result &#x3D; i;\n &#125;\n &#125;\n return result;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def bestRotation(self, nums: List[int]) -&gt; int:\n size &#x3D; len(nums)\n arrs &#x3D; [0] * (size + 1)\n for i in range(size):\n left &#x3D; (i + 1) % size\n right &#x3D; (i - nums[i] + size) % size\n if left &gt; right:\n arrs[0] +&#x3D; 1\n arrs[size] -&#x3D; 1\n arrs[left] +&#x3D; 1\n arrs[right + 1] -&#x3D; 1\n for i in range(1, size + 1):\n arrs[i] +&#x3D; arrs[i - 1]\n result &#x3D; 0\n for i in range(1, size + 1):\n if arrs[i] &gt; arrs[result]:\n result &#x3D; i\n return result</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣504:七进制数","slug":"day20220307","date":"2022-03-07T06:15:07.000Z","updated":"2024-04-25T08:10:09.095Z","comments":true,"path":"/post/day20220307/","link":"","excerpt":"","content":"<p>2022年02月14日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个整数 <code>num</code>,将其转化为 <strong>7 进制</strong>,并以字符串形式输出。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> num = 100\n<strong>输出:</strong> \"202\"\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> num = -7\n<strong>输出:</strong> \"-10\"\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>-10<sup>7</sup>&nbsp;&lt;= num &lt;= 10<sup>7</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数学</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public String convertToBase7(int num) &#123;\n boolean bl &#x3D; num &lt; 0;\n num &#x3D; Math.abs(num);\n StringBuilder str &#x3D; new StringBuilder();\n while (num &gt;&#x3D; 7) &#123;\n str.insert(0, num % 7);\n num &#x2F;&#x3D; 7;\n &#125;\n str.insert(0, num);\n if (bl) &#123;\n str.insert(0, &#39;-&#39;);\n &#125;\n return str.toString();\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def convertToBase7(self, num: int) -&gt; str:\n bl &#x3D; num &lt; 0\n s &#x3D; &#39;&#39;\n num &#x3D; abs(num)\n while num &gt;&#x3D; 7:\n s &#x3D; str(num % 7) + s\n num &#x2F;&#x2F;&#x3D; 7\n s &#x3D; str(num) + s\n if bl:\n s &#x3D; &#39;-&#39; + s\n return s</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"推理界的3月7号","slug":"mystery0307","date":"2022-03-07T01:21:47.000Z","updated":"2022-09-22T07:39:53.099Z","comments":true,"path":"/post/mystery0307/","link":"","excerpt":"","content":"<p>今天是3月7日在推理界历史的今天有如下事件</p>\n<ul>\n<li><p>仁木悦子日本诞辰94周年</p>\n</li>\n<li><p>种村直树日本诞辰86周年</p>\n</li>\n<li><p>佐飞通俊日本诞辰62周年</p>\n</li>\n<li><p>贾德森·菲利普斯美国逝世33周年</p>\n</li>\n</ul>\n<h1 id=\"仁木悦子\"><a href=\"#仁木悦子\" class=\"headerlink\" title=\"仁木悦子\"></a>仁木悦子</h1><p>  日本名女推理小说作家。</p>\n<p>  仁木悦子的经历尤其令人注目1928年生于东京原名大井三重子、她幼年无忧无虑但四岁那年患结核性胸椎骨疽病以致下肢瘫痪半身不遂。七岁那年父亲去世不久母亲也亡故。疾病缠身的仁木悦子幸亏有哥哥大井羲光照顾他每天教她读书。第二次世界大战爆发16岁的仁木悦子由哥哥背着来到富山乡下居住。她只读到小学三年级但却看了不少书并从18岁起开始写作。她先练习写童话发表在《儿童俱乐部》和《母亲之友》杂志上她的30多篇童话小说还结集出版。后来她又成了“克里斯蒂小说迷”并写出推理小说《猫知道》。这部小说的主角是一对兄妹侦探哥哥雄太郎是植物系大学生妹妹悦子是音乐系学生这对兄妹通过一只猫的经历侦破了一起谋杀案。作品中渗入作者与她哥哥的影子推理手法十分细腻许多伏线埋在紧张的情节之中把粗心的读者引人迷途在作品中可见女作家的风格。故事的进展采用侦探的助手叙述的方式叙述者仁木悦子与作者同名的形式在日本就是由仁木悦子创下的成功先例。之后在日本作者与作品同名的作品不少。</p>\n<p>  以仁木兄妹为侦探,作者之后继续撰写了《林中之家》、《有刺之树》、《黑色的飘带》等三部长篇和《黄色的花》等若干短篇。 </p>\n<p>  仁木悦子幼时卧病在床,玩伴就是猫,所以她一直喜欢猫,不但让猫在《猫知道》里扮演重要的角色,她所出版的许多推理小说的封面,也都请画家画描,晚年时还主编了一本以“猫”为主题的小说集。她家中的猫则是女佣外出时,从外面捡回来的遭人遗弃的小猫。</p>\n<p>  《猫知道》写于1957年参加了江户川乱步侦探小说奖的评选。经过评委投票《猫知道》在96篇征文作品中名列第一并获第三届江户川乱步奖。</p>\n<p>  由于评委都不认识作者当仁木悦子由她哥哥大井羲光和亲友抬着参加颁奖仪式时全场引起了轰动。人们意想不到一个半身不遂、不能走动的女性竟有如此聪颖的智慧与坚韧的毅力她赢得了热烈的掌声。在闪光灯中第一次见到仁木悦子的江户川乱步亲自给她发奖、奖品是一人座“福尔摩斯座像”还有五万日元的奖金。评委木木高太郎则发表了一段讲话“《呼啸山庄》在英国文学史上占有不朽的地位女作家艾米莉·勃朗蒂病魔缠身能写出这样的杰作。仁木悦子君也是有病在身相信她也能写出与勃朗蒂媲美的好书。”29岁的仁术悦子激动得热泪盈眶她是20多年来第一次离开家门。事后她回忆道“我走进豪华的会场大厅看见闪闪发光的水晶吊灯以为自己走进了童话王国。”</p>\n<p>  仁木悦子获奖后《猫知道》印数剧增。15万册一销而空后来又拍成电影。丰厚的稿酬收入改善了仁木悦子艰难的处境她住医院进行了5 次手术终于能在家中行走并坐着轮椅车上街观光。一位翻译家同她结了婚婚后两人和谐美满。仁木悦子不仅成为丈夫的助手而且又先后写出了7 部长篇推理小说《林中小屋》1959 年、《杀人线路图》1960年、《有刺的树》1961年、《黑色缎带》1962年、《两张底片》1964年、《枯叶色的街》1966年、《冰冷的街道》1973年。有5 部小说仍以兄妹侦探为主角。《两张底片》则是以一对夫妇联手破案。《枯叶色的街》是个贫穷的青年与书店女职员被卷进凶案,成为破案主角。这些推理小说都得到了读者的好评。</p>\n<p>  1980年的&lt;赤的猫&gt;获得第三十四届日本推理作家协会短篇赏。仁木悦子最后于1986年因肾病逝世享年58岁。</p>\n<p>  《猫知道》被日本评论家誉为推理小说史上的“第二次浪潮”。在同一年,松本清张也发表了推理名篇《点与线》。这两部小说一扫日本侦探小说中阴森诡秘的文风,替而代之清新简朴的风格。仁木悦子以女性细腻的文笔,写出了社会推理小说,尽管她身患重疾、但她的小说却给人乐观健康的感受。她注重细节的挖掘,留给读者深刻的印象。继仁木悦子之后,许多推理小说家都自觉地摆脱“变格派”的风格,推重社会推理小说的写实手法。从这一点上说,仁木悦子对日本推理小说的发展有着重要的贡献。</p>\n<h1 id=\"种村直树\"><a href=\"#种村直树\" class=\"headerlink\" title=\"种村直树\"></a>种村直树</h1><p>  种村直树1936年3月7日日本作家、随笔家、评论家。</p>\n<p>  1973年开始创作从事与铁路有关的创作发表过很多铁路相关的报告文学、时评、游记、推理小说。</p>\n<p>  出生于滋贺县大津市。滋贺县立大津东高中(现滋贺县立膳所高中)、京都大学法学系毕业。</p>\n<p>  1972年在每日新闻当记者。在此期间掌握了丰富的铁道知识和创作能力在当时“铁路杂志”总编辑竹岛纪元的鼓动下执笔创作了《列车追迹》并开始连载。成为自由撰稿人之后成为“社会派”推理小说的主要创作作家之一。</p>\n<p>  代表作《铁道旅行术》、《日本国有铁道最后的事件》、《“青春18车票”之旅》等。</p>\n<h1 id=\"佐飞通俊\"><a href=\"#佐飞通俊\" class=\"headerlink\" title=\"佐飞通俊\"></a>佐飞通俊</h1><p>  佐飞通俊1960年3月7日日本作家、文艺评论家。</p>\n<p>  出身于福井县。中央大学文学系哲学科毕业在新闻社工作。1991年《静音系统》静かなるシステム刊登于“群像”1991年6月号获第34届群像新人文学奖评论部门优秀作品。</p>\n<p>  2006年开始创作小说2月出版《孤独通告》円環の孤独讲谈社小说同年8月出版《爱因斯坦游戏》アインシュタイン·ゲーム讲谈社小说2007年4月又推出“宴の果て 死は独裁者に”讲谈社小说。</p>\n<h1 id=\"贾德森·菲利普斯\"><a href=\"#贾德森·菲利普斯\" class=\"headerlink\" title=\"贾德森·菲利普斯\"></a>贾德森·菲利普斯</h1><p>  贾德森·菲利普斯全名贾德森·潘特寇斯特·菲利普斯Judson Pentecost Philips1903年8月10号- 1989年3月7日美国侦探小说作家他以休·潘特寇斯特、菲利普·欧文的笔名和他的本名发表了100多部侦探小说上世纪30年代他还写了为数众多的体育运动类小说。</p>\n<p>  他出生在美国马萨诸塞州诺斯菲尔德1925年从哥伦比亚大学毕业。</p>\n<p>  20世纪的20年代到30年代菲利普斯开始为“纸浆”杂志撰写短篇小说他还同时撰写剧本和一家报纸的专栏。1950年他进入沙龙剧场负责剧本写作和宣传。</p>\n<p>  1973年他获得美国侦探作家协会MWA颁发的最高荣誉奖项——大师奖。</p>\n<p>  1989年菲利普斯因肺气肿引起并发症在康涅狄格州迦南去世享年85岁。他留下妻子诺玛·伯顿·菲利普斯、三个儿子大卫、约翰、丹尼尔和一个女儿卡罗琳·诺伍德。</p>\n","categories":[{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"}],"tags":[{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"推理界的3月5号","slug":"mystery0305","date":"2022-03-05T02:45:18.000Z","updated":"2022-09-22T07:39:53.098Z","comments":true,"path":"/post/mystery0305/","link":"","excerpt":"","content":"<p>今天是3月5日在推理界历史的今天有如下事件</p>\n<ul>\n<li><p>水谷准日本诞辰118周年</p>\n</li>\n<li><p>《广益丛报》中国第六十五号刊载署名“冷血陈景韩戏作”《歇洛克来游上海第一案》117周年</p>\n</li>\n<li><p>谷克二日本诞辰81周年</p>\n</li>\n</ul>\n<h1 id=\"水谷准\"><a href=\"#水谷准\" class=\"headerlink\" title=\"水谷准\"></a>水谷准</h1><p>  水谷准1904年3月5日2001年3月20日日本小说家、推理作家、翻译家、编辑。</p>\n<p>  出生于北海道函馆市。旧制函馆中学现北海道函馆中部高中中途退学后进入东京早稻田高中读书。读书期间1922年以《好敌手》参加“新青年”的有奖征稿第一等入选。早稻田大学文学部法国文学系毕业。1929年接替“新青年”总编辑的职务。1938年一度离职1939年到1945年再次担任“新青年”的总编辑。</p>\n<p>  1952年《决斗》ある決闘获第5届侦探作家俱乐部奖短篇奖。</p>\n<p>  二战之后较多创作与高尔夫球有关的作品。</p>\n<h1 id=\"谷克二\"><a href=\"#谷克二\" class=\"headerlink\" title=\"谷克二\"></a>谷克二</h1><p>  谷克二1941年3月5日日本小说家被称为“狩猎冒险小说之王狩猎冒险小说第一人者”。出生于宫崎县延冈市。本名谷正胜。</p>\n<p>  1963年毕业于早稻田大学商学系。在德国大众汽车公司工作过之后去了英国在伦敦大学主修历史经济学。回国后开始创作生涯。</p>\n<p>  1974年凭借处女作《追うもの》获得第1届野性时代新人奖。1978年又以《狙击者》获得第5届角川小说奖。他的作品《サバンナ》又译作《西班牙的短暂夏天》以及《越境线》先后获得直木奖候补作。</p>\n","categories":[{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"}],"tags":[{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"推理界的3月4号","slug":"mystery0304","date":"2022-03-04T03:28:18.000Z","updated":"2022-09-22T07:39:53.097Z","comments":true,"path":"/post/mystery0304/","link":"","excerpt":"","content":"<p>今天是3月4日在推理界历史的今天有如下事件</p>\n<ul>\n<li><p>程小青中国出席纪念白居易诞辰诗会65周年</p>\n</li>\n<li><p>妹尾韶夫日本诞辰130周年</p>\n</li>\n<li><p>詹姆斯·艾尔罗伊美国诞辰74周年</p>\n</li>\n<li><p>黑川博行日本诞辰73周年</p>\n</li>\n<li><p>半村良日本逝世20周年</p>\n</li>\n</ul>\n<h1 id=\"程小青\"><a href=\"#程小青\" class=\"headerlink\" title=\"程小青\"></a>程小青</h1><p>  程小青1893—1976【原名程青心又名程辉斋】</p>\n<p>  籍贯:江苏吴县人。</p>\n<p>  身平介绍少年家贫曾在钟表店当学徒自学外语和热爱看书他18岁时开始从事文学写作先是与周瘦鹃合作翻译柯南·道尔作品后来创作《霍桑探案》一举成名。</p>\n<p>  据史料介绍程小青在21岁时发表的《灯光人影》被《新闻报》举行的征文大赛选中他小说中的侦探原名霍森因排字工人误排于是便成了霍桑。《霍桑探案》发表之后程小青不断收到读者大量来信。是读者的鼓励促使程小青先后写出了《江南燕》、《珠项圈》、《黄浦江中》、《八十四》、《轮下血》、《裹棉刀》、《恐怖的话剧》、《雨夜枪声》、《白衣怪》、《催命符》、《索命钱》、《新婚劫》、《活尸》、《逃犯》、《血手印》、《黑地牢》、《无头案》等30余部侦探小说。著名报人郑逸梅曾称赞他“毕生精力尽瘁于此也就成为侦探小说的巨擘。”</p>\n<p>  程小青的创作,据另一位著名报人范烟桥称“模仿了柯南道尔的写法”,但他又塑造了“中国的福尔摩斯”。为了达到这一目的,程小青作为函授生,受业于美国大学函授科,进修犯罪心理学与侦探学的学习,他从理论上学习西欧侦探理论,在实践中又把中国旧社会发生的案例加以改造。他在谈到创作时,多次谈到自己如何设计侦探小说的名字,怎样取材与裁剪,怎样构思开头与结尾,他把美国作家韦尔斯的专著《侦探小说技艺论》和美国心理学家聂克逊博士的专著《著作人应知的心理学》作为教科书。在小说中,程小青设计了霍桑与包朗一对搭档,类似福尔摩斯与华生医生,但在案件的取材上,程小青着重描写旧中国社会弊病引发的凶杀案,注重人物的心理分析,把凶杀与现实生活的投影结合起来,因此形成了自己的特点与风格。</p>\n<h1 id=\"妹尾韶夫\"><a href=\"#妹尾韶夫\" class=\"headerlink\" title=\"妹尾韶夫\"></a>妹尾韶夫</h1><p>  妹尾韶夫1892年3月4日1962年4月19日日本翻译家、侦探小说作家。出生于冈山县津山市。</p>\n<p>  早稻田大学英文系毕业后1922年为“新青年”等杂志翻译英美侦探小说其中多数是阿加莎·克里斯蒂的作品。1925年以后以妹尾安艺夫名义创作发表了30到40个短篇小说。</p>\n<p>  在“新青年”担当每月评论的胡铁梅、“宝石”杂志每月评论者小原俊一,据说都是妹尾的笔名。</p>\n<p>  1962年因脑溢血去世终年70岁。</p>\n<h1 id=\"詹姆斯·艾尔罗伊\"><a href=\"#詹姆斯·艾尔罗伊\" class=\"headerlink\" title=\"詹姆斯·艾尔罗伊\"></a>詹姆斯·艾尔罗伊</h1><p>  詹姆斯·艾尔罗伊 (詹姆斯·艾尔罗瓦) James Ellroy1948年3月4日美国加州洛杉矶-</p>\n<p>  类型:硬汉;警察程序;私人侦探;倒叙</p>\n<p>  主要系列:</p>\n<ul>\n<li>“洛依·霍普金斯”三部曲Lloyd Hopkins trilogy, 1984-1986</li>\n<li>洛杉矶四部曲L.A. quartet, 1987-1992</li>\n<li>American Underworld trilogy/Underworld USA trilogy, 1995-</li>\n</ul>\n<p>  艾尔罗伊本名李·厄尔·艾尔罗伊Lee Earle Ellroy。父亲阿曼德·艾尔罗伊Armand Ellroy是反犹太主义者副业是会计师母亲杰尼瓦·奥德丽·“简”·希利克·艾尔罗伊Geneva Odelia “Jean” Hilliker Ellroy是注册护士。艾尔罗伊的父母于1940年结婚1954年离婚。艾尔罗伊被判给母亲接着搬到了埃尔蒙特市。据艾尔罗伊回忆母亲经常在周六晚上酗酒。1958年6月22日发生了一件对于艾尔罗伊一生影响深远的事情那天他的母亲被人谋杀。之后艾尔罗伊和父亲一起居住。十一岁生日父亲送给他一本洛杉矶警察局历史的书籍他仔细阅读了这本书立志将来当一名作家。艾尔罗伊是一个有强迫症的读者他常常去图书馆借书还从书店里偷犯罪小说。</p>\n<p>  艾尔罗伊进入犹太费尔法克斯高中Jewish Fairfax High School1965年校方知道他父亲的纳粹观点之后将他开除。接着他进入美国陆军但是很快认识到自己不是当兵的材料。他假装口吃于是很快退伍。他回家之后不久父亲去世了。</p>\n<p>  那段时间艾尔罗伊就住在街上靠着入店行窃和入室盗窃为生。他喝酒有时候还嗑药占据着无人的房子。1965年到1977年间艾尔罗伊因为醉酒、偷窃和非法入室而多次被捕。最后被判入狱八个月。刑满释放之后他做过一些低等的工作诸如散发传单递送邮件色情书店出纳等等。他继续喝酒滥用鼻用吸入器。因为患上肺炎和妄想症艾尔罗伊被送去治疗1975年治愈。接着他找了一些稳定的工作比如高尔夫和乡村俱乐部的球童参加戒酒互助协会Alcoholics Anonymous之后他开始创作小说。</p>\n<p>  艾尔罗伊的第一部长篇小说《布朗的安魂曲》Browns Requiem是一部半自传性质的犯罪小说风格类似雷蒙德·钱德勒小说的主人公弗里兹·布朗Fritz Brown曾经是一名警官他戒酒之后变成了一名私人侦探。第二部《秘密行事》Clandestine1982讲述了一名前警官追踪杀害以前爱人的凶手的故事获得埃德加奖提名。</p>\n<p>  此后艾尔罗伊的创作速度保持稳健。他先是发表了“洛依·霍普金斯”三部曲包括《染血之夜》Blood on the Moon1984、《因起此夜》Because the Night1984、《自殺坡》Suicide Hill1986。1984年他辞去球童全职写作。他又发表了“洛杉矶四部曲”包括《黑色大丽花》The Black Dahlia1987、《无处藏身》The Big Nowhere1988、《洛杉矶的秘密》L.A. Confidential1990、《白色爵士舞》White Jazz1992。因此在国内和国际上获得了声誉。《无处藏身》或的1990年侦探小说奖Prix Mystere Award。《洛杉矶的秘密》被改编成电影获得奥斯卡奖提名。2006年《黑色大丽花》被搬上大银幕。</p>\n<p>  1993年到2004年间艾尔罗伊在《GQ》杂志上发表了小说和非小说。这些作品结集为《好莱坞夜曲》Hollywood Nocturnes1994、《犯罪之波来自洛杉矶地下社会的报道和小说》Crime Wave: Reportage and Fiction from the Underside of L.A.1999和《危险的步调》Breakneck Pace2000。</p>\n<p>  艾尔罗伊结过两次婚第一任妻子是玛丽·多赫尔蒂Mary Doherty第二任是海伦·诺德Helen Knode均离婚。2005年他从康涅狄格州纽卡纳安搬到洛杉矶。ellry</p>\n<h1 id=\"黑川博行\"><a href=\"#黑川博行\" class=\"headerlink\" title=\"黑川博行\"></a>黑川博行</h1><p>  黑川博行1949年3月4日日本小说家。出生于爱媛县。京都市立艺术大学美术学系雕刻科毕业。妻子是日本画家黑川雅子。</p>\n<p>  毕业后在高中担任美术教师1984年以《第二次告别》二度のお别れ获三得利推理大奖佳作。1986年《猫眼宝石》キャッツアイころがった获第4届三得利推理大奖。1996年《伯爵计划》カウント·プラン获第49届日本推理作家协会奖短篇部门。</p>\n<p>  获得直木奖候补的作品有《伯爵计划》(カウント·プラン)、《疫病神》、《文福茶釜》、《国境》、《恶果》等。</p>\n<p>  他还是由船越荣一郎主演的电视连续剧《刑事吉永诚一·泪的事件簿》的原作。</p>\n<h1 id=\"半村良\"><a href=\"#半村良\" class=\"headerlink\" title=\"半村良\"></a>半村良</h1><p>  半村良1933年10月27日2002年3月4日日本小说家。本名清野平太郎。出生于东京府现东京都在东京都立两国高中毕业后先后做过酒吧侍者等多种职业在广告公司任职期间与广播公司等建立了密切的关系后开始这方面的工作。</p>\n<p>  1962年短篇小说《收获》収穫获得第2届早川科幻小说大赛ハヤカワ·SFコンテスト第三名正式成为作家上世纪六十年代在《SF杂志》SFマガジン上发表若干个短篇小说后突然不再发表作品据说和当时《SF杂志》总编辑福岛正实关系不佳后转入自由创作。</p>\n<p>  1971年出版《石之血脉》石の血脈开创了浪漫传奇小说流派这种风格对后世很多作家产生了影响。</p>\n<p>  1975年《雨やどり》获得直木奖。</p>\n","categories":[{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"}],"tags":[{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"}]},{"title":"python3学习笔记--集合、元组、字典、列表对比","slug":"pyMulCom","date":"2022-03-03T13:55:20.000Z","updated":"2022-09-22T07:39:53.194Z","comments":true,"path":"/post/pyMulCom/","link":"","excerpt":"","content":"<h1 id=\"数据结构\"><a href=\"#数据结构\" class=\"headerlink\" title=\"数据结构\"></a>数据结构</h1><p>Python支持以下数据结构列表字典元组集合。</p>\n<p><strong>何时使用字典:</strong></p>\n<ul>\n<li><p>当您需要键:值对之间的逻辑关联时。</p>\n</li>\n<li><p>当您需要基于自定义密钥快速查找数据时。</p>\n</li>\n<li><p>当你的数据不断修改时。请记住,字典是可变的。</p>\n</li>\n</ul>\n<p><strong>何时使用其他类型:</strong></p>\n<ul>\n<li><p>如果您有一些不需要随机访问的数据集合,请使用列表。当你需要一个简单的,可迭代的频繁修改的集合可以使用列表。</p>\n</li>\n<li><p>如果你需要元素的唯一性,使用集合。</p>\n</li>\n<li><p>当数据无法更改时使用元组。</p>\n</li>\n</ul>\n<blockquote>\n<p>很多时候,元组与字典结合使用,例如元组可能代表一个关键字,因为它是不可变的。</p>\n</blockquote>\n<h1 id=\"1、列表\"><a href=\"#1、列表\" class=\"headerlink\" title=\"1、列表\"></a>1、列表</h1><p>使用<strong>方括号</strong>创建</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">words &#x3D; [&quot;Hello&quot;, &quot;world&quot;, &quot;!&quot;]</code></pre>\n<blockquote>\n<p>使用空的方括号创建空列表</p>\n<p>可以通过索引来访问</p>\n<p>大多数情况下,列表中的最后一项不会带逗号。然而,在最后一项放置一个逗号是完全有效的,在某些情况下是鼓励的。 </p>\n<p>列表的索引是从0开始的而不是从1开始的</p>\n</blockquote>\n<h1 id=\"2、集合\"><a href=\"#2、集合\" class=\"headerlink\" title=\"2、集合\"></a>2、集合</h1><p>使用<strong>花括号</strong>或 <strong>set</strong> 函数创建</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">num_set &#x3D; &#123;1, 2, 3, 4, 5&#125;\nword_set &#x3D; set([&quot;spam&quot;, &quot;eggs&quot;, &quot;sausage&quot;])</code></pre>\n<blockquote>\n<p>要创建一个空集,必须使用 set(),如 {} 是创建一个空字典。</p>\n<p>集合是<strong>无序</strong>的,这意味着他们不能被索引。</p>\n<p>集合不能包含重复的元素。</p>\n<p>由于存储的方式,检查一个项目是否是一个集合的一部分比检查是不是列表的一部分<strong>更快</strong>。 </p>\n<p>集合使用 <strong>add</strong> 添加元素 。 </p>\n<p><strong>remove</strong> 方法从集合中删除特定的元素; <strong>pop</strong> 删除随机的元素。</p>\n</blockquote>\n<h1 id=\"3、元组\"><a href=\"#3、元组\" class=\"headerlink\" title=\"3、元组\"></a>3、元组</h1><p>元组 使用<strong>圆括号</strong>创建 ,也可以在没有<strong>圆括号</strong>的情况下创建</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">words &#x3D; (&quot;spam&quot;, &quot;eggs&quot;, &quot;sausages&quot;,)\nmy_tuple &#x3D; &quot;one&quot;, &quot;two&quot;, &quot;three&quot;</code></pre>\n<blockquote>\n<p>使用空括号对创建空元组。</p>\n<p>元组比列表快,但是元组不能改变。 </p>\n<p>可以使用索引访问元组中的值。</p>\n</blockquote>\n<h1 id=\"4、字典\"><a href=\"#4、字典\" class=\"headerlink\" title=\"4、字典\"></a>4、字典</h1><p>字典是用于将任意键映射到值的数据结构</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">ages &#x3D; &#123;&quot;Dave&quot;: 24, &quot;Mary&quot;: 42, &quot;John&quot;: 58&#125;</code></pre>\n<blockquote>\n<p>空字典被定义为{}。</p>\n<p>字典 中的每个元素都由一个 键:值 对来表示。 </p>\n<p>使用 <strong>字典[“键名”]</strong> 可以获取对应的值。</p>\n</blockquote>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"python3学习笔记--列表切片","slug":"pyListSlice","date":"2022-03-01T01:47:34.000Z","updated":"2022-09-22T07:39:53.187Z","comments":true,"path":"/post/pyListSlice/","link":"","excerpt":"","content":"<p>列表切片(<strong>List slices</strong>)提供了从列表中检索值的更高级的方法。</p>\n<blockquote>\n<p>列表名[num1 : num2 : num3]</p>\n<p>从索引num1到num2不包括num2间隔为num3的元素</p>\n<p>num1或num2为负值代表从末尾开始算起的</p>\n<p>num3为负值代表切片进行逆序截取</p>\n</blockquote>\n<p>以下为具体说明</p>\n<h1 id=\"基本用法\"><a href=\"#基本用法\" class=\"headerlink\" title=\"基本用法\"></a>基本用法</h1><p>用两个以冒号分隔的整数索引列表。</p>\n<p>列表切片返回一个包含索引之间旧列表中所有值的新列表。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">squares &#x3D; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\nprint(squares[2:6])\nprint(squares[3:8])\nprint(squares[0:1])</code></pre>\n<p>结果:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">[4, 9, 16, 25]\n[9, 16, 25, 36, 49]\n[0]</code></pre>\n<blockquote>\n<p>和Range参数一样在一个 slice 中提供的第一个索引被包含在结果中,但是第二个索引没有。</p>\n</blockquote>\n<h1 id=\"省略一个数字\"><a href=\"#省略一个数字\" class=\"headerlink\" title=\"省略一个数字\"></a>省略一个数字</h1><p>如果省略了切片中的第一个数字,则将从列表第一个元素开始。 </p>\n<p>如果第二个数字被省略,则认为是到列表结束。 </p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">squares &#x3D; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\nprint(squares[:7])\nprint(squares[7:])</code></pre>\n<p>结果:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">[0, 1, 4, 9, 16, 25, 36]\n[49, 64, 81]</code></pre>\n<blockquote>\n<p>切片也可以用在元组上</p>\n</blockquote>\n<h1 id=\"带间隔的切片\"><a href=\"#带间隔的切片\" class=\"headerlink\" title=\"带间隔的切片\"></a>带间隔的切片</h1><p>列表切片还可以有第三个数字,表示间隔。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">squares &#x3D; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\nprint(squares[::2])\nprint(squares[2:8:3])</code></pre>\n<p>结果:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">[0, 4, 16, 36, 64]\n[4, 25]</code></pre>\n<blockquote>\n<p>[283] 包含从索引2到8间隔3的元素。</p>\n</blockquote>\n<h1 id=\"带负值\"><a href=\"#带负值\" class=\"headerlink\" title=\"带负值\"></a>带负值</h1><p>负值也可用于列表切片(和正常列表索引)。当切片(或普通索引)中的第一个和第二个值使用负值时,它们将从列表的末尾算起。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">squares &#x3D; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\nprint(squares[1:-1])\nprint(squares[-3:-1])\nprint(squares[::-1])</code></pre>\n<p>结果:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">[1, 4, 9, 16, 25, 36, 49, 64]\n[49, 64]\n[81, 64, 49, 36, 25, 16, 9, 4, 1, 0]</code></pre>\n<blockquote>\n<p>如果切片第三个数值使用负值,则切片进行逆序截取。<br>使用[::-1]作为切片是反转列表的常用方法。</p>\n</blockquote>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"python3学习笔记--常用的函数","slug":"pyUsefulFun","date":"2022-03-01T01:02:19.000Z","updated":"2024-04-25T08:10:09.104Z","comments":true,"path":"/post/pyUsefulFun/","link":"","excerpt":"","content":"<div class=\"note info no-icon flat\"><p>本篇博客内容为学习整理笔记,学习地址为:<br><a href=\"https://www.w3cschool.cn/minicourse/play/python3course?cp=427&amp;gid=0\">https://www.w3cschool.cn/minicourse/play/python3course?cp=427&amp;gid=0</a></p>\n</div>\n<h1 id=\"字符串函数\"><a href=\"#字符串函数\" class=\"headerlink\" title=\"字符串函数\"></a>字符串函数</h1><h2 id=\"1、join\"><a href=\"#1、join\" class=\"headerlink\" title=\"1、join\"></a>1、join</h2><p>以另一个字符串作为分隔符连接字符串列表。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;, &quot;.join([&quot;spam&quot;, &quot;eggs&quot;, &quot;ham&quot;]))\n# 打印 &quot;spam, eggs, ham&quot;</code></pre>\n<h2 id=\"2、replace\"><a href=\"#2、replace\" class=\"headerlink\" title=\"2、replace\"></a>2、replace</h2><p>用另一个替换字符串中的一个子字符串。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;Hello ME&quot;.replace(&quot;ME&quot;, &quot;world&quot;))\n# 打印 &quot;Hello world&quot;</code></pre>\n<h2 id=\"3、startswith\"><a href=\"#3、startswith\" class=\"headerlink\" title=\"3、startswith\"></a>3、startswith</h2><p>确定是否在字符串的开始处有一个子字符串。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;This is a sentence.&quot;.startswith(&quot;This&quot;))\n# 打印 &quot;True&quot;</code></pre>\n<h2 id=\"4、endswith\"><a href=\"#4、endswith\" class=\"headerlink\" title=\"4、endswith\"></a>4、endswith</h2><p>确定是否在字符串的结尾处有一个子字符串。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;This is a sentence.&quot;.endswith(&quot;sentence.&quot;))\n# 打印 &quot;True&quot;</code></pre>\n<h2 id=\"5、lower\"><a href=\"#5、lower\" class=\"headerlink\" title=\"5、lower\"></a>5、lower</h2><p>将字符串全部转为小写。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;AN ALL CAPS SENTENCE&quot;.lower())\n# 打印 &quot;an all caps sentence&quot;</code></pre>\n<h2 id=\"6、upper\"><a href=\"#6、upper\" class=\"headerlink\" title=\"6、upper\"></a>6、upper</h2><p>将字符串全部转为大写。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;This is a sentence.&quot;.upper())\n# 打印 &quot;THIS IS A SENTENCE.&quot;</code></pre>\n<h2 id=\"7、split\"><a href=\"#7、split\" class=\"headerlink\" title=\"7、split\"></a>7、split</h2><p>把一个字符串转换成一个列表。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(&quot;spam, eggs, ham&quot;.split(&quot;, &quot;))\n# 打印 &quot;[&#39;spam&#39;, &#39;eggs&#39;, &#39;ham&#39;]&quot;</code></pre>\n<h1 id=\"数字函数\"><a href=\"#数字函数\" class=\"headerlink\" title=\"数字函数\"></a>数字函数</h1><h2 id=\"1、max\"><a href=\"#1、max\" class=\"headerlink\" title=\"1、max\"></a>1、max</h2><p>查找某些数字或列表的最大值。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(max([1, 2, 9, 2, 4, 7, 8]))\n# 打印 9</code></pre>\n<h2 id=\"2、min\"><a href=\"#2、min\" class=\"headerlink\" title=\"2、min\"></a>2、min</h2><p>查找某些数字或列表的最小值。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(min(1, 6, 3, 4, 0, 7, 1))\n# 打印 0</code></pre>\n<h2 id=\"3、abs\"><a href=\"#3、abs\" class=\"headerlink\" title=\"3、abs\"></a>3、abs</h2><p>将数字转成绝对值该数字与0的距离。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(abs(-93))\nprint(abs(22))\n# 打印 93</code></pre>\n<h2 id=\"4、round\"><a href=\"#4、round\" class=\"headerlink\" title=\"4、round\"></a>4、round</h2><p>要将数字四舍五入到一定的小数位数。</p>\n<h2 id=\"5、sum\"><a href=\"#5、sum\" class=\"headerlink\" title=\"5、sum\"></a>5、sum</h2><p>计算一个列表数字的总和。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">print(sum([1, 2, 3, 4, 5, 6]))\n# 打印 21</code></pre>\n<h1 id=\"列表函数\"><a href=\"#列表函数\" class=\"headerlink\" title=\"列表函数\"></a>列表函数</h1><h2 id=\"1、all\"><a href=\"#1、all\" class=\"headerlink\" title=\"1、all\"></a>1、all</h2><p>列表中所有值均为 True 时,结果为 True否则结果为 False。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">nums &#x3D; [55, 44, 33, 22, 11]\n\nif all([i &gt; 5 for i in nums]):\n print(&quot;All larger than 5&quot;)\n\n# 打印 All larger than 5</code></pre>\n<h2 id=\"2、any\"><a href=\"#2、any\" class=\"headerlink\" title=\"2、any\"></a>2、any</h2><p>列表中只要有一个为 True结果为 True反之结果为 False。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">nums &#x3D; [55, 44, 33, 22, 11]\n\nif any([i % 2 &#x3D;&#x3D; 0 for i in nums]):\n print(&quot;At least one is even&quot;)\n\n# 打印 At least one is even5</code></pre>\n<h2 id=\"3、enumerate\"><a href=\"#3、enumerate\" class=\"headerlink\" title=\"3、enumerate\"></a>3、enumerate</h2><p>用来同时迭代列表的键和值。</p>\n<p>例如:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">nums &#x3D; [55, 44, 33, 22, 11]\n\nfor v in enumerate(nums):\n print(v)\n\n# 打印\n# (0, 55)\n# (1, 44)\n# (2, 33)\n# (3, 22)\n# (4, 11)</code></pre>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"力扣540:有序数组中的单一元素","slug":"day20220214","date":"2022-02-14T01:49:24.000Z","updated":"2024-04-25T08:10:09.093Z","comments":true,"path":"/post/day20220214/","link":"","excerpt":"","content":"<p>2022年02月14日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个只包含整数的有序数组,每个元素都会出现两次,唯有一个数只会出现一次,找出这个数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> nums = [1,1,2,3,3,4,4,8,8]\n<strong>输出:</strong> 2\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> nums = [3,3,7,7,10,11,11]\n<strong>输出:</strong> 10\n</pre>\n\n<p> </p>\n\n<p><meta charset=\"UTF-8\" /></p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n <li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n <li><code>0 <= nums[i] <= 10<sup>5</sup></code></li>\n</ul>\n\n<p> </p>\n\n<p><p><strong>进阶:</strong> 采用的方案可以在 <code>O(log n)</code> 时间复杂度和 <code>O(1)</code> 空间复杂度中运行吗?</p></p>\n<div><div>Related Topics</div><div><li>数组</li><li>二分查找</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>根据异或的规则相同为0不同为1这样把所有数都异或一遍结果就是唯一的只出现一次的数</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">public int singleNonDuplicate(int[] nums) &#123;\n int result &#x3D; nums[0];\n for (int i &#x3D; 1; i &lt; nums.length; i++) &#123;\n result ^&#x3D; nums[i];\n &#125;\n return result;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">import operator\nfrom functools import reduce\nfrom typing import List\n\n\nclass Solution:\n def singleNonDuplicate(self, nums: List[int]) -&gt; int:\n return reduce(operator.xor, nums)</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣1189:“气球” 的最大数量","slug":"day20220213","date":"2022-02-13T14:32:48.000Z","updated":"2024-04-25T08:10:09.092Z","comments":true,"path":"/post/day20220213/","link":"","excerpt":"","content":"<p>2022年02月13日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个字符串&nbsp;<code>text</code>,你需要使用 <code>text</code> 中的字母来拼凑尽可能多的单词&nbsp;<strong>&quot;balloon&quot;(气球)</strong>。</p>\n\n<p>字符串&nbsp;<code>text</code> 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词&nbsp;<strong>&quot;balloon&quot;</strong>。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://img.huangge1199.cn/blog/day20220213/1536_ex1_upd.jpeg\" style=\"height: 35px; width: 154px;\"></strong></p>\n\n<pre><strong>输入:</strong>text = &quot;nlaebolko&quot;\n<strong>输出:</strong>1\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://img.huangge1199.cn/blog/day20220213/1536_ex2_upd.jpeg\" style=\"height: 35px; width: 233px;\"></strong></p>\n\n<pre><strong>输入:</strong>text = &quot;loonbalxballpoon&quot;\n<strong>输出:</strong>2\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><strong>输入:</strong>text = &quot;leetcode&quot;\n<strong>输出:</strong>0\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= text.length &lt;= 10^4</code></li>\n <li><code>text</code>&nbsp;全部由小写英文字母组成</li>\n</ul></p>\n<div><div>Related Topics</div><div><li>哈希表</li><li>字符串</li><li>计数</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>一个单词”balloon”分别需要一个ban以及二个lo<br>首先我们统计给的单词中每个字母的个数<br>然后统计ban数量以及lo除以2的最小值</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int maxNumberOfBalloons(String text) &#123;\n int[] arrs &#x3D; new int[26];\n for (char ch : text.toCharArray()) &#123;\n arrs[ch - &#39;a&#39;]++;\n &#125;\n int count &#x3D; Math.min(arrs[0], arrs[1]);\n count &#x3D; Math.min(count, arrs[&#39;l&#39; - &#39;a&#39;] &#x2F; 2);\n count &#x3D; Math.min(count, arrs[&#39;o&#39; - &#39;a&#39;] &#x2F; 2);\n count &#x3D; Math.min(count, arrs[&#39;n&#39; - &#39;a&#39;]);\n return count;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def maxNumberOfBalloons(self, text: str) -&gt; int:\n return min(cnts[ch] &#x2F;&#x2F; 2 if ch in &quot;lo&quot; else cnts[ch] for ch in &quot;balon&quot;) if (cnts :&#x3D; Counter(text)) else 0</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣1020:飞地的数量","slug":"day20220212","date":"2022-02-12T14:22:26.000Z","updated":"2024-04-25T08:10:09.090Z","comments":true,"path":"/post/day20220212/","link":"","excerpt":"","content":"<p>2022年02月12日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个大小为 <code>m x n</code> 的二进制矩阵 <code>grid</code> ,其中 <code>0</code> 表示一个海洋单元格、<code>1</code> 表示一个陆地单元格。</p>\n\n<p>一次 <strong>移动</strong> 是指从一个陆地单元格走到另一个相邻(<strong>上、下、左、右</strong>)的陆地单元格或跨过 <code>grid</code> 的边界。</p>\n\n<p>返回网格中<strong> 无法 </strong>在任意次数的移动中离开网格边界的陆地单元格的数量。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/02/18/enclaves1.jpg\" style=\"height: 200px; width: 200px;\" />\n<pre>\n<strong>输入:</strong>grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\n<strong>输出:</strong>3\n<strong>解释:</strong>有三个 1 被 0 包围。一个 1 没有被包围,因为它在边界上。\n</pre>\n\n<p><strong>示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/02/18/enclaves2.jpg\" style=\"height: 200px; width: 200px;\" />\n<pre>\n<strong>输入:</strong>grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\n<strong>输出:</strong>0\n<strong>解释:</strong>所有 1 都在边界上或可以到达边界。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>m == grid.length</code></li>\n <li><code>n == grid[i].length</code></li>\n <li><code>1 &lt;= m, n &lt;= 500</code></li>\n <li><code>grid[i][j]</code> 的值为 <code>0</code> 或 <code>1</code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>深度优先搜索</li><li>广度优先搜索</li><li>并查集</li><li>数组</li><li>矩阵</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>解题方法:广度优先算法</p>\n<p>这道题是统计无法力扣网络边界的陆地单元格数量,我的思路是反过来统计,用<code>总陆地数量</code>-<code>能离开的陆地数量</code></p>\n<p>这样的话,我就可以用广度优先算法来进行解决,步骤如下:</p>\n<ol>\n<li>将边界的单元格坐标加入到队列,并计数</li>\n<li>依次从队列中取出</li>\n<li>将取出陆地的相邻陆地加入到队列中,并计数</li>\n<li>当队列为空时,遍历数组获取总陆地数,并减去能离开的陆地数量</li>\n</ol>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.LinkedList;\nimport java.util.Queue;\n\nclass Solution &#123;\n public int numEnclaves(int[][] grid) &#123;\n boolean[][] use &#x3D; new boolean[grid.length][grid[0].length];\n Queue&lt;int[]&gt; queue &#x3D; new LinkedList&lt;&gt;();\n int xl &#x3D; grid.length;\n int yl &#x3D; grid[0].length;\n int count &#x3D; 0;\n for (int i &#x3D; 0; i &lt; xl; i++) &#123;\n if (grid[i][0] &#x3D;&#x3D; 1) &#123;\n queue.add(new int[]&#123;i, 0&#125;);\n use[i][0] &#x3D; true;\n count++;\n &#125;\n if (grid[i][yl - 1] &#x3D;&#x3D; 1 &amp;&amp; !use[i][yl - 1]) &#123;\n queue.add(new int[]&#123;i, yl - 1&#125;);\n use[i][yl - 1] &#x3D; true;\n count++;\n &#125;\n &#125;\n for (int i &#x3D; 1; i &lt; yl - 1; i++) &#123;\n if (grid[0][i] &#x3D;&#x3D; 1 &amp;&amp; !use[0][i]) &#123;\n queue.add(new int[]&#123;0, i&#125;);\n use[0][i] &#x3D; true;\n count++;\n &#125;\n if (grid[xl - 1][i] &#x3D;&#x3D; 1 &amp;&amp; !use[xl - 1][i]) &#123;\n queue.add(new int[]&#123;xl - 1, i&#125;);\n use[xl - 1][i] &#x3D; true;\n count++;\n &#125;\n &#125;\n int[] xp &#x3D; new int[]&#123;1, -1, 0, 0&#125;;\n int[] yp &#x3D; new int[]&#123;0, 0, 1, -1&#125;;\n while (!queue.isEmpty()) &#123;\n int[] arr &#x3D; queue.poll();\n int x &#x3D; arr[0];\n int y &#x3D; arr[1];\n for (int k &#x3D; 0; k &lt; 4; k++) &#123;\n int nx &#x3D; x + xp[k];\n int ny &#x3D; y + yp[k];\n if (nx &gt;&#x3D; 0 &amp;&amp; nx &lt; grid.length &amp;&amp; ny &gt;&#x3D; 0 &amp;&amp; ny &lt; grid[0].length &amp;&amp; grid[nx][ny] &#x3D;&#x3D; 1 &amp;&amp; !use[nx][ny]) &#123;\n queue.add(new int[]&#123;nx, ny&#125;);\n use[nx][ny] &#x3D; true;\n count++;\n &#125;\n &#125;\n &#125;\n int sum &#x3D; 0;\n for (int[] ints : grid) &#123;\n for (int j &#x3D; 0; j &lt; yl; j++) &#123;\n if (ints[j] &#x3D;&#x3D; 1) &#123;\n sum++;\n &#125;\n &#125;\n &#125;\n return sum - count;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from collections import deque\nfrom typing import List\n\n\nclass Solution:\n def numEnclaves(self, grid: List[List[int]]) -&gt; int:\n use &#x3D; [[False] * len(grid[0]) for _ in range(len(grid))]\n queue &#x3D; deque()\n xl &#x3D; len(grid)\n yl &#x3D; len(grid[0])\n count &#x3D; 0\n for i in range(xl):\n if grid[i][0] &#x3D;&#x3D; 1:\n queue.append((i, 0))\n use[i][0] &#x3D; True\n count +&#x3D; 1\n if grid[i][yl - 1] &#x3D;&#x3D; 1 and not use[i][yl - 1]:\n queue.append((i, yl - 1))\n use[i][yl - 1] &#x3D; True\n count +&#x3D; 1\n for i in range(1, yl - 1):\n if grid[0][i] &#x3D;&#x3D; 1 and not use[0][i]:\n queue.append((0, i))\n use[0][i] &#x3D; True\n count +&#x3D; 1\n if grid[xl - 1][i] &#x3D;&#x3D; 1 and not use[xl - 1][i]:\n queue.append((xl - 1, i))\n use[xl - 1][i] &#x3D; True\n count +&#x3D; 1\n while queue:\n x, y &#x3D; queue.pop()\n for nx, ny in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):\n if nx &lt; 0 or nx &gt;&#x3D; len(grid) or ny &lt; 0 or ny &gt;&#x3D; len(grid[0]) or grid[nx][ny] &#x3D;&#x3D; 0 or use[nx][ny]:\n continue\n queue.append((nx, ny))\n use[nx][ny] &#x3D; True\n count +&#x3D; 1\n sc &#x3D; sum([sum(row) for row in grid])\n return sc - count</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"代码提交到多个git仓库","slug":"gitPushMoreRepo","date":"2022-02-11T09:34:25.000Z","updated":"2022-09-22T07:39:52.889Z","comments":true,"path":"/post/gitPushMoreRepo/","link":"","excerpt":"","content":"<p>现在我们都习惯于把自己的代码放到远程仓库中毫无疑问GitHub是首选但由于国内的网络等各种原因会导致我们连接不上这时候我们会考虑放到自建的代码管理仓库或者是gitee上面。</p>\n<p>我们还不想放弃GitHub那么我们就要考虑将代码提交到多个仓库中。</p>\n<p>比如我分别在GitHub和gitee上都有格子的仓库</p>\n<ul>\n<li><a href=\"https://github.com/huangge1199/my-blog.git\">https://github.com/huangge1199/my-blog.git</a></li>\n<li><a href=\"https://gitee.com/huangge1199_admin/my-blog.git\">https://gitee.com/huangge1199_admin/my-blog.git</a></li>\n</ul>\n<p>那么,我可以通过以下命令来进行添加仓库:</p>\n<p>先添加第一个GitHub的仓库地址<br><pre class=\"line-numbers language-none\"><code class=\"language-none\">git remote add origin https:&#x2F;&#x2F;github.com&#x2F;huangge1199&#x2F;my-blog.git</code></pre></p>\n<p>再添加gitee的仓库地址<br><pre class=\"line-numbers language-none\"><code class=\"language-none\">git remote set-url --add origin https:&#x2F;&#x2F;gitee.com&#x2F;huangge1199_admin&#x2F;my-blog.git</code></pre><br>这样的话我们push时就会将代码同时推送到两个仓库了。</p>\n<p>当然不想用命令的形式操作,也可以直接修改项目目录下隐藏目录.git中的config文件在[remote “origin”]中添加多个仓库地址就可以了,参考如下:</p>\n<pre class=\"line-numbers language-none\"><code class=\"language-none\">[remote &quot;origin&quot;]\n\turl &#x3D; https:&#x2F;&#x2F;gitee.com&#x2F;huangge1199_admin&#x2F;my-blog.git\n\tfetch &#x3D; +refs&#x2F;heads&#x2F;*:refs&#x2F;remotes&#x2F;origin&#x2F;*\n\turl &#x3D; https:&#x2F;&#x2F;github.com&#x2F;huangge1199&#x2F;my-blog.git</code></pre>\n","categories":[{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/categories/git/"}],"tags":[{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/tags/git/"}]},{"title":"力扣1984:学生分数的最小差值","slug":"day20220211","date":"2022-02-11T05:35:01.000Z","updated":"2024-04-25T08:10:09.089Z","comments":true,"path":"/post/day20220211/","link":"","excerpt":"","content":"<p>2022年02月11日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个 <strong>下标从 0 开始</strong> 的整数数组 <code>nums</code> ,其中 <code>nums[i]</code> 表示第 <code>i</code> 名学生的分数。另给你一个整数 <code>k</code> 。</p>\n\n<p>从数组中选出任意 <code>k</code> 名学生的分数,使这 <code>k</code> 个分数间 <strong>最高分</strong> 和 <strong>最低分</strong> 的 <strong>差值</strong> 达到<strong> 最小化</strong> 。</p>\n\n<p>返回可能的 <strong>最小差值</strong> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>nums = [90], k = 1\n<strong>输出:</strong>0\n<strong>解释:</strong>选出 1 名学生的分数,仅有 1 种方法:\n- [<em><strong>90</strong></em>] 最高分和最低分之间的差值是 90 - 90 = 0\n可能的最小差值是 0\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>nums = [9,4,1,7], k = 2\n<strong>输出:</strong>2\n<strong>解释:</strong>选出 2 名学生的分数,有 6 种方法:\n- [<em><strong>9</strong></em>,<em><strong>4</strong></em>,1,7] 最高分和最低分之间的差值是 9 - 4 = 5\n- [<em><strong>9</strong></em>,4,<em><strong>1</strong></em>,7] 最高分和最低分之间的差值是 9 - 1 = 8\n- [<em><strong>9</strong></em>,4,1,<em><strong>7</strong></em>] 最高分和最低分之间的差值是 9 - 7 = 2\n- [9,<em><strong>4</strong></em>,<em><strong>1</strong></em>,7] 最高分和最低分之间的差值是 4 - 1 = 3\n- [9,<em><strong>4</strong></em>,1,<em><strong>7</strong></em>] 最高分和最低分之间的差值是 7 - 4 = 3\n- [9,4,<em><strong>1</strong></em>,<em><strong>7</strong></em>] 最高分和最低分之间的差值是 7 - 1 = 6\n可能的最小差值是 2</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= k &lt;= nums.length &lt;= 1000</code></li>\n <li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>排序</li><li>滑动窗口</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><p>排序后,使用滑动窗口</p>\n<div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int minimumDifference(int[] nums, int k) &#123;\n Arrays.sort(nums);\n int min &#x3D; Integer.MAX_VALUE;\n for (int i &#x3D; 0; i &lt;&#x3D; nums.length - k; i++) &#123;\n min &#x3D; Math.min(min, nums[i + k - 1] - nums[i]);\n &#125;\n return min;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -&gt; int:\n if k &gt; 1:\n num &#x3D; sorted(nums)\n return min(num[i + k - 1] - num[i] for i in range(len(num) - k + 1))\n else:\n return 0</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"个人网站加入到搜索引擎中","slug":"putWebsiteToSearchEngine","date":"2022-02-08T10:26:58.000Z","updated":"2023-02-07T07:18:09.140Z","comments":true,"path":"/post/putWebsiteToSearchEngine/","link":"","excerpt":"","content":"<p>一般来说,搜索引擎中是不会收入你个人网站的,你可以试试用谷歌或者百度等其他搜索引擎看看,能不能收到你个人网站的相关页面?<br>如果搜索不到,你可以申请加入搜索引擎,这个是免费的,下面提供一些搜索引擎的提交地址:</p>\n<ul>\n<li>谷歌博客搜索收录入口:<br><a href=\"http://www.google.com/addurl/\">http://www.google.com/addurl/</a></li>\n<li>百度收录入口:<br><a href=\"http://www.baidu.com/search/url_submit.html\">http://www.baidu.com/search/url_submit.html</a></li>\n<li>必应Bing收录入口:<br><a href=\"https://www.bing.com/toolbox/submit-site-url\">https://www.bing.com/toolbox/submit-site-url</a></li>\n<li>360搜索引擎登录入口<br><a href=\"http://info.so.360.cn/site_submit.html\">http://info.so.360.cn/site_submit.html</a></li>\n<li>搜狗提交入口:<br><a href=\"http://www.sogou.com/feedback/urlfeedback.php\">http://www.sogou.com/feedback/urlfeedback.php</a></li>\n</ul>\n<p>目前,我所知道的就只有,如果你有其他搜索引擎的提交地址,可以在评论区中留下搜索引擎名称和地址,万分感谢!</p>\n","categories":[{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/categories/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}],"tags":[{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/tags/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"}]},{"title":"力扣1219:黄金矿工","slug":"day20220205","date":"2022-02-06T04:37:26.000Z","updated":"2024-04-25T08:10:09.087Z","comments":true,"path":"/post/day20220205/","link":"","excerpt":"","content":"<p>2022年02月05日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>你要开发一座金矿,地质勘测学家已经探明了这座金矿中的资源分布,并用大小为&nbsp;<code>m * n</code> 的网格 <code>grid</code> 进行了标注。每个单元格中的整数就表示这一单元格中的黄金数量;如果该单元格是空的,那么就是 <code>0</code>。</p>\n\n<p>为了使收益最大化,矿工需要按以下规则来开采黄金:</p>\n\n<ul>\n <li>每当矿工进入一个单元,就会收集该单元格中的所有黄金。</li>\n <li>矿工每次可以从当前位置向上下左右四个方向走。</li>\n <li>每个单元格只能被开采(进入)一次。</li>\n <li><strong>不得开采</strong>(进入)黄金数目为 <code>0</code> 的单元格。</li>\n <li>矿工可以从网格中 <strong>任意一个</strong> 有黄金的单元格出发或者是停止。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>grid = [[0,6,0],[5,8,7],[0,9,0]]\n<strong>输出:</strong>24\n<strong>解释:</strong>\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\n一种收集最多黄金的路线是9 -&gt; 8 -&gt; 7。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\n<strong>输出:</strong>28\n<strong>解释:</strong>\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\n一种收集最多黄金的路线是1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5 -&gt; 6 -&gt; 7。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= grid.length,&nbsp;grid[i].length &lt;= 15</code></li>\n <li><code>0 &lt;= grid[i][j] &lt;= 100</code></li>\n <li>最多 <strong>25 </strong>个单元格中有黄金。</li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>回溯</li><li>矩阵</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n int[] xl &#x3D; new int[]&#123;1, -1, 0, 0&#125;;\n int[] yl &#x3D; new int[]&#123;0, 0, 1, -1&#125;;\n public int getMaximumGold(int[][] grid) &#123;\n int counts &#x3D; 0;\n boolean[][] use &#x3D; new boolean[grid.length][grid[0].length];\n for (int i &#x3D; 0; i &lt; grid.length; i++) &#123;\n for (int j &#x3D; 0; j &lt; grid[0].length; j++) &#123;\n use[i][j] &#x3D; true;\n counts &#x3D; Math.max(counts, dfs(i, j, grid, use));\n use[i][j] &#x3D; false;\n &#125;\n &#125;\n return counts;\n &#125;\n private int dfs(int x, int y, int[][] grid, boolean[][] use) &#123;\n int counts &#x3D; grid[x][y];\n for (int i &#x3D; 0; i &lt; 4; i++) &#123;\n int nx &#x3D; x + xl[i];\n int ny &#x3D; y + yl[i];\n if (nx &lt; 0 || nx &gt;&#x3D; grid.length || ny &lt; 0 || ny &gt;&#x3D; grid[0].length || grid[nx][ny] &#x3D;&#x3D; 0 || use[nx][ny]) &#123;\n continue;\n &#125;\n use[nx][ny] &#x3D; true;\n counts &#x3D; Math.max(counts, grid[x][y] + dfs(nx, ny, grid, use));\n use[nx][ny] &#x3D; false;\n &#125;\n return counts;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def getMaximumGold(self, grid: List[List[int]]) -&gt; int:\n def dfs(x: int, y: int) -&gt; int:\n count &#x3D; grid[x][y]\n for nx, ny in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):\n if nx &lt; 0 or nx &gt;&#x3D; len(grid) or ny &lt; 0 or ny &gt;&#x3D; len(grid[0]) or grid[nx][ny] &#x3D;&#x3D; 0 or use[nx][ny]:\n continue\n use[nx][ny] &#x3D; True\n count &#x3D; max(count, grid[x][y] + dfs(nx, ny))\n use[nx][ny] &#x3D; False\n return count\n\n counts &#x3D; 0\n # 这种形式下,给一个元素赋值,对应的所有行相同列都会赋值\n # use &#x3D; [[False] * len(grid[0])] * len(grid)\n use &#x3D; [[False] * len(grid[0]) for _ in range(len(grid))]\n for i in range(len(grid)):\n for j in range(len(grid[0])):\n if grid[i][j] !&#x3D; 0:\n use[i][j] &#x3D; True\n counts &#x3D; max(counts, dfs(i, j))\n use[i][j] &#x3D; False\n return counts</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣1725:可以形成最大正方形的矩形数目","slug":"day20220204","date":"2022-02-04T14:50:47.000Z","updated":"2024-04-25T08:10:09.086Z","comments":true,"path":"/post/day20220204/","link":"","excerpt":"","content":"<p>2022年02月04日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个数组 <code>rectangles</code> ,其中 <code>rectangles[i] = [l<sub>i</sub>, w<sub>i</sub>]</code> 表示第 <code>i</code> 个矩形的长度为 <code>l<sub>i</sub></code> 、宽度为 <code>w<sub>i</sub></code> 。</p>\n\n<p>如果存在 <code>k</code> 同时满足 <code>k <= l<sub>i</sub></code> 和 <code>k <= w<sub>i</sub></code> ,就可以将第 <code>i</code> 个矩形切成边长为 <code>k</code> 的正方形。例如,矩形 <code>[4,6]</code> 可以切成边长最大为 <code>4</code> 的正方形。</p>\n\n<p>设 <code>maxLen</code> 为可以从矩形数组 <code>rectangles</code> 切分得到的 <strong>最大正方形</strong> 的边长。</p>\n\n<p>请你统计有多少个矩形能够切出边长为<em> </em><code>maxLen</code> 的正方形,并返回矩形 <strong>数目</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>rectangles = [[5,8],[3,9],[5,12],[16,5]]\n<strong>输出:</strong>3\n<strong>解释:</strong>能从每个矩形中切出的最大正方形边长分别是 [5,3,5,5] 。\n最大正方形的边长为 5 ,可以由 3 个矩形切分得到。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>rectangles = [[2,3],[3,7],[4,3],[3,7]]\n<strong>输出:</strong>3\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 <= rectangles.length <= 1000</code></li>\n <li><code>rectangles[i].length == 2</code></li>\n <li><code>1 <= l<sub>i</sub>, w<sub>i</sub> <= 10<sup>9</sup></code></li>\n <li><code>l<sub>i</sub> != w<sub>i</sub></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int countGoodRectangles(int[][] rectangles) &#123;\n int maxLength &#x3D; 0;\n int count &#x3D; 0;\n for (int[] rectangle : rectangles) &#123;\n int temp &#x3D; Math.min(rectangle[0], rectangle[1]);\n if (temp &#x3D;&#x3D; maxLength) &#123;\n count++;\n &#125; else if (temp &gt; maxLength) &#123;\n count &#x3D; 1;\n maxLength &#x3D; temp;\n &#125;\n &#125;\n return count;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def countGoodRectangles(self, rectangles: List[List[int]]) -&gt; int:\n maxLength &#x3D; 0\n count &#x3D; 0\n for rectangle in rectangles:\n temp &#x3D; min(rectangle[0], rectangle[1])\n if temp &#x3D;&#x3D; maxLength:\n count &#x3D; count + 1\n elif temp &gt; maxLength:\n count &#x3D; 1\n maxLength &#x3D; temp\n return count</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"seata1.4.1服务端部署及应用","slug":"seata141demo","date":"2022-02-02T01:37:59.000Z","updated":"2022-09-22T07:39:53.204Z","comments":true,"path":"/post/seata141demo/","link":"","excerpt":"","content":"<h1 id=\"seata1-4-1服务端部署及应用\"><a href=\"#seata1-4-1服务端部署及应用\" class=\"headerlink\" title=\"seata1.4.1服务端部署及应用\"></a>seata1.4.1服务端部署及应用</h1><p>springcloud-nacos-seata</p>\n<p><strong>分布式事务组件seata的使用demoAT模式集成nacos、springboot、springcloud、mybatis-plus、feign数据库采用mysql</strong></p>\n<p>demo中使用的相关版本号具体请看代码。如果搭建个人demo不成功验证是否是由版本导致由于目前这几个项目更新比较频繁版本稍有变化便会出现许多奇怪问题</p>\n<ul>\n<li>seata 1.4.1</li>\n<li>spring-cloud-alibaba-seata 2.2.0.RELEASE</li>\n<li>spring-cloud-starter-alibaba-nacos-discovery 2.1.1.RELEASE</li>\n<li>springboot 2.1.10.RELEASE</li>\n<li>springcloud Greenwich.SR4</li>\n</ul>\n<hr>\n<h1 id=\"1-服务端配置\"><a href=\"#1-服务端配置\" class=\"headerlink\" title=\"1. 服务端配置\"></a>1. 服务端配置</h1><p>seata-server为release版本1.4.1采用docker部署方式</p>\n<p><a href=\"https://github.com/seata/seata/releases/tag/v1.4.1\">https://github.com/seata/seata/releases/tag/v1.4.1</a>)</p>\n<h2 id=\"1-1-docker拉取镜像\"><a href=\"#1-1-docker拉取镜像\" class=\"headerlink\" title=\"1.1 docker拉取镜像\"></a>1.1 docker拉取镜像</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull seataio&#x2F;seata-server:1.4.1</code></pre>\n<h2 id=\"1-2-启动临时容器\"><a href=\"#1-2-启动临时容器\" class=\"headerlink\" title=\"1.2 启动临时容器\"></a>1.2 启动临时容器</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker run --rm --name seata-server -d -p 8091:8091 seataio&#x2F;seata-server:1.4.1</code></pre>\n<p><img src=\"https://file.huangge1199.cn/group1/M00/00/00/CgAYB2H54oaAImNHAAAUub2sTS4448.png\" alt=\"\"></p>\n<h2 id=\"1-3-将配置文件拷贝出来\"><a href=\"#1-3-将配置文件拷贝出来\" class=\"headerlink\" title=\"1.3 将配置文件拷贝出来\"></a>1.3 将配置文件拷贝出来</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker cp d5cd81d60189:&#x2F;seata-server&#x2F;resources&#x2F; .&#x2F;conf&#x2F;</code></pre>\n<h2 id=\"1-4-修改conf-registry-conf文件\"><a href=\"#1-4-修改conf-registry-conf文件\" class=\"headerlink\" title=\"1.4 修改conf/registry.conf文件\"></a>1.4 修改conf/registry.conf文件</h2><p>修改文件用nacos做注册中心和配置中心</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi .&#x2F;conf&#x2F;registry.conf</code></pre>\n<p>原始内容:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">registry &#123;\n # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa\n type &#x3D; &quot;file&quot;\n loadBalance &#x3D; &quot;RandomLoadBalance&quot;\n loadBalanceVirtualNodes &#x3D; 10\n\n nacos &#123;\n application &#x3D; &quot;seata-server&quot;\n serverAddr &#x3D; &quot;127.0.0.1:8848&quot;\n group &#x3D; &quot;SEATA_GROUP&quot;\n namespace &#x3D; &quot;&quot;\n cluster &#x3D; &quot;default&quot;\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n eureka &#123;\n serviceUrl &#x3D; &quot;http:&#x2F;&#x2F;localhost:8761&#x2F;eureka&quot;\n application &#x3D; &quot;default&quot;\n weight &#x3D; &quot;1&quot;\n &#125;\n redis &#123;\n serverAddr &#x3D; &quot;localhost:6379&quot;\n db &#x3D; 0\n password &#x3D; &quot;&quot;\n cluster &#x3D; &quot;default&quot;\n timeout &#x3D; 0\n &#125;\n zk &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;127.0.0.1:2181&quot;\n sessionTimeout &#x3D; 6000\n connectTimeout &#x3D; 2000\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n consul &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;127.0.0.1:8500&quot;\n &#125;\n etcd3 &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;http:&#x2F;&#x2F;localhost:2379&quot;\n &#125;\n sofa &#123;\n serverAddr &#x3D; &quot;127.0.0.1:9603&quot;\n application &#x3D; &quot;default&quot;\n region &#x3D; &quot;DEFAULT_ZONE&quot;\n datacenter &#x3D; &quot;DefaultDataCenter&quot;\n cluster &#x3D; &quot;default&quot;\n group &#x3D; &quot;SEATA_GROUP&quot;\n addressWaitTime &#x3D; &quot;3000&quot;\n &#125;\n file &#123;\n name &#x3D; &quot;file.conf&quot;\n &#125;\n&#125;\n\nconfig &#123;\n # file、nacos 、apollo、zk、consul、etcd3\n type &#x3D; &quot;file&quot;\n\n nacos &#123;\n serverAddr &#x3D; &quot;127.0.0.1:8848&quot;\n namespace &#x3D; &quot;&quot;\n group &#x3D; &quot;SEATA_GROUP&quot;\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n consul &#123;\n serverAddr &#x3D; &quot;127.0.0.1:8500&quot;\n &#125;\n apollo &#123;\n appId &#x3D; &quot;seata-server&quot;\n apolloMeta &#x3D; &quot;http:&#x2F;&#x2F;192.168.1.204:8801&quot;\n namespace &#x3D; &quot;application&quot;\n apolloAccesskeySecret &#x3D; &quot;&quot;\n &#125;\n zk &#123;\n serverAddr &#x3D; &quot;127.0.0.1:2181&quot;\n sessionTimeout &#x3D; 6000\n connectTimeout &#x3D; 2000\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n etcd3 &#123;\n serverAddr &#x3D; &quot;http:&#x2F;&#x2F;localhost:2379&quot;\n &#125;\n file &#123;\n name &#x3D; &quot;file.conf&quot;\n &#125;\n&#125;\n</code></pre>\n<p>修改后的内容:</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">registry &#123;\n # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa\n type &#x3D; &quot;nacos&quot; # 改为nacos\n loadBalance &#x3D; &quot;RandomLoadBalance&quot;\n loadBalanceVirtualNodes &#x3D; 10\n\n nacos &#123;\n application &#x3D; &quot;seata-server&quot;\n serverAddr &#x3D; &quot;IP:端口&quot; # 改为nacos实际的IP:端口\n group &#x3D; &quot;SEATA_GROUP&quot;\n namespace &#x3D; &quot;&quot;\n cluster &#x3D; &quot;default&quot;\n username &#x3D; &quot;nacos&quot; # 改为nacos的账号\n password &#x3D; &quot;nacos&quot; # 改为nacos的密码\n &#125;\n eureka &#123;\n serviceUrl &#x3D; &quot;http:&#x2F;&#x2F;localhost:8761&#x2F;eureka&quot;\n application &#x3D; &quot;default&quot;\n weight &#x3D; &quot;1&quot;\n &#125;\n redis &#123;\n serverAddr &#x3D; &quot;localhost:6379&quot;\n db &#x3D; 0\n password &#x3D; &quot;&quot;\n cluster &#x3D; &quot;default&quot;\n timeout &#x3D; 0\n &#125;\n zk &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;127.0.0.1:2181&quot;\n sessionTimeout &#x3D; 6000\n connectTimeout &#x3D; 2000\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n consul &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;127.0.0.1:8500&quot;\n &#125;\n etcd3 &#123;\n cluster &#x3D; &quot;default&quot;\n serverAddr &#x3D; &quot;http:&#x2F;&#x2F;localhost:2379&quot;\n &#125;\n sofa &#123;\n serverAddr &#x3D; &quot;127.0.0.1:9603&quot;\n application &#x3D; &quot;default&quot;\n region &#x3D; &quot;DEFAULT_ZONE&quot;\n datacenter &#x3D; &quot;DefaultDataCenter&quot;\n cluster &#x3D; &quot;default&quot;\n group &#x3D; &quot;SEATA_GROUP&quot;\n addressWaitTime &#x3D; &quot;3000&quot;\n &#125;\n file &#123;\n name &#x3D; &quot;file.conf&quot;\n &#125;\n&#125;\n\nconfig &#123;\n # file、nacos 、apollo、zk、consul、etcd3\n type &#x3D; &quot;nacos&quot; # 改为nacos\n\n nacos &#123;\n serverAddr &#x3D; &quot;IP:端口&quot; # 改为nacos实际的IP:端口\n namespace &#x3D; &quot;&quot;\n group &#x3D; &quot;SEATA_GROUP&quot;\n username &#x3D; &quot;nacos&quot; # 改为nacos的账号\n password &#x3D; &quot;nacos&quot; # 改为nacos的密码\n &#125;\n consul &#123;\n serverAddr &#x3D; &quot;127.0.0.1:8500&quot;\n &#125;\n apollo &#123;\n appId &#x3D; &quot;seata-server&quot;\n apolloMeta &#x3D; &quot;http:&#x2F;&#x2F;192.168.1.204:8801&quot;\n namespace &#x3D; &quot;application&quot;\n apolloAccesskeySecret &#x3D; &quot;&quot;\n &#125;\n zk &#123;\n serverAddr &#x3D; &quot;127.0.0.1:2181&quot;\n sessionTimeout &#x3D; 6000\n connectTimeout &#x3D; 2000\n username &#x3D; &quot;&quot;\n password &#x3D; &quot;&quot;\n &#125;\n etcd3 &#123;\n serverAddr &#x3D; &quot;http:&#x2F;&#x2F;localhost:2379&quot;\n &#125;\n file &#123;\n name &#x3D; &quot;file.conf&quot;\n &#125;\n&#125;\n</code></pre>\n<h2 id=\"1-5-执行SQL语句\"><a href=\"#1-5-执行SQL语句\" class=\"headerlink\" title=\"1.5 执行SQL语句\"></a>1.5 执行SQL语句</h2><p>seata配置使用db事务日志存储方式</p>\n<p>SQL文件下载地址<a href=\"https://github.com/seata/seata/tree/develop/script/server/db\">seata/script/server/db at develop · seata/seata (github.com)</a></p>\n<h2 id=\"1-6-创建config-txt并修改\"><a href=\"#1-6-创建config-txt并修改\" class=\"headerlink\" title=\"1.6 创建config.txt并修改\"></a>1.6 创建config.txt并修改</h2><p>config.txt文件地址<a href=\"https://github.com/seata/seata/blob/develop/script/config-center/config.txt\">seata/config.txt at develop · seata/seata (github.com)</a></p>\n<p>config.txt原件</p>\n<pre class=\"line-numbers language-properties\" data-language=\"properties\"><code class=\"language-properties\">transport.type&#x3D;TCP\ntransport.server&#x3D;NIO\ntransport.heartbeat&#x3D;true\ntransport.enableClientBatchSendRequest&#x3D;true\ntransport.threadFactory.bossThreadPrefix&#x3D;NettyBoss\ntransport.threadFactory.workerThreadPrefix&#x3D;NettyServerNIOWorker\ntransport.threadFactory.serverExecutorThreadPrefix&#x3D;NettyServerBizHandler\ntransport.threadFactory.shareBossWorker&#x3D;false\ntransport.threadFactory.clientSelectorThreadPrefix&#x3D;NettyClientSelector\ntransport.threadFactory.clientSelectorThreadSize&#x3D;1\ntransport.threadFactory.clientWorkerThreadPrefix&#x3D;NettyClientWorkerThread\ntransport.threadFactory.bossThreadSize&#x3D;1\ntransport.threadFactory.workerThreadSize&#x3D;default\ntransport.shutdown.wait&#x3D;3\nservice.vgroupMapping.my_test_tx_group&#x3D;default\nservice.default.grouplist&#x3D;127.0.0.1:8091\nservice.enableDegrade&#x3D;false\nservice.disableGlobalTransaction&#x3D;false\nclient.rm.asyncCommitBufferLimit&#x3D;10000\nclient.rm.lock.retryInterval&#x3D;10\nclient.rm.lock.retryTimes&#x3D;30\nclient.rm.lock.retryPolicyBranchRollbackOnConflict&#x3D;true\nclient.rm.reportRetryCount&#x3D;5\nclient.rm.tableMetaCheckEnable&#x3D;false\nclient.rm.tableMetaCheckerInterval&#x3D;60000\nclient.rm.sqlParserType&#x3D;druid\nclient.rm.reportSuccessEnable&#x3D;false\nclient.rm.sagaBranchRegisterEnable&#x3D;false\nclient.rm.tccActionInterceptorOrder&#x3D;-2147482648\nclient.tm.commitRetryCount&#x3D;5\nclient.tm.rollbackRetryCount&#x3D;5\nclient.tm.defaultGlobalTransactionTimeout&#x3D;60000\nclient.tm.degradeCheck&#x3D;false\nclient.tm.degradeCheckAllowTimes&#x3D;10\nclient.tm.degradeCheckPeriod&#x3D;2000\nclient.tm.interceptorOrder&#x3D;-2147482648\nstore.mode&#x3D;file\nstore.lock.mode&#x3D;file\nstore.session.mode&#x3D;file\nstore.publicKey&#x3D;\nstore.file.dir&#x3D;file_store&#x2F;data\nstore.file.maxBranchSessionSize&#x3D;16384\nstore.file.maxGlobalSessionSize&#x3D;512\nstore.file.fileWriteBufferCacheSize&#x3D;16384\nstore.file.flushDiskMode&#x3D;async\nstore.file.sessionReloadReadSize&#x3D;100\nstore.db.datasource&#x3D;druid\nstore.db.dbType&#x3D;mysql\nstore.db.driverClassName&#x3D;com.mysql.jdbc.Driver\nstore.db.url&#x3D;jdbc:mysql:&#x2F;&#x2F;127.0.0.1:3306&#x2F;seata?useUnicode&#x3D;true&amp;rewriteBatchedStatements&#x3D;true\nstore.db.user&#x3D;username\nstore.db.password&#x3D;password\nstore.db.minConn&#x3D;5\nstore.db.maxConn&#x3D;30\nstore.db.globalTable&#x3D;global_table\nstore.db.branchTable&#x3D;branch_table\nstore.db.queryLimit&#x3D;100\nstore.db.lockTable&#x3D;lock_table\nstore.db.maxWait&#x3D;5000\nstore.redis.mode&#x3D;single\nstore.redis.single.host&#x3D;127.0.0.1\nstore.redis.single.port&#x3D;6379\nstore.redis.sentinel.masterName&#x3D;\nstore.redis.sentinel.sentinelHosts&#x3D;\nstore.redis.maxConn&#x3D;10\nstore.redis.minConn&#x3D;1\nstore.redis.maxTotal&#x3D;100\nstore.redis.database&#x3D;0\nstore.redis.password&#x3D;\nstore.redis.queryLimit&#x3D;100\nserver.recovery.committingRetryPeriod&#x3D;1000\nserver.recovery.asynCommittingRetryPeriod&#x3D;1000\nserver.recovery.rollbackingRetryPeriod&#x3D;1000\nserver.recovery.timeoutRetryPeriod&#x3D;1000\nserver.maxCommitRetryTimeout&#x3D;-1\nserver.maxRollbackRetryTimeout&#x3D;-1\nserver.rollbackRetryTimeoutUnlockEnable&#x3D;false\nserver.distributedLockExpireTime&#x3D;10000\nclient.undo.dataValidation&#x3D;true\nclient.undo.logSerialization&#x3D;jackson\nclient.undo.onlyCareUpdateColumns&#x3D;true\nserver.undo.logSaveDays&#x3D;7\nserver.undo.logDeletePeriod&#x3D;86400000\nclient.undo.logTable&#x3D;undo_log\nclient.undo.compress.enable&#x3D;true\nclient.undo.compress.type&#x3D;zip\nclient.undo.compress.threshold&#x3D;64k\nlog.exceptionRate&#x3D;100\ntransport.serialization&#x3D;seata\ntransport.compressor&#x3D;none\nmetrics.enabled&#x3D;false\nmetrics.registryType&#x3D;compact\nmetrics.exporterList&#x3D;prometheus\nmetrics.exporterPrometheusPort&#x3D;9898</code></pre>\n<p>这里根据自己需求做调整,我这里的配置如下:</p>\n<pre class=\"line-numbers language-properties\" data-language=\"properties\"><code class=\"language-properties\">service.vgroupMapping.order-service-group&#x3D;default\nservice.vgroupMapping.storage-service-group&#x3D;default\nservice.enableDegrade&#x3D;false\nservice.disableGlobalTransaction&#x3D;false\nstore.mode&#x3D;db\nstore.db.datasource&#x3D;druid\nstore.db.dbType&#x3D;mysql\n#store.db.driverClassName&#x3D;com.mysql.jdbc.Driver 这个是mysql8以下的驱动\nstore.db.driverClassName&#x3D;com.mysql.cj.jdbc.Driver #这个是mysql8的驱动\nstore.db.url&#x3D;jdbc:mysql:&#x2F;&#x2F;192.168.0.1:3306&#x2F;seata?useUnicode&#x3D;true #这个是mysql的连接信息\nstore.db.user&#x3D;root #这个是mysql的用户名\nstore.db.password&#x3D;123456 #这个是mysql的密码\nstore.db.minConn&#x3D;5\nstore.db.maxConn&#x3D;30\nstore.db.globalTable&#x3D;global_table\nstore.db.branchTable&#x3D;branch_table\nstore.db.queryLimit&#x3D;100\nstore.db.lockTable&#x3D;lock_table\nstore.db.maxWait&#x3D;5000</code></pre>\n<h2 id=\"1-7-创建nacos-config-sh\"><a href=\"#1-7-创建nacos-config-sh\" class=\"headerlink\" title=\"1.7 创建nacos-config.sh\"></a>1.7 创建nacos-config.sh</h2><p>在conf中</p>\n<p>nacos-config.sh获取地址<a href=\"https://github.com/seata/seata/tree/develop/script/config-center/nacos\">seata/script/config-center/nacos at develop · seata/seata (github.com)</a></p>\n<h2 id=\"1-8-上传seata配置信息到nacos\"><a href=\"#1-8-上传seata配置信息到nacos\" class=\"headerlink\" title=\"1.8 上传seata配置信息到nacos\"></a>1.8 上传seata配置信息到nacos</h2><p>先确认目录结构正确</p>\n<p><img src=\"https://file.huangge1199.cn/group1/M00/00/00/CgAYB2H54zyAYKwlAAAi_TSko4g044.png\" alt=\"\"></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">.&#x2F;nacos-config.sh -h docker所在机器IP -p 8848 -g SEATA_GROUP -u nacos -w nacos</code></pre>\n<h4 id=\"1-2-2-修改conf-nacos-config-txt-配置\"><a href=\"#1-2-2-修改conf-nacos-config-txt-配置\" class=\"headerlink\" title=\"1.2.2 修改conf/nacos-config.txt 配置\"></a>1.2.2 修改conf/nacos-config.txt 配置</h4><p>service.vgroup_mapping.${your-service-gruop}=default中间的${your-service-gruop}为自己定义的服务组名称服务中的application.properties文件里配置服务组名称。</p>\n<p>demo中有两个服务分别是storage-service和order-service所以配置如下</p>\n<pre class=\"line-numbers language-properties\" data-language=\"properties\"><code class=\"language-properties\">service.vgroup_mapping.storage-service-group&#x3D;defaultservice.vgroup_mapping.order-service-group&#x3D;default</code></pre>\n<p><strong> 注意这里,高版本中应该是vgroupMapping 同时后面的如: order-service-group 不能定义为 order_service_group</strong></p>\n<h4 id=\"1-3-启动seata-server\"><a href=\"#1-3-启动seata-server\" class=\"headerlink\" title=\"1.3 启动seata-server\"></a>1.3 启动seata-server</h4><p><strong>分两步,如下</strong></p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\"># 初始化seata 的nacos配置cd confsh nacos-config.sh 192.168.21.89# 启动seata-servercd binsh seata-server.sh -p 8091 -m file</code></pre>\n<hr>\n<h1 id=\"2-应用配置\"><a href=\"#2-应用配置\" class=\"headerlink\" title=\"2. 应用配置\"></a>2. 应用配置</h1><h3 id=\"2-1-数据库初始化\"><a href=\"#2-1-数据库初始化\" class=\"headerlink\" title=\"2.1 数据库初始化\"></a>2.1 数据库初始化</h3><pre class=\"line-numbers language-SQL\" data-language=\"SQL\"><code class=\"language-SQL\">-- 创建 order库、业务表、undo_log表create database seata_order;use seata_order;DROP TABLE IF EXISTS &#96;order_tbl&#96;;CREATE TABLE &#96;order_tbl&#96; ( &#96;id&#96; int(11) NOT NULL AUTO_INCREMENT, &#96;user_id&#96; varchar(255) DEFAULT NULL, &#96;commodity_code&#96; varchar(255) DEFAULT NULL, &#96;count&#96; int(11) DEFAULT 0, &#96;money&#96; int(11) DEFAULT 0, PRIMARY KEY (&#96;id&#96;)) ENGINE&#x3D;InnoDB DEFAULT CHARSET&#x3D;utf8;CREATE TABLE &#96;undo_log&#96;( &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT, &#96;branch_id&#96; BIGINT(20) NOT NULL, &#96;xid&#96; VARCHAR(100) NOT NULL, &#96;context&#96; VARCHAR(128) NOT NULL, &#96;rollback_info&#96; LONGBLOB NOT NULL, &#96;log_status&#96; INT(11) NOT NULL, &#96;log_created&#96; DATETIME NOT NULL, &#96;log_modified&#96; DATETIME NOT NULL, &#96;ext&#96; VARCHAR(100) DEFAULT NULL, PRIMARY KEY (&#96;id&#96;), UNIQUE KEY &#96;ux_undo_log&#96; (&#96;xid&#96;, &#96;branch_id&#96;)) ENGINE &#x3D; InnoDB AUTO_INCREMENT &#x3D; 1 DEFAULT CHARSET &#x3D; utf8;-- 创建 storage库、业务表、undo_log表create database seata_storage;use seata_storage;DROP TABLE IF EXISTS &#96;storage_tbl&#96;;CREATE TABLE &#96;storage_tbl&#96; ( &#96;id&#96; int(11) NOT NULL AUTO_INCREMENT, &#96;commodity_code&#96; varchar(255) DEFAULT NULL, &#96;count&#96; int(11) DEFAULT 0, PRIMARY KEY (&#96;id&#96;), UNIQUE KEY (&#96;commodity_code&#96;)) ENGINE&#x3D;InnoDB DEFAULT CHARSET&#x3D;utf8;CREATE TABLE &#96;undo_log&#96;( &#96;id&#96; BIGINT(20) NOT NULL AUTO_INCREMENT, &#96;branch_id&#96; BIGINT(20) NOT NULL, &#96;xid&#96; VARCHAR(100) NOT NULL, &#96;context&#96; VARCHAR(128) NOT NULL, &#96;rollback_info&#96; LONGBLOB NOT NULL, &#96;log_status&#96; INT(11) NOT NULL, &#96;log_created&#96; DATETIME NOT NULL, &#96;log_modified&#96; DATETIME NOT NULL, &#96;ext&#96; VARCHAR(100) DEFAULT NULL, PRIMARY KEY (&#96;id&#96;), UNIQUE KEY &#96;ux_undo_log&#96; (&#96;xid&#96;, &#96;branch_id&#96;)) ENGINE &#x3D; InnoDB AUTO_INCREMENT &#x3D; 1 DEFAULT CHARSET &#x3D; utf8;-- 初始化库存模拟数据INSERT INTO seata_storage.storage_tbl (id, commodity_code, count) VALUES (1, &#39;product-1&#39;, 9999999);INSERT INTO seata_storage.storage_tbl (id, commodity_code, count) VALUES (2, &#39;product-2&#39;, 0);</code></pre>\n<h3 id=\"2-2-应用配置\"><a href=\"#2-2-应用配置\" class=\"headerlink\" title=\"2.2 应用配置\"></a>2.2 应用配置</h3><p>见代码</p>\n<p>几个重要的配置</p>\n<ol>\n<li>每个应用的resource里需要配置一个registry.conf demo中与seata-server里的配置相同</li>\n<li>application.propeties 的各个配置项注意spring.cloud.alibaba.seata.tx-service-group 是服务组名称与nacos-config.txt 配置的service.vgroup_mapping.${your-service-gruop}具有对应关系</li>\n</ol>\n<hr>\n<h1 id=\"3-测试\"><a href=\"#3-测试\" class=\"headerlink\" title=\"3. 测试\"></a>3. 测试</h1><ol>\n<li><p>分布式事务成功,模拟正常下单、扣库存</p>\n<p>localhost:9091/order/placeOrder/commit</p>\n</li>\n<li><p>分布式事务失败,模拟下单成功、扣库存失败,最终同时回滚</p>\n<p>localhost:9091/order/placeOrder/rollback </p>\n</li>\n</ol>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"seata","slug":"java/seata","permalink":"https://hexo.huangge1199.cn/categories/java/seata/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"seata","slug":"seata","permalink":"https://hexo.huangge1199.cn/tags/seata/"}]},{"title":"力扣1688:比赛中的配对次数","slug":"day20220125","date":"2022-01-25T05:57:48.000Z","updated":"2024-04-25T08:10:09.084Z","comments":true,"path":"/post/day20220125/","link":"","excerpt":"","content":"<p>2022年01月25日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个整数 <code>n</code> ,表示比赛中的队伍数。比赛遵循一种独特的赛制:</p>\n\n<ul>\n <li>如果当前队伍数是 <strong>偶数</strong> ,那么每支队伍都会与另一支队伍配对。总共进行 <code>n / 2</code> 场比赛,且产生 <code>n / 2</code> 支队伍进入下一轮。</li>\n <li>如果当前队伍数为 <strong>奇数</strong> ,那么将会随机轮空并晋级一支队伍,其余的队伍配对。总共进行 <code>(n - 1) / 2</code> 场比赛,且产生 <code>(n - 1) / 2 + 1</code> 支队伍进入下一轮。</li>\n</ul>\n\n<p>返回在比赛中进行的配对次数,直到决出获胜队伍为止。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>n = 7\n<strong>输出:</strong>6\n<strong>解释:</strong>比赛详情:\n- 第 1 轮:队伍数 = 7 ,配对次数 = 3 4 支队伍晋级。\n- 第 2 轮:队伍数 = 4 ,配对次数 = 2 2 支队伍晋级。\n- 第 3 轮:队伍数 = 2 ,配对次数 = 1 ,决出 1 支获胜队伍。\n总配对次数 = 3 + 2 + 1 = 6\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>n = 14\n<strong>输出:</strong>13\n<strong>解释:</strong>比赛详情:\n- 第 1 轮:队伍数 = 14 ,配对次数 = 7 7 支队伍晋级。\n- 第 2 轮:队伍数 = 7 ,配对次数 = 3 4 支队伍晋级。 \n- 第 3 轮:队伍数 = 4 ,配对次数 = 2 2 支队伍晋级。\n- 第 4 轮:队伍数 = 2 ,配对次数 = 1 ,决出 1 支获胜队伍。\n总配对次数 = 7 + 3 + 2 + 1 = 13\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= n &lt;= 200</code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数学</li><li>模拟</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public int numberOfMatches(int n) &#123;\n &#x2F;&#x2F; 总配对次数\n int sum &#x3D; 0;\n while (n &gt; 1) &#123;\n if (n % 2 &#x3D;&#x3D; 1) &#123;\n &#x2F;&#x2F; 奇数队伍\n &#x2F;&#x2F; 配对次数:(n - 1) &#x2F; 2\n sum +&#x3D; (n - 1) &#x2F; 2;\n &#x2F;&#x2F; 剩余队伍数:(n - 1) &#x2F; 2 + 1\n n &#x3D; (n - 1) &#x2F; 2 + 1;\n &#125; else &#123;\n &#x2F;&#x2F; 偶数队伍\n &#x2F;&#x2F; 配对次数n &#x2F; 2\n sum +&#x3D; n &#x2F; 2;\n &#x2F;&#x2F; 剩余队伍数n &#x2F; 2\n n &#x2F;&#x3D; 2;\n &#125;\n &#125;\n return sum;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">class Solution:\n def numberOfMatches(self, n: int) -&gt; int:\n # 总配对次数\n sums &#x3D; 0\n while n &gt; 1:\n if n % 2 &#x3D;&#x3D; 1:\n # 奇数队伍\n # 配对次数:(n - 1) &#x2F; 2\n sums +&#x3D; (n - 1) &#x2F; 2\n # 剩余队伍数:(n - 1) &#x2F; 2 + 1\n n &#x3D; (n - 1) &#x2F; 2 + 1\n else:\n # 偶数队伍\n # 配对次数n &#x2F; 2\n sums +&#x3D; n &#x2F; 2\n # 剩余队伍数n &#x2F; 2\n n &#x2F;&#x3D; 2\n return int(sums)</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2045:到达目的地的第二短时间","slug":"day20220124","date":"2022-01-24T07:22:58.000Z","updated":"2024-04-25T08:10:09.083Z","comments":true,"path":"/post/day20220124/","link":"","excerpt":"","content":"<p>2022年01月24日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>城市用一个 <strong>双向连通</strong> 图表示,图中有 <code>n</code> 个节点,从 <code>1</code> 到 <code>n</code> 编号(包含 <code>1</code> 和 <code>n</code>)。图中的边用一个二维整数数组 <code>edges</code> 表示,其中每个 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code>&nbsp;表示一条节点&nbsp;<code>u<sub>i</sub></code> 和节点&nbsp;<code>v<sub>i</sub></code> 之间的双向连通边。每组节点对由 <strong>最多一条</strong> 边连通,顶点不存在连接到自身的边。穿过任意一条边的时间是 <code>time</code>&nbsp;分钟。</p>\n\n<p>每个节点都有一个交通信号灯,每 <code>change</code> 分钟改变一次,从绿色变成红色,再由红色变成绿色,循环往复。所有信号灯都&nbsp;<strong>同时</strong> 改变。你可以在 <strong>任何时候</strong> 进入某个节点,但是 <strong>只能</strong> 在节点&nbsp;<strong>信号灯是绿色时</strong> 才能离开。如果信号灯是&nbsp; <strong>绿色</strong> ,你 <strong>不能</strong> 在节点等待,必须离开。</p>\n\n<p><strong>第二小的值</strong> 是&nbsp;<strong>严格大于</strong> 最小值的所有值中最小的值。</p>\n\n<ul>\n <li>例如,<code>[2, 3, 4]</code> 中第二小的值是 <code>3</code> ,而 <code>[2, 2, 4]</code> 中第二小的值是 <code>4</code> 。</li>\n</ul>\n\n<p>给你 <code>n</code>、<code>edges</code>、<code>time</code> 和 <code>change</code> ,返回从节点 <code>1</code> 到节点 <code>n</code> 需要的 <strong>第二短时间</strong> 。</p>\n\n<p><strong>注意:</strong></p>\n\n<ul>\n <li>你可以 <strong>任意次</strong> 穿过任意顶点,<strong>包括</strong> <code>1</code> 和 <code>n</code> 。</li>\n <li>你可以假设在 <strong>启程时</strong> ,所有信号灯刚刚变成 <strong>绿色</strong> 。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/29/e1.png\" style=\"width: 200px; height: 250px;\" /> <img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/29/e2.png\" style=\"width: 200px; height: 250px;\" /></p>\n\n<pre>\n<strong>输入:</strong>n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5\n<strong>输出:</strong>13\n<strong>解释:</strong>\n上面的左图展现了给出的城市交通图。\n右图中的蓝色路径是最短时间路径。\n花费的时间是\n- 从节点 1 开始,总花费时间=0\n- 1 -&gt; 43 分钟,总花费时间=3\n- 4 -&gt; 53 分钟,总花费时间=6\n因此需要的最小时间是 6 分钟。\n\n右图中的红色路径是第二短时间路径。\n- 从节点 1 开始,总花费时间=0\n- 1 -&gt; 33 分钟,总花费时间=3\n- 3 -&gt; 43 分钟,总花费时间=6\n- 在节点 4 等待 4 分钟,总花费时间=10\n- 4 -&gt; 53 分钟,总花费时间=13\n因此第二短时间是 13 分钟。 \n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/29/eg2.png\" style=\"width: 225px; height: 50px;\" /></p>\n\n<pre>\n<strong>输入:</strong>n = 2, edges = [[1,2]], time = 3, change = 2\n<strong>输出:</strong>11\n<strong>解释:</strong>\n最短时间路径是 1 -&gt; 2 ,总花费时间 = 3 分钟\n最短时间路径是 1 -&gt; 2 -&gt; 1 -&gt; 2 ,总花费时间 = 11 分钟</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>2 &lt;= n &lt;= 10<sup>4</sup></code></li>\n <li><code>n - 1 &lt;= edges.length &lt;= min(2 * 10<sup>4</sup>, n * (n - 1) / 2)</code></li>\n <li><code>edges[i].length == 2</code></li>\n <li><code>1 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n</code></li>\n <li><code>u<sub>i</sub> != v<sub>i</sub></code></li>\n <li>不含重复边</li>\n <li>每个节点都可以从其他节点直接或者间接到达</li>\n <li><code>1 &lt;= time, change &lt;= 10<sup>3</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>广度优先搜索</li><li>图</li><li>最短路</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.*;\n\nclass Solution &#123;\n public int secondMinimum(int n, int[][] edges, int time, int change) &#123;\n &#x2F;&#x2F; 统计所有节点的联通节点并将其存入map中留着后面使用\n Map&lt;Integer, List&lt;Integer&gt;&gt; map &#x3D; new HashMap&lt;&gt;(n);\n for (int i &#x3D; 1; i &lt;&#x3D; n; i++) &#123;\n map.put(i, new ArrayList&lt;&gt;());\n &#125;\n for (int[] edge : edges) &#123;\n map.get(edge[0]).add(edge[1]);\n map.get(edge[1]).add(edge[0]);\n &#125;\n Queue&lt;Integer&gt; queue &#x3D; new LinkedList&lt;&gt;();\n queue.add(1);\n &#x2F;&#x2F; 记录节点到达的次数\n int[] counts &#x3D; new int[n + 1];\n &#x2F;&#x2F; 记录到达节点的时间\n int free &#x3D; 0;\n while (!queue.isEmpty()) &#123;\n &#x2F;&#x2F; 红灯情况下加上需要等待的时间\n if (free % (2 * change) &gt;&#x3D; change) &#123;\n free +&#x3D; change - free % change;\n &#125;\n free +&#x3D; time;\n &#x2F;&#x2F; 同一时间可以到达的节点数量\n int size &#x3D; queue.size();\n &#x2F;&#x2F; 同一时间节点是否已经到达\n boolean[] use &#x3D; new boolean[n + 1];\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n &#x2F;&#x2F; 获取该节点接下来可以到达的节点\n List&lt;Integer&gt; list &#x3D; map.get(queue.poll());\n for (int num : list) &#123;\n &#x2F;&#x2F; 同一时间未到达并且到达该节点的总次数小于2\n if (!use[num] &amp;&amp; counts[num] &lt; 2) &#123;\n queue.add(num);\n use[num] &#x3D; true;\n counts[num]++;\n &#125;\n &#x2F;&#x2F; 如果是第二次到达最后一个节点,直接返回需要到达的诗句\n if (num &#x3D;&#x3D; n &amp;&amp; counts[num] &#x3D;&#x3D; 2) &#123;\n return free;\n &#125;\n &#125;\n &#125;\n &#125;\n return 0;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from collections import deque\nfrom typing import List\n\n\nclass Solution:\n def secondMinimum(self, n: int, edges: List[List[int]], time: int, change: int) -&gt; int:\n # 统计所有节点的联通节点并将其存入map中留着后面使用\n maps &#x3D; [[0] for _ in range(n + 1)]\n for edge in edges:\n maps[edge[0]].append(edge[1])\n maps[edge[1]].append(edge[0])\n queue &#x3D; deque()\n queue.append(1)\n # 记录节点到达的次数\n counts &#x3D; [0] * (n + 1)\n # 记录到达节点的时间\n free &#x3D; 0\n while len(queue):\n # 红灯情况下加上需要等待的时间\n if free % (2 * change) &gt;&#x3D; change:\n free +&#x3D; change - free % change\n free +&#x3D; time\n # 同一时间可以到达的节点数量\n size &#x3D; len(queue)\n # 同一时间节点是否已经到达\n use &#x3D; [False] * (n + 1)\n for i in range(size):\n for num in maps[queue.popleft()]:\n # 同一时间未到达并且到达该节点的总次数小于2\n if use[num] is False and counts[num] &lt; 2:\n queue.append(num)\n use[num] &#x3D; True\n counts[num] +&#x3D; 1\n\n # 如果是第二次到达最后一个节点,直接返回需要到达的诗句\n if num &#x3D;&#x3D; n and counts[num] &#x3D;&#x3D; 2:\n return free\n return 0</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣1345:跳跃游戏 IV","slug":"day20220121","date":"2022-01-21T08:26:26.000Z","updated":"2024-04-25T08:10:09.081Z","comments":true,"path":"/post/day20220121/","link":"","excerpt":"","content":"<p>2022年01月21日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个整数数组&nbsp;<code>arr</code>&nbsp;,你一开始在数组的第一个元素处(下标为 0。</p>\n\n<p>每一步,你可以从下标&nbsp;<code>i</code>&nbsp;跳到下标:</p>\n\n<ul>\n <li><code>i + 1</code>&nbsp;满足:<code>i + 1 &lt; arr.length</code></li>\n <li><code>i - 1</code>&nbsp;满足:<code>i - 1 &gt;= 0</code></li>\n <li><code>j</code>&nbsp;满足:<code>arr[i] == arr[j]</code>&nbsp;且&nbsp;<code>i != j</code></li>\n</ul>\n\n<p>请你返回到达数组最后一个元素的下标处所需的&nbsp;<strong>最少操作次数</strong>&nbsp;。</p>\n\n<p>注意:任何时候你都不能跳到数组外面。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>arr = [100,-23,-23,404,100,23,23,23,3,404]\n<strong>输出:</strong>3\n<strong>解释:</strong>那你需要跳跃 3 次,下标依次为 0 --&gt; 4 --&gt; 3 --&gt; 9 。下标 9 为数组的最后一个元素的下标。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>arr = [7]\n<strong>输出:</strong>0\n<strong>解释:</strong>一开始就在最后一个元素处,所以你不需要跳跃。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><strong>输入:</strong>arr = [7,6,9,6,9,6,9,7]\n<strong>输出:</strong>1\n<strong>解释:</strong>你可以直接从下标 0 处跳到下标 7 处,也就是数组的最后一个元素处。\n</pre>\n\n<p><strong>示例 4</strong></p>\n\n<pre><strong>输入:</strong>arr = [6,1,9]\n<strong>输出:</strong>2\n</pre>\n\n<p><strong>示例 5</strong></p>\n\n<pre><strong>输入:</strong>arr = [11,22,7,7,7,7,7,7,7,22,13]\n<strong>输出:</strong>3\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= arr.length &lt;= 5 * 10^4</code></li>\n <li><code>-10^8 &lt;= arr[i] &lt;= 10^8</code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>广度优先搜索</li><li>数组</li><li>哈希表</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.*;\n\nclass Solution &#123;\n public int minJumps(int[] arr) &#123;\n if (arr.length &#x3D;&#x3D; 1) &#123;\n return 0;\n &#125;\n boolean[] use &#x3D; new boolean[arr.length];\n Map&lt;Integer, List&lt;Integer&gt;&gt; map &#x3D; new HashMap&lt;&gt;();\n for (int i &#x3D; 0; i &lt; arr.length; i++) &#123;\n map.computeIfAbsent(arr[i], k -&gt; new ArrayList&lt;&gt;\n &#125;\n use[0] &#x3D; true;\n Queue&lt;Integer&gt; queue &#x3D; new ArrayDeque&lt;&gt;();\n queue.add(0);\n int count &#x3D; 0;\n while (!queue.isEmpty()) &#123;\n int size &#x3D; queue.size();\n count++;\n for (int i &#x3D; 0; i &lt; size; i++) &#123;\n int index &#x3D; queue.poll();\n if (index - 1 &gt;&#x3D; 0 &amp;&amp; !use[index - 1]) &#123;\n queue.add(index - 1);\n use[index - 1] &#x3D; true;\n &#125;\n if (index + 1 &#x3D;&#x3D; arr.length - 1) &#123;\n return count;\n &#125;\n if (index + 1 &gt;&#x3D; 0 &amp;&amp; !use[index + 1]) &#123;\n queue.add(index + 1);\n use[index + 1] &#x3D; true;\n &#125;\n if (map.containsKey(arr[index])) &#123;\n List&lt;Integer&gt; list &#x3D; map.get(arr[index])\n map.remove(arr[index]);\n for (int ind : list) &#123;\n if (ind &#x3D;&#x3D; arr.length - 1) &#123;\n return count;\n &#125;\n if (!use[ind]) &#123;\n queue.add(ind);\n use[ind] &#x3D; true;\n &#125;\n &#125;\n &#125;\n &#125;\n &#125;\n return 0;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from collections import defaultdict, deque\nfrom typing import List\n\n\nclass Solution:\n def minJumps(self, arr: List[int]) -&gt; int:\n if len(arr) &#x3D;&#x3D; 1:\n return 0\n map &#x3D; defaultdict(list)\n for i, a in enumerate(arr):\n map[a].append(i)\n use &#x3D; set()\n queue &#x3D; deque()\n queue.append(0)\n use.add(0)\n count &#x3D; 0\n while queue:\n count +&#x3D; 1\n for i in range(len(queue)):\n index &#x3D; queue.popleft()\n if index - 1 &gt;&#x3D; 0 and (index - 1) not in use:\n use.add(index - 1)\n queue.append(index - 1)\n if index + 1 &#x3D;&#x3D; len(arr) - 1:\n return count\n if index + 1 &lt; len(arr) and (index + 1) not in use:\n use.add(index + 1)\n queue.append(index + 1)\n v &#x3D; arr[index]\n for i in map[v]:\n if i &#x3D;&#x3D; len(arr) - 1:\n return count\n if i not in use:\n use.add(i)\n queue.append(i)\n del map[v]</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣2029:石子游戏 IX","slug":"day20220120","date":"2022-01-20T02:56:54.000Z","updated":"2024-04-25T08:10:09.080Z","comments":true,"path":"/post/day20220120/","link":"","excerpt":"","content":"<p>2022年01月20日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>Alice 和 Bob 再次设计了一款新的石子游戏。现有一行 n 个石子,每个石子都有一个关联的数字表示它的价值。给你一个整数数组 <code>stones</code> ,其中 <code>stones[i]</code> 是第 <code>i</code> 个石子的价值。</p>\n\n<p>Alice 和 Bob 轮流进行自己的回合,<strong>Alice</strong> 先手。每一回合,玩家需要从 <code>stones</code>&nbsp;中移除任一石子。</p>\n\n<ul>\n <li>如果玩家移除石子后,导致 <strong>所有已移除石子</strong> 的价值&nbsp;<strong>总和</strong> 可以被 3 整除,那么该玩家就 <strong>输掉游戏</strong> 。</li>\n <li>如果不满足上一条,且移除后没有任何剩余的石子,那么 Bob 将会直接获胜(即便是在 Alice 的回合)。</li>\n</ul>\n\n<p>假设两位玩家均采用&nbsp;<strong>最佳</strong> 决策。如果 Alice 获胜,返回 <code>true</code> ;如果 Bob 获胜,返回 <code>false</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>stones = [2,1]\n<strong>输出:</strong>true\n<strong>解释:</strong>游戏进行如下:\n- 回合 1Alice 可以移除任意一个石子。\n- 回合 2Bob 移除剩下的石子。 \n已移除的石子的值总和为 1 + 2 = 3 且可以被 3 整除。因此Bob 输Alice 获胜。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>stones = [2]\n<strong>输出:</strong>false\n<strong>解释:</strong>Alice 会移除唯一一个石子,已移除石子的值总和为 2 。 \n由于所有石子都已移除且值总和无法被 3 整除Bob 获胜。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>stones = [5,1,2,4,3]\n<strong>输出:</strong>false\n<strong>解释:</strong>Bob 总会获胜。其中一种可能的游戏进行方式如下:\n- 回合 1Alice 可以移除值为 1 的第 2 个石子。已移除石子值总和为 1 。\n- 回合 2Bob 可以移除值为 3 的第 5 个石子。已移除石子值总和为 = 1 + 3 = 4 。\n- 回合 3Alices 可以移除值为 4 的第 4 个石子。已移除石子值总和为 = 1 + 3 + 4 = 8 。\n- 回合 4Bob 可以移除值为 2 的第 3 个石子。已移除石子值总和为 = 1 + 3 + 4 + 2 = 10.\n- 回合 5Alice 可以移除值为 5 的第 1 个石子。已移除石子值总和为 = 1 + 3 + 4 + 2 + 5 = 15.\nAlice 输掉游戏因为已移除石子值总和15可以被 3 整除Bob 获胜。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= stones.length &lt;= 10<sup>5</sup></code></li>\n <li><code>1 &lt;= stones[i] &lt;= 10<sup>4</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>贪心</li><li>数组</li><li>数学</li><li>计数</li><li>博弈</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">class Solution &#123;\n public boolean stoneGameIX(int[] stones) &#123;\n int[] counts &#x3D; new int[3];\n for (int stone : stones) &#123;\n counts[stone % 3]++;\n &#125;\n return counts[0] % 2 &#x3D;&#x3D; 0 ? counts[1] &gt; 0 &amp;&amp; counts[2] &gt; 0 : Math.abs(counts[1] - counts[2]) &gt; 2;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def stoneGameIX(self, stones: List[int]) -&gt; bool:\n counts &#x3D; [0] * 3\n for stone in stones:\n counts[stone % 3] +&#x3D; 1\n if counts[0] % 2 &#x3D;&#x3D; 0:\n return counts[1] &gt; 0 and counts[2] &gt; 0\n else:\n return abs(counts[1] - counts[2]) &gt; 2</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣219:存在重复元素 II","slug":"day20220119","date":"2022-01-19T03:24:37.000Z","updated":"2024-04-25T08:10:09.079Z","comments":true,"path":"/post/day20220119/","link":"","excerpt":"","content":"<p>2022年01月19日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给你一个整数数组&nbsp;<code>nums</code> 和一个整数&nbsp;<code>k</code> ,判断数组中是否存在两个 <strong>不同的索引</strong><em>&nbsp;</em><code>i</code>&nbsp;和<em>&nbsp;</em><code>j</code> ,满足 <code>nums[i] == nums[j]</code> 且 <code>abs(i - j) &lt;= k</code> 。如果存在,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例&nbsp;1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,2,3,1], k<em> </em>= 3\n<strong>输出:</strong>true</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,0,1,1], k<em> </em>=<em> </em>1\n<strong>输出:</strong>true</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,2,3,1,2,3], k<em> </em>=<em> </em>2\n<strong>输出:</strong>false</pre>\n\n<p>&nbsp;</p>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n <li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n <li><code>0 &lt;= k &lt;= 10<sup>5</sup></code></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>哈希表</li><li>滑动窗口</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.HashMap;\nimport java.util.Map;\n\nclass Solution &#123;\n public boolean containsNearbyDuplicate(int[] nums, int k) &#123;\n if (k &lt;&#x3D; 0) &#123;\n return false;\n &#125;\n Map&lt;Integer, Integer&gt; map &#x3D; new HashMap&lt;&gt;();\n for (int i &#x3D; 0; i &lt; nums.length; i++) &#123;\n if (map.containsKey(nums[i]) &amp;&amp; i - map.get(nums[i]) &lt;&#x3D; k) &#123;\n return true;\n &#125;\n map.put(nums[i], i);\n &#125;\n return false;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -&gt; bool:\n map &#x3D; &#123;&#125;\n for i, num in enumerate(nums):\n if num in map and i - map[num] &lt;&#x3D; k:\n return True\n map[num] &#x3D; i\n return False</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"力扣539:最小时间差","slug":"day20220118","date":"2022-01-18T06:26:41.000Z","updated":"2024-04-25T08:10:09.078Z","comments":true,"path":"/post/day20220118/","link":"","excerpt":"","content":"<p>2022年01月18日 力扣每日一题</p>\n<h1 id=\"题目\"><a href=\"#题目\" class=\"headerlink\" title=\"题目\"></a>题目</h1><p>给定一个 24 小时制(小时:分钟 <strong>\"HH:MM\"</strong>)的时间列表,找出列表中任意两个时间的最小时间差并以分钟数表示。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>timePoints = [\"23:59\",\"00:00\"]\n<strong>输出:</strong>1\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>timePoints = [\"00:00\",\"23:59\",\"00:00\"]\n<strong>输出:</strong>0\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<p><ul>\n <li><code>2 <= timePoints.length <= 2 * 10<sup>4</sup></code></li>\n <li><code>timePoints[i]</code> 格式为 <strong>\"HH:MM\"</strong></li>\n</ul></p>\n<div><div>Related Topics</div><div><li>数组</li><li>数学</li><li>字符串</li><li>排序</li></div></div>\n\n<h1 id=\"个人解法\"><a href=\"#个人解法\" class=\"headerlink\" title=\"个人解法\"></a>个人解法</h1><div class=\"tabs\" id=\"categories\"><ul class=\"nav-tabs\"><button type=\"button\" class=\"tab active\" data-href=\"categories-1\">Java</button><button type=\"button\" class=\"tab \" data-href=\"categories-2\">Python3</button></ul><div class=\"tab-contents\"><div class=\"tab-item-content active\" id=\"categories-1\"><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import java.util.List;\n\nclass Solution &#123;\n public int findMinDifference(List&lt;String&gt; timePoints) &#123;\n int[] times &#x3D; new int[2880];\n for (String timePoint : timePoints) &#123;\n String[] strs &#x3D; timePoint.split(&quot;:&quot;);\n int time &#x3D; Integer.parseInt(strs[0]) * 60 + Integer.parseInt(strs[1]);\n if (times[time] &#x3D;&#x3D; 1) &#123;\n return 0;\n &#125;\n times[time] &#x3D; 1;\n times[time + 1440] &#x3D; 1;\n &#125;\n if (times[0] &#x3D;&#x3D; 1 &amp;&amp; times[1439] &#x3D;&#x3D; 1) &#123;\n return 1;\n &#125;\n int min &#x3D; 1440;\n int bef &#x3D; 0;\n for (int i &#x3D; 1; i &lt; 2880; i++) &#123;\n if (times[i] &#x3D;&#x3D; 1) &#123;\n if (bef &gt; 0) &#123;\n min &#x3D; Math.min(min, i - bef);\n &#125;\n if (i &gt; 1439) &#123;\n break;\n &#125;\n bef &#x3D; i;\n &#125;\n &#125;\n return min;\n &#125;\n&#125;</code></pre></div><div class=\"tab-item-content\" id=\"categories-2\"><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">from typing import List\n\n\nclass Solution:\n def findMinDifference(self, timePoints: List[str]) -&gt; int:\n times &#x3D; [0] * 2880\n for timePoint in timePoints:\n time &#x3D; int(timePoint[:2]) * 60 + int(timePoint[-2:])\n if times[time] &#x3D;&#x3D; 1:\n return 0\n times[time] &#x3D; 1\n times[time + 1440] &#x3D; 1\n result &#x3D; 1440\n bef &#x3D; 0\n for i in range(2880):\n if times[i] &#x3D;&#x3D; 1:\n if bef &gt; 0:\n result &#x3D; min(result, i - bef)\n if i &gt; 1439:\n break\n bef &#x3D; i\n return result</code></pre></div></div><div class=\"tab-to-top\"><button type=\"button\" aria-label=\"scroll to top\"><i class=\"fas fa-arrow-up\"></i></button></div></div>\n","categories":[{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"}],"tags":[{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"}]},{"title":"Sublime Text 4 破解","slug":"sublimeText4Purchase","date":"2022-01-14T07:24:18.000Z","updated":"2022-09-22T07:39:53.207Z","comments":true,"path":"/post/sublimeText4Purchase/","link":"","excerpt":"","content":"<h1 id=\"下载地址\"><a href=\"#下载地址\" class=\"headerlink\" title=\"下载地址\"></a>下载地址</h1><p><a href=\"https://www.sublimetext.com/download\">https://www.sublimetext.com/download</a></p>\n<h1 id=\"激活方法\"><a href=\"#激活方法\" class=\"headerlink\" title=\"激活方法\"></a>激活方法</h1><h2 id=\"打开在线十六进制编辑器\"><a href=\"#打开在线十六进制编辑器\" class=\"headerlink\" title=\"打开在线十六进制编辑器\"></a>打开在线十六进制编辑器</h2><p>地址:<a href=\"https://hexed.it/\">hexed</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114153619254.png\" alt=\"image-20220114153619254\"></p>\n<h2 id=\"打开sublime-text-exe文件\"><a href=\"#打开sublime-text-exe文件\" class=\"headerlink\" title=\"打开sublime_text.exe文件\"></a>打开<code>sublime_text.exe</code>文件</h2><p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/img.png\" alt=\"img.png\"></p>\n<h2 id=\"替换\"><a href=\"#替换\" class=\"headerlink\" title=\"替换\"></a>替换</h2><p>根据版本不同替换不同:</p>\n<ul>\n<li><p>X64版本</p>\n<p><code>4157415656575553B828210000</code> 替换为 <code>33C0FEC0C3575553B828210000</code></p>\n</li>\n<li><p>X86版本<br><code>55535756B8AC200000</code> 替换为 <code>33C0FEC0C3AC200000</code></p>\n</li>\n</ul>\n<p>按住<code>Ctrl+F</code>我这边是64位电脑在搜索中输入<code>4157415656575553B828210000</code> ,在替换为输入<code>33C0FEC0C3AC200000</code>,如果替换为无法输入,记得将替换为上一行的启用替换勾选上,然后先查找一下,接下来再点击替换</p>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114154528250.png\" alt=\"image-20220114154528250\"></p>\n<h2 id=\"替换后点击另存为,替换掉原来的文件,保存\"><a href=\"#替换后点击另存为,替换掉原来的文件,保存\" class=\"headerlink\" title=\"替换后点击另存为,替换掉原来的文件,保存\"></a>替换后点击另存为,替换掉原来的文件,保存</h2><p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114154843108.png\" alt=\"image-20220114154843108\"></p>\n<h2 id=\"输入激活码激活\"><a href=\"#输入激活码激活\" class=\"headerlink\" title=\"输入激活码激活\"></a>输入激活码激活</h2><ul>\n<li><p>打开应用</p>\n</li>\n<li><p>依次点击Help-&gt;Enter License</p>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114155104130.png\" alt=\"image-20220114155104130\"></p>\n</li>\n<li><p>在弹出的窗口输入激活码</p>\n<p>激活码如下:</p>\n<pre class=\"line-numbers language-latex\" data-language=\"latex\"><code class=\"language-latex\">----- BEGIN LICENSE -----\nRUYO.net\nUnlimited User License\nEA7E-81044230\n0C0CD4A8 CAA317D9 CCABD1AC 434C984C\n7E4A0B13 77893C3E DD0A5BA1 B2EB721C\n4BAAB4C4 9B96437D 14EB743E 7DB55D9C\n7CA26EE2 67C3B4EC 29B2C65A 88D90C59\nCB6CCBA5 7DE6177B C02C2826 8C9A21B0\n6AB1A5B6 20B09EA2 01C979BD 29670B19\n92DC6D90 6E365849 4AB84739 5B4C3EA1\n048CC1D0 9748ED54 CAC9D585 90CAD815\n------ END LICENSE ------</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114155245648.png\" alt=\"image-20220114155245648\"></p>\n</li>\n<li><p>点击下方的Use License</p>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114155341371.png\" alt=\"image-20220114155341371\"></p>\n</li>\n<li><p>确认</p>\n<p>依次点击Help-&gt;About Sublime Text</p>\n<p><img src=\"https://img.huangge1199.cn/blog/sublimeText4Purchase/image-20220114155558214.png\" alt=\"image-20220114155558214\"></p>\n</li>\n</ul>\n","categories":[{"name":"开发工具","slug":"开发工具","permalink":"https://hexo.huangge1199.cn/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/"}],"tags":[{"name":"破解","slug":"破解","permalink":"https://hexo.huangge1199.cn/tags/%E7%A0%B4%E8%A7%A3/"}]},{"title":"用nexus部署maven私服","slug":"nexusCreate","date":"2022-01-12T11:52:40.000Z","updated":"2022-09-22T07:39:53.101Z","comments":true,"path":"/post/nexusCreate/","link":"","excerpt":"","content":"<h1 id=\"nexus-服务部署\"><a href=\"#nexus-服务部署\" class=\"headerlink\" title=\"nexus 服务部署\"></a>nexus 服务部署</h1><p>由于本人习惯问题本次继续用docker部署</p>\n<h2 id=\"查找docker镜像\"><a href=\"#查找docker镜像\" class=\"headerlink\" title=\"查找docker镜像\"></a>查找docker镜像</h2><p>通过<a href=\"https://hub.docker.com/\">https://hub.docker.com/</a> 网站查找选用了官方的sonatype/nexus3</p>\n<h2 id=\"拉取镜像\"><a href=\"#拉取镜像\" class=\"headerlink\" title=\"拉取镜像\"></a>拉取镜像</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker pull sonatype&#x2F;nexus3</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112202513617.png\" alt=\"image-20220112202513617\"></p>\n<h2 id=\"创建宿主机挂载目录并编写docker-compose-yml\"><a href=\"#创建宿主机挂载目录并编写docker-compose-yml\" class=\"headerlink\" title=\"创建宿主机挂载目录并编写docker-compose.yml\"></a>创建宿主机挂载目录并编写docker-compose.yml</h2><p>执行命令:</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">vi docker-compose.yml\nmkdir nexus-data</code></pre>\n<p>docker-compose.yml内容</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">version: &#39;3&#39;\nservices:\n nexus3:\n container_name: nexus3\n image: sonatype&#x2F;nexus3:latest\n environment:\n - TZ&#x3D;Asia&#x2F;Shanghai\n volumes: \n - .&#x2F;nexus-data:&#x2F;var&#x2F;nexus-data\n ports: \n - 8081:8081\n restart: always</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112203927784.png\" alt=\"image-20220112203927784\"></p>\n<h2 id=\"启动容器\"><a href=\"#启动容器\" class=\"headerlink\" title=\"启动容器\"></a>启动容器</h2><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker-compose up -d</code></pre>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112204407509.png\" alt=\"image-20220112204407509\"></p>\n<h2 id=\"浏览器验证\"><a href=\"#浏览器验证\" class=\"headerlink\" title=\"浏览器验证\"></a>浏览器验证</h2><p>浏览器中输入<a href=\"http://IP:8081/,出现下面的页面启动完成\">http://IP:8081/,出现下面的页面启动完成</a></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112204921432.png\" alt=\"image-20220112204921432\"></p>\n<h1 id=\"Nexus-服务的配置\"><a href=\"#Nexus-服务的配置\" class=\"headerlink\" title=\"Nexus 服务的配置\"></a>Nexus 服务的配置</h1><h2 id=\"浏览器中点击右上角的登录\"><a href=\"#浏览器中点击右上角的登录\" class=\"headerlink\" title=\"浏览器中点击右上角的登录\"></a>浏览器中点击右上角的登录</h2><p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112205557025.png\" alt=\"image-20220112205557025\"></p>\n<h2 id=\"登录\"><a href=\"#登录\" class=\"headerlink\" title=\"登录\"></a>登录</h2><p>首次登录会提示密码保存在<strong>/nexus-data/admin.password</strong>(位置可能会变,看提示)</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214506743.png\" alt=\"image-20220112214506743\"></p>\n<p>由于这个目录我们的docker并没有引出来所以我们要去docker容器内查看</p>\n<pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">docker exec -it nexus3 &#x2F;bin&#x2F;bash\ncat &#x2F;nexus-data&#x2F;admin.password</code></pre>\n<p>这地方注意下cat后不会换行注意看下密码用户名是admin文件中存的就是密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214220341.png\" alt=\"image-20220112214220341\"></p>\n<h2 id=\"设置密码\"><a href=\"#设置密码\" class=\"headerlink\" title=\"设置密码\"></a>设置密码</h2><p>登录后:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214637528.png\" alt=\"image-20220112214637528\"></p>\n<p>点击next设置新密码</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214717867.png\" alt=\"image-20220112214717867\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214820826.png\" alt=\"image-20220112214820826\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112214831857.png\" alt=\"image-20220112214831857\"></p>\n<h2 id=\"增加阿里云公共仓库\"><a href=\"#增加阿里云公共仓库\" class=\"headerlink\" title=\"增加阿里云公共仓库\"></a>增加阿里云公共仓库</h2><p>由于默认的里面没有阿里云仓库用maven的仓库速度慢所以增加一个阿里云仓库</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112215708898.png\" alt=\"image-20220112215708898\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112215809631.png\" alt=\"image-20220112215809631\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112215951755.png\" alt=\"image-20220112215951755\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112220131151.png\" alt=\"image-20220112220131151\"></p>\n<p>接下来填写信息name这个随意填为了方便记忆我填写的aliyun-public-proxy下面的配置阿里云地址<a href=\"https://maven.aliyun.com/repository/public两个填好后点击最下方的Create\">https://maven.aliyun.com/repository/public两个填好后点击最下方的Create</a> repository</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112220511830.png\" alt=\"image-20220112220511830\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112220741095.png\" alt=\"image-20220112220741095\"></p>\n<h2 id=\"统一私服\"><a href=\"#统一私服\" class=\"headerlink\" title=\"统一私服\"></a>统一私服</h2><ul>\n<li>编辑<strong>maven-public</strong></li>\n</ul>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112221401367.png\" alt=\"image-20220112221401367\"></p>\n<ul>\n<li>将刚刚的aliyun-public-proxy放入 <strong>group</strong> 中,并调整优先级,然后保存</li>\n</ul>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112221517343.png\" alt=\"image-20220112221517343\"></p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112221637473.png\" alt=\"image-20220112221637473\"></p>\n<h2 id=\"查看私服地址\"><a href=\"#查看私服地址\" class=\"headerlink\" title=\"查看私服地址\"></a>查看私服地址</h2><p>回到上一个页面点击copy弹出来的地址就是私服地址</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112221849871.png\" alt=\"image-20220112221849871\"></p>\n<h1 id=\"使用私服\"><a href=\"#使用私服\" class=\"headerlink\" title=\"使用私服\"></a>使用私服</h1><p>注maven地址E:\\maven\\apache-maven-3.6.3</p>\n<h2 id=\"maven中setting-xml-文件配置\"><a href=\"#maven中setting-xml-文件配置\" class=\"headerlink\" title=\"maven中setting.xml 文件配置\"></a>maven中setting.xml 文件配置</h2><ul>\n<li><p>下载依赖</p>\n<p>找到mirrors位置并将其标签内容修改如下</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;mirrors&gt;\n &lt;!-- mirror\n | Specifies a repository mirror site to use instead of a given repository. The repository that\n | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used\n | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.\n |\n &lt;mirror&gt;\n &lt;id&gt;mirrorId&lt;&#x2F;id&gt;\n &lt;mirrorOf&gt;repositoryId&lt;&#x2F;mirrorOf&gt;\n &lt;name&gt;Human Readable Name for this Mirror.&lt;&#x2F;name&gt;\n &lt;url&gt;http:&#x2F;&#x2F;my.repository.com&#x2F;repo&#x2F;path&lt;&#x2F;url&gt;\n &lt;&#x2F;mirror&gt;\n --&gt;\n\t&lt;mirror&gt;\n &lt;!--该镜像的唯一标识符。id用来区分不同的mirror元素。 --&gt;\n &lt;id&gt;maven-public&lt;&#x2F;id&gt;\n &lt;!--镜像名称 --&gt;\n &lt;name&gt;maven-public&lt;&#x2F;name&gt;\n &lt;!--*指的是访问任何仓库都使用我们的私服--&gt;\n &lt;mirrorOf&gt;*&lt;&#x2F;mirrorOf&gt;\n &lt;!--该镜像的URL。构建系统会优先考虑使用该URL而非使用默认的服务器URL。 --&gt;\n &lt;url&gt;http:&#x2F;&#x2F;192.168.1.187:8081&#x2F;repository&#x2F;maven-public&#x2F;&lt;&#x2F;url&gt; \n &lt;&#x2F;mirror&gt;\n&lt;&#x2F;mirrors&gt;</code></pre>\n</li>\n<li><p>发布依赖</p>\n<p>找到servers位置并将其标签内容修改如下</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;servers&gt;\n &lt;!-- server\n | Specifies the authentication information to use when connecting to a particular server, identified by\n | a unique name within the system (referred to by the &#39;id&#39; attribute below).\n |\n | NOTE: You should either specify username&#x2F;password OR privateKey&#x2F;passphrase, since these pairings are\n | used together.\n |\n &lt;server&gt;\n &lt;id&gt;deploymentRepo&lt;&#x2F;id&gt;\n &lt;username&gt;repouser&lt;&#x2F;username&gt;\n &lt;password&gt;repopwd&lt;&#x2F;password&gt;\n &lt;&#x2F;server&gt;\n --&gt;\n &lt;!-- Another sample, using keys to authenticate.\n &lt;server&gt;\n &lt;id&gt;siteServer&lt;&#x2F;id&gt;\n &lt;privateKey&gt;&#x2F;path&#x2F;to&#x2F;private&#x2F;key&lt;&#x2F;privateKey&gt;\n &lt;passphrase&gt;optional; leave empty if not used.&lt;&#x2F;passphrase&gt;\n &lt;&#x2F;server&gt;\n --&gt;\n &lt;server&gt;\n &lt;id&gt;releases&lt;&#x2F;id&gt;\n &lt;username&gt;admin&lt;&#x2F;username&gt;\n &lt;password&gt;123456&lt;&#x2F;password&gt;\n &lt;&#x2F;server&gt;\n &lt;server&gt;\n &lt;id&gt;snapshots&lt;&#x2F;id&gt;\n &lt;username&gt;admin&lt;&#x2F;username&gt;\n &lt;password&gt;123456&lt;&#x2F;password&gt;\n &lt;&#x2F;server&gt;\n&lt;&#x2F;servers&gt;</code></pre>\n</li>\n</ul>\n<h2 id=\"新建maven项目\"><a href=\"#新建maven项目\" class=\"headerlink\" title=\"新建maven项目\"></a>新建maven项目</h2><p>我这边建了一个Springboot项目</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112223312451.png\" alt=\"image-20220112223312451\"></p>\n<p>设置maven路径</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112224909515.png\" alt=\"image-20220112224909515\"></p>\n<h2 id=\"发布依赖\"><a href=\"#发布依赖\" class=\"headerlink\" title=\"发布依赖\"></a>发布依赖</h2><ol>\n<li><p>项目pom中添加 <strong>distributionManagement</strong> 节点</p>\n<pre class=\"line-numbers language-markup\" data-language=\"markup\"><code class=\"language-markup\">&lt;distributionManagement&gt;\n &lt;repository&gt;\n &lt;id&gt;releases&lt;&#x2F;id&gt;\n &lt;name&gt;Releases&lt;&#x2F;name&gt;\n &lt;url&gt;http:&#x2F;&#x2F;192.168.1.187:8081&#x2F;repository&#x2F;maven-releases&#x2F;&lt;&#x2F;url&gt;\n &lt;&#x2F;repository&gt;\n &lt;snapshotRepository&gt;\n &lt;id&gt;snapshots&lt;&#x2F;id&gt;\n &lt;name&gt;Snapshot&lt;&#x2F;name&gt;\n &lt;url&gt;http:&#x2F;&#x2F;192.168.1.187:8081&#x2F;repository&#x2F;maven-snapshots&#x2F;&lt;&#x2F;url&gt;\n &lt;&#x2F;snapshotRepository&gt;\n&lt;&#x2F;distributionManagement&gt;</code></pre>\n<p>注:<strong>repository</strong> 里的 <strong>id</strong> 需要和上一步里的 <strong>server id</strong> 名称保持一致。</p>\n</li>\n<li><p>执行 <strong>mvn deploy</strong> 命令发布:</p>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112230213213.png\" alt=\"image-20220112230213213\"></p>\n</li>\n<li><p>查看网页,是否部署成功</p>\n<p>注:</p>\n<ul>\n<li>若项目版本号末尾带有 <strong>-SNAPSHOT</strong>,则会发布到 <strong>snapshots</strong> 快照版本仓库</li>\n<li>若项目版本号末尾带有 <strong>-RELEASES</strong> 或什么都不带,则会发布到 <strong>releases</strong> 正式版本仓库</li>\n</ul>\n<p><img src=\"https://img.huangge1199.cn/blog/nexusCreate/image-20220112230645860.png\" alt=\"image-20220112230645860\"></p>\n</li>\n</ol>\n","categories":[{"name":"nexus","slug":"nexus","permalink":"https://hexo.huangge1199.cn/categories/nexus/"}],"tags":[{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"maven","slug":"maven","permalink":"https://hexo.huangge1199.cn/tags/maven/"},{"name":"nexus","slug":"nexus","permalink":"https://hexo.huangge1199.cn/tags/nexus/"}]},{"title":"JPA复合主键使用","slug":"jpaCompositePK","date":"2022-01-05T07:14:53.000Z","updated":"2022-09-22T07:39:53.084Z","comments":true,"path":"/post/jpaCompositePK/","link":"","excerpt":"","content":"<h1 id=\"1、建立带有复合主键的表User\"><a href=\"#1、建立带有复合主键的表User\" class=\"headerlink\" title=\"1、建立带有复合主键的表User\"></a>1、建立带有复合主键的表User</h1><p>该表使用 <code>username</code>+<code>phone</code> 做为复合组件</p>\n<pre class=\"line-numbers language-sql\" data-language=\"sql\"><code class=\"language-sql\">create table user\n(\n username varchar(50) not null,\n phone varchar(11) not null,\n email varchar(20) default &#39;&#39;,\n address varchar(50) default &#39;&#39;,\n primary key (username, phone)\n) default charset &#x3D; utf8</code></pre>\n<h1 id=\"2、java中建立复合主键的实体类\"><a href=\"#2、java中建立复合主键的实体类\" class=\"headerlink\" title=\"2、java中建立复合主键的实体类\"></a>2、java中建立复合主键的实体类</h1><pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import lombok.Data;\nimport javax.persistence.*;\nimport java.io.Serializable;\n\n@Data\n@Entity\npublic class UserKey implements Serializable &#123;\n private String username;\n private String phone;\n&#125;</code></pre>\n<h1 id=\"3、建立表的实体类\"><a href=\"#3、建立表的实体类\" class=\"headerlink\" title=\"3、建立表的实体类\"></a>3、建立表的实体类</h1><p>在实体类上面使用 @IdClass 注解指定复合主键。同时,需要在 name 和 phone 字段上面使用 @Id 注解标记为主键</p>\n<pre class=\"line-numbers language-java\" data-language=\"java\"><code class=\"language-java\">import lombok.Data;\nimport javax.persistence.*;\n\n@Data\n@Entity\n@Table(name &#x3D; &quot;user&quot;)\n@IdClass(value &#x3D; UserKey.class)\npublic class User &#123;\n @Id\n @Column(nullable &#x3D; false)\n private String username;\n\n @Id\n @Column(nullable &#x3D; false)\n private String phone;\n\n @Column\n private String email;\n\n @Column\n private String address;\n&#125;</code></pre>\n","categories":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"jpa","slug":"java/jpa","permalink":"https://hexo.huangge1199.cn/categories/java/jpa/"}],"tags":[{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"},{"name":"jpa","slug":"jpa","permalink":"https://hexo.huangge1199.cn/tags/jpa/"}]},{"title":"python3学习笔记--条件控制用法整理","slug":"pyControl","date":"2021-12-29T08:04:06.000Z","updated":"2022-09-22T07:39:53.182Z","comments":true,"path":"/post/pyControl/","link":"","excerpt":"","content":"<h1 id=\"if\"><a href=\"#if\" class=\"headerlink\" title=\"if\"></a>if</h1><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">if_stmt ::&#x3D; &quot;if&quot; assignment_expression &quot;:&quot; suite\n (&quot;elif&quot; assignment_expression &quot;:&quot; suite)*\n [&quot;else&quot; &quot;:&quot; suite]</code></pre>\n<p>用法:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">if EXPRESSION1:\n SUITE1\nelif EXPRESSION2:\n SUITE2\nelse:\n SUITE</code></pre>\n<p>常用的操作符:</p>\n<ul>\n<li>“&lt;”:小于</li>\n<li>“&lt;=”:小于等于</li>\n<li>“&gt;”:大于</li>\n<li>“&gt;=”:大于等于</li>\n<li>“==”:等于</li>\n<li>“!=”:不等于</li>\n<li>“and”并且</li>\n<li>“or”或者</li>\n</ul>\n<h1 id=\"with\"><a href=\"#with\" class=\"headerlink\" title=\"with\"></a>with</h1><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">with_stmt ::&#x3D; &quot;with&quot; ( &quot;(&quot; with_stmt_contents &quot;,&quot;? &quot;)&quot; | with_stmt_contents ) &quot;:&quot; suite\nwith_stmt_contents ::&#x3D; with_item (&quot;,&quot; with_item)*\nwith_item ::&#x3D; expression [&quot;as&quot; target]</code></pre>\n<p>用法:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">with EXPRESSION as TARGET:\n SUITE\n或者\nwith A() as a, B() as b:\n SUITE\n或者\nwith A() as a:\n with B() as b:\n SUITE\n或者\nwith (\n A() as a,\n B() as b,\n):\n SUITE</code></pre>\n<h1 id=\"match3-10新特性\"><a href=\"#match3-10新特性\" class=\"headerlink\" title=\"match3.10新特性)\"></a>match3.10新特性)</h1><pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">match_stmt ::&#x3D; &#39;match&#39; subject_expr &quot;:&quot; NEWLINE INDENT case_block+ DEDENT\nsubject_expr ::&#x3D; star_named_expression &quot;,&quot; star_named_expressions?\n | named_expression\ncase_block ::&#x3D; &#39;case&#39; patterns [guard] &quot;:&quot; block</code></pre>\n<p>用法:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">match variable: #这里的variable是需要判断的内容\n case [&quot;quit&quot;]: \n statement_block_1 # 对应案例的执行代码当variable&#x3D;&quot;quit&quot;时执行statement_block_1\n case [&quot;go&quot;, direction]: \n statement_block_2\n case [&quot;drop&quot;, *objects]: \n statement_block_3\n ... # 其他的case语句\n case _: #如果上面的case语句没有命中则执行这个代码块类似于Switch的default\n statement_block_default</code></pre>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"python3学习笔记--两种排序方法","slug":"pyListSort","date":"2021-12-29T02:20:17.000Z","updated":"2022-09-22T07:39:53.188Z","comments":true,"path":"/post/pyListSort/","link":"","excerpt":"","content":"<h1 id=\"列表排序方法\"><a href=\"#列表排序方法\" class=\"headerlink\" title=\"列表排序方法\"></a>列表排序方法</h1><ul>\n<li>sort()仅对list对象进行排序会改变list自身的顺序没有返回值即<strong>原地排序</strong></li>\n<li>sorted():对所有可迭代对象进行排序,返回排序后的新对象,原对象保持不变;</li>\n</ul>\n<h1 id=\"sort\"><a href=\"#sort\" class=\"headerlink\" title=\"sort()\"></a>sort()</h1><p>list.sort(key=None, reverse=False)</p>\n<ul>\n<li><strong>key</strong>设置排序方法或指定list中用于排序的元素</li>\n<li><strong>reverse</strong>:升降序排列,默认为升序排列;</li>\n</ul>\n<p>例子:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">nums &#x3D; [2, 3, 5, 1, 6]\nnums.sort()\nprint(nums) # [1, 2, 3, 5, 6]\nnums.sort(key&#x3D;None, reverse&#x3D;True)\nprint(nums) # [6, 5, 3, 2, 1]\n \nstudents &#x3D; [(&#39;john&#39;, &#39;C&#39;, 15), (&#39;jane&#39;, &#39;A&#39;, 12), (&#39;dave&#39;, &#39;B&#39;, 10)]\nstudents.sort(key&#x3D;lambda x: x[2]) # 按照列表中第三个元素排序\nprint(students) # [(&#39;dave&#39;, &#39;B&#39;, 10), (&#39;jane&#39;, &#39;A&#39;, 12), (&#39;john&#39;, &#39;C&#39;, 15)]</code></pre>\n<h1 id=\"sorted\"><a href=\"#sorted\" class=\"headerlink\" title=\"sorted()\"></a>sorted()</h1><p>sorted(iterable [, key[, reverse]])</p>\n<ul>\n<li><strong>key</strong> :设置排序方法,或指定迭代对象中,用于排序的元素;</li>\n<li><strong>reverse</strong> :升降序排列,默认为升序排列;</li>\n</ul>\n<p>例子:</p>\n<pre class=\"line-numbers language-python\" data-language=\"python\"><code class=\"language-python\">nums &#x3D; [2, 3, 5, 1, 6]\nnewNums &#x3D; sorted(nums)\nprint(nums) # [2, 3, 5, 1, 6]\nprint(newNums) # [1, 2, 3, 5, 6]\nstudents &#x3D; [(&#39;john&#39;, &#39;C&#39;, 15), (&#39;jane&#39;, &#39;A&#39;, 12), (&#39;dave&#39;, &#39;B&#39;, 10)]\nnewStudents &#x3D; sorted(students, key&#x3D;lambda x: x[1])\nprint(students) # [(&#39;john&#39;, &#39;C&#39;, 15), (&#39;jane&#39;, &#39;A&#39;, 12), (&#39;dave&#39;, &#39;B&#39;, 10)]\nprint(newStudents) # [(&#39;jane&#39;, &#39;A&#39;, 12), (&#39;dave&#39;, &#39;B&#39;, 10), (&#39;john&#39;, &#39;C&#39;, 15)]</code></pre>\n<script src=\"https://readmore.openwrite.cn/js/readmore.js\" type=\"text/javascript\"></script>\n<script>\n const btw = new BTWPlugin();\n btw.init({\n id: 'article-container',\n blogId: '28702-1640918923546-365',\n name: '龙儿之家',\n qrcode: 'https://img.huangge1199.cn/blog/images/WeaselLong.jpg',\n keyword: 'more',\n });\n</script>\n","categories":[{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"}],"tags":[{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"}]},{"title":"Hello World","slug":"hello-world","date":"2021-12-01T11:04:06.000Z","updated":"2022-09-22T07:39:52.889Z","comments":true,"path":"/post/hello-world/","link":"","excerpt":"","content":"<p>Welcome to <a href=\"https://hexo.io/\">Hexo</a>! This is your very first post. Check <a href=\"https://hexo.io/docs/\">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href=\"https://hexo.io/docs/troubleshooting.html\">troubleshooting</a> or you can ask me on <a href=\"https://github.com/hexojs/hexo/issues\">GitHub</a>.</p>\n<h2 id=\"Quick-Start\"><a href=\"#Quick-Start\" class=\"headerlink\" title=\"Quick Start\"></a>Quick Start</h2><h3 id=\"Create-a-new-post\"><a href=\"#Create-a-new-post\" class=\"headerlink\" title=\"Create a new post\"></a>Create a new post</h3><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">$ hexo new &quot;My New Post&quot;</code></pre>\n<p>More info: <a href=\"https://hexo.io/docs/writing.html\">Writing</a></p>\n<h3 id=\"Run-server\"><a href=\"#Run-server\" class=\"headerlink\" title=\"Run server\"></a>Run server</h3><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">$ hexo server</code></pre>\n<p>More info: <a href=\"https://hexo.io/docs/server.html\">Server</a></p>\n<h3 id=\"Generate-static-files\"><a href=\"#Generate-static-files\" class=\"headerlink\" title=\"Generate static files\"></a>Generate static files</h3><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">$ hexo generate</code></pre>\n<p>More info: <a href=\"https://hexo.io/docs/generating.html\">Generating</a></p>\n<h3 id=\"Deploy-to-remote-sites\"><a href=\"#Deploy-to-remote-sites\" class=\"headerlink\" title=\"Deploy to remote sites\"></a>Deploy to remote sites</h3><pre class=\"line-numbers language-bash\" data-language=\"bash\"><code class=\"language-bash\">$ hexo deploy</code></pre>\n<p>More info: <a href=\"https://hexo.io/docs/one-command-deployment.html\">Deployment</a></p>\n","categories":[],"tags":[]}],"categories":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"前端/vue","permalink":"https://hexo.huangge1199.cn/categories/%E5%89%8D%E7%AB%AF/vue/"},{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/categories/java/"},{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/categories/%E7%9B%96%E7%AB%A0/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/categories/git/"},{"name":"算法","slug":"算法","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/"},{"name":"力扣","slug":"算法/力扣","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/"},{"name":"每日一题","slug":"算法/力扣/每日一题","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/categories/python/"},{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/categories/%E5%B7%A5%E5%85%B7/"},{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/categories/Linux/"},{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/categories/vue/"},{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/categories/nas/"},{"name":"P5笔记","slug":"java/P5笔记","permalink":"https://hexo.huangge1199.cn/categories/java/P5%E7%AC%94%E8%AE%B0/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/categories/deepin/"},{"name":"游戏","slug":"deepin/游戏","permalink":"https://hexo.huangge1199.cn/categories/deepin/%E6%B8%B8%E6%88%8F/"},{"name":"问题记录","slug":"问题记录","permalink":"https://hexo.huangge1199.cn/categories/%E9%97%AE%E9%A2%98%E8%AE%B0%E5%BD%95/"},{"name":"网站建设","slug":"问题记录/网站建设","permalink":"https://hexo.huangge1199.cn/categories/%E9%97%AE%E9%A2%98%E8%AE%B0%E5%BD%95/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"},{"name":"web开发","slug":"web开发","permalink":"https://hexo.huangge1199.cn/categories/web%E5%BC%80%E5%8F%91/"},{"name":"服务器","slug":"服务器","permalink":"https://hexo.huangge1199.cn/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/"},{"name":"nacos","slug":"java/nacos","permalink":"https://hexo.huangge1199.cn/categories/java/nacos/"},{"name":"游戏","slug":"游戏","permalink":"https://hexo.huangge1199.cn/categories/%E6%B8%B8%E6%88%8F/"},{"name":"云原生2023","slug":"云原生2023","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F2023/"},{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/categories/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"},{"name":"安装部署","slug":"nas/安装部署","permalink":"https://hexo.huangge1199.cn/categories/nas/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"历史上的今天","slug":"历史上的今天","permalink":"https://hexo.huangge1199.cn/categories/%E5%8E%86%E5%8F%B2%E4%B8%8A%E7%9A%84%E4%BB%8A%E5%A4%A9/"},{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/categories/docker/"},{"name":"deepin","slug":"docker/deepin","permalink":"https://hexo.huangge1199.cn/categories/docker/deepin/"},{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"deepin","slug":"云原生/deepin","permalink":"https://hexo.huangge1199.cn/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/deepin/"},{"name":"周赛","slug":"算法/力扣/周赛","permalink":"https://hexo.huangge1199.cn/categories/%E7%AE%97%E6%B3%95/%E5%8A%9B%E6%89%A3/%E5%91%A8%E8%B5%9B/"},{"name":"PHP","slug":"PHP","permalink":"https://hexo.huangge1199.cn/categories/PHP/"},{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"},{"name":"it百科","slug":"it百科","permalink":"https://hexo.huangge1199.cn/categories/it%E7%99%BE%E7%A7%91/"},{"name":"推理","slug":"推理","permalink":"https://hexo.huangge1199.cn/categories/%E6%8E%A8%E7%90%86/"},{"name":"seata","slug":"java/seata","permalink":"https://hexo.huangge1199.cn/categories/java/seata/"},{"name":"开发工具","slug":"开发工具","permalink":"https://hexo.huangge1199.cn/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/"},{"name":"nexus","slug":"nexus","permalink":"https://hexo.huangge1199.cn/categories/nexus/"},{"name":"jpa","slug":"java/jpa","permalink":"https://hexo.huangge1199.cn/categories/java/jpa/"}],"tags":[{"name":"前端","slug":"前端","permalink":"https://hexo.huangge1199.cn/tags/%E5%89%8D%E7%AB%AF/"},{"name":"vue","slug":"vue","permalink":"https://hexo.huangge1199.cn/tags/vue/"},{"name":"java","slug":"java","permalink":"https://hexo.huangge1199.cn/tags/java/"},{"name":"盖章","slug":"盖章","permalink":"https://hexo.huangge1199.cn/tags/%E7%9B%96%E7%AB%A0/"},{"name":"安装部署","slug":"安装部署","permalink":"https://hexo.huangge1199.cn/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"},{"name":"git","slug":"git","permalink":"https://hexo.huangge1199.cn/tags/git/"},{"name":"力扣","slug":"力扣","permalink":"https://hexo.huangge1199.cn/tags/%E5%8A%9B%E6%89%A3/"},{"name":"python","slug":"python","permalink":"https://hexo.huangge1199.cn/tags/python/"},{"name":"工具","slug":"工具","permalink":"https://hexo.huangge1199.cn/tags/%E5%B7%A5%E5%85%B7/"},{"name":"Linux","slug":"Linux","permalink":"https://hexo.huangge1199.cn/tags/Linux/"},{"name":"nas","slug":"nas","permalink":"https://hexo.huangge1199.cn/tags/nas/"},{"name":"P5笔记","slug":"P5笔记","permalink":"https://hexo.huangge1199.cn/tags/P5%E7%AC%94%E8%AE%B0/"},{"name":"游戏","slug":"游戏","permalink":"https://hexo.huangge1199.cn/tags/%E6%B8%B8%E6%88%8F/"},{"name":"deepin","slug":"deepin","permalink":"https://hexo.huangge1199.cn/tags/deepin/"},{"name":"网站建设","slug":"网站建设","permalink":"https://hexo.huangge1199.cn/tags/%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE/"},{"name":"web开发","slug":"web开发","permalink":"https://hexo.huangge1199.cn/tags/web%E5%BC%80%E5%8F%91/"},{"name":"服务器","slug":"服务器","permalink":"https://hexo.huangge1199.cn/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/"},{"name":"nacos","slug":"nacos","permalink":"https://hexo.huangge1199.cn/tags/nacos/"},{"name":"R2DBC","slug":"R2DBC","permalink":"https://hexo.huangge1199.cn/tags/R2DBC/"},{"name":"学习笔记","slug":"学习笔记","permalink":"https://hexo.huangge1199.cn/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"},{"name":"云原生2023","slug":"云原生2023","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F2023/"},{"name":"历史上的今天","slug":"历史上的今天","permalink":"https://hexo.huangge1199.cn/tags/%E5%8E%86%E5%8F%B2%E4%B8%8A%E7%9A%84%E4%BB%8A%E5%A4%A9/"},{"name":"docker","slug":"docker","permalink":"https://hexo.huangge1199.cn/tags/docker/"},{"name":"云原生","slug":"云原生","permalink":"https://hexo.huangge1199.cn/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/"},{"name":"PHP","slug":"PHP","permalink":"https://hexo.huangge1199.cn/tags/PHP/"},{"name":"设计模式","slug":"设计模式","permalink":"https://hexo.huangge1199.cn/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"},{"name":"it百科","slug":"it百科","permalink":"https://hexo.huangge1199.cn/tags/it%E7%99%BE%E7%A7%91/"},{"name":"推理界的今天","slug":"推理界的今天","permalink":"https://hexo.huangge1199.cn/tags/%E6%8E%A8%E7%90%86%E7%95%8C%E7%9A%84%E4%BB%8A%E5%A4%A9/"},{"name":"maven","slug":"maven","permalink":"https://hexo.huangge1199.cn/tags/maven/"},{"name":"seata","slug":"seata","permalink":"https://hexo.huangge1199.cn/tags/seata/"},{"name":"破解","slug":"破解","permalink":"https://hexo.huangge1199.cn/tags/%E7%A0%B4%E8%A7%A3/"},{"name":"nexus","slug":"nexus","permalink":"https://hexo.huangge1199.cn/tags/nexus/"},{"name":"jpa","slug":"jpa","permalink":"https://hexo.huangge1199.cn/tags/jpa/"}]}