-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
385 lines (183 loc) · 186 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>zs13のシェルター</title>
<icon>https://blog.zs13.tech/icon.png</icon>
<subtitle>僕のblog</subtitle>
<link href="https://blog.zs13.tech/atom.xml" rel="self"/>
<link href="https://blog.zs13.tech/"/>
<updated>2024-08-13T09:17:00.000Z</updated>
<id>https://blog.zs13.tech/</id>
<author>
<name>zs13</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>docker使用的基本知识</title>
<link href="https://blog.zs13.tech/posts/31322/"/>
<id>https://blog.zs13.tech/posts/31322/</id>
<published>2024-08-12T05:42:00.000Z</published>
<updated>2024-08-13T09:17:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="简单入门">简单入门</h2><h3 id="通过docker部署mysql">通过docker部署mysql</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker run -d \</span><br><span class="line">--name mysql \</span><br><span class="line">-p 3306:3306 \</span><br><span class="line">-e TZ=Asia/Shanghai \</span><br><span class="line">-e MYSQL_ROOT_PASSWORD=123 \</span><br><span class="line">mysql</span><br></pre></td></tr></table></figure><ul><li>docker run : 创建并运行一个容器,-d是让容器在后台运行</li><li>–name mysql : 给容器起个名字,必须唯一</li><li>-p 3306:3306 : 设置端口映射 <code>宿主端口:容器端口</code></li><li>-e KEY=VALUE : 设置环境变量</li><li>mysql : 镜像名 <code>[repository]:[tag]</code> 镜像名:镜像版本不填默认latest</li></ul><h2 id="基础命令">基础命令</h2><h3 id="常见命令">常见命令</h3><ul><li>docker pull 获取镜像</li><li>docker build 自定义镜像 需要 dockerfile文件</li><li>docker save 保存docker镜像</li><li>docker load 加载本地镜像</li><li>docker push 上传镜像到仓库</li><li>docker stop/start 开启/关闭容器进程</li><li>docker ps 查看容器</li><li>docker rm/rmi 删除容器/镜像</li><li>docker logs 查看日志</li><li>docker exec 进入容器</li></ul><h3 id="通过部署nginx联系">通过部署nginx联系</h3><p>拉取nginx:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull nginx</span><br></pre></td></tr></table></figure><p>查看本地镜像:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure><p>保存镜像:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker save -o nginx.tar nginx:latest</span><br><span class="line">// -o 保存名 镜像名:版本</span><br></pre></td></tr></table></figure><p>删除镜像:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi nginx:latest</span><br></pre></td></tr></table></figure><p>加载镜像:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker load -i nginx.tar</span><br></pre></td></tr></table></figure><p>启动nginx:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name nginx -p 80:80 nginx</span><br></pre></td></tr></table></figure><p>查看容器状态:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps</span><br></pre></td></tr></table></figure><p>启动一个新容器:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name nginx -p 80:80 nginx</span><br></pre></td></tr></table></figure><p>停止容器:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker stop nginx</span><br><span class="line">//docker stop {NAMES或者ID}</span><br></pre></td></tr></table></figure><p>启动一个旧容器容器:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker start nginx</span><br><span class="line">//docker start {NAMES或者ID}</span><br></pre></td></tr></table></figure><p>查看日志:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker logs nginx</span><br><span class="line">// -f 持续查看日志</span><br></pre></td></tr></table></figure><p>进入容器内部:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it nginx bash</span><br></pre></td></tr></table></figure><h4 id="部分可选配置">部分可选配置</h4><p>设置命令别名修改<code>~/.bashrc</code>文件</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">alias dps = 'docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Names}}"'</span><br><span class="line">alias dis = 'docker images'</span><br></pre></td></tr></table></figure><h2 id="docker数据卷">Docker数据卷</h2><p>官方定义:<code>数据卷</code>是一个虚拟目录,是<code>容器内目录</code>与<code>宿主机目录</code>之间映射的桥梁。</p><table><colgroup><col style="width: 18%" /><col style="width: 8%" /><col style="width: 73%" /></colgroup><thead><tr><th>命令</th><th>说明</th><th>文档地址</th></tr></thead><tbody><tr><td>docker volume create</td><td>创建数据卷</td><td><ahref="https://docs.docker.com/reference/cli/docker/volume/create/">docker_volume_create</a></td></tr><tr><td>docker volume ls</td><td>查看所有数据卷</td><td><ahref="https://docs.docker.com/reference/cli/docker/volume/ls/">docker_volume_ls</a></td></tr><tr><td>docker volume rm</td><td>删除指定数据卷</td><td><ahref="https://docs.docker.com/reference/cli/docker/volume/rm">docker_volume_rm</a></td></tr><tr><td>docker volume inspect</td><td>查看某个数据卷的详情</td><td><ahref="https://docs.docker.com/reference/cli/docker/volume/inspect">docker_volume_inspect</a></td></tr><tr><td>docker volume prune</td><td>清楚数据卷</td><td><ahref="https://docs.docker.com/reference/cli/docker/volume/prune/">docker_volume_prune</a></td></tr></tbody></table><h3 id="简单使用">简单使用</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//创建挂载数据卷的nginx</span><br><span class="line">docker run -d --name -p 80:80 -v html:/usr/share/nginx/html nginx</span><br></pre></td></tr></table></figure><p>查询数据卷:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker volume ls</span><br></pre></td></tr></table></figure><p>查看详细数据:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker volume inspect html</span><br></pre></td></tr></table></figure><h4 id="本地挂载">本地挂载</h4><ul><li>-v 本地目录:容器内目录</li></ul><h2 id="dockerfile">Dockerfile</h2><h3 id="dockerfile基础命令">Dockerfile基础命令</h3><table><colgroup><col style="width: 10%" /><col style="width: 26%" /><col style="width: 63%" /></colgroup><thead><tr><th>指令</th><th>说明</th><th>示例</th></tr></thead><tbody><tr><td>FROM</td><td>指定基础镜像</td><td>FROM centos:6</td></tr><tr><td>ENV</td><td>设置环境变量,可在后面指令使用</td><td>ENV key value</td></tr><tr><td>COPY</td><td>拷贝本地文件到镜像的指定目录</td><td>CPOY ./jrell.tar.gz /tmp</td></tr><tr><td>RUN</td><td>执行Linux的shell命令,一般是安装过程的命令</td><td>RUN tar -zxvf /tmp/jrell.tar.gz&& EXPORTSpath=/tmp/jrell:$path</td></tr><tr><td>EXPOSE</td><td>指定容器运行时监听的端口,是给镜像使用者看的</td><td>EXPOSE 8080</td></tr><tr><td>ENTRYPOINT</td><td>镜像中运用的启动命令,容器运行时调用</td><td>ENTRYPOINT java -jar xx.jar</td></tr></tbody></table><p>使用基础镜像:</p><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 指定基础镜像</span></span><br><span class="line"><span class="keyword">FROM</span> ubuntu:<span class="number">16.04</span></span><br><span class="line"><span class="comment"># 配置环境变量,JDK的安装目录、容器内时区</span></span><br><span class="line"><span class="keyword">ENV</span> JAVA_DIR=/usr/local</span><br><span class="line"><span class="keyword">ENV</span> TZ=Asia/Shanghai</span><br><span class="line"><span class="comment"># 拷贝jdk和java项目的包</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> ./jdk8.tar.gz <span class="variable">$JAVA_DIR</span>/</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> ./docker-demo.jar /tmp/app.jar</span></span><br><span class="line"><span class="comment"># 设定时区</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">ln</span> -snf /usr/share/zoneinfo/<span class="variable">$TZ</span> /etc/localtime && <span class="built_in">echo</span> <span class="variable">$TZ</span> > /etc/timezone</span></span><br><span class="line"><span class="comment"># 安装JDK</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">cd</span> <span class="variable">$JAVA_DIR</span> \</span></span><br><span class="line"><span class="language-bash"> && tar -xf ./jdk8.tar.gz \</span></span><br><span class="line"><span class="language-bash"> && <span class="built_in">mv</span> ./jdk1.8.0_144 ./java8</span></span><br><span class="line"><span class="comment"># 配置环境变量</span></span><br><span class="line"><span class="keyword">ENV</span> JAVA_HOME=$JAVA_DIR/java8</span><br><span class="line"><span class="keyword">ENV</span> PATH=$PATH:$JAVA_HOME/bin</span><br><span class="line"><span class="comment"># 指定项目监听的端口</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">8080</span></span><br><span class="line"><span class="comment"># 入口,java项目的启动命令</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="language-bash"> [<span class="string">"java"</span>, <span class="string">"-jar"</span>, <span class="string">"/app.jar"</span>]</span></span><br></pre></td></tr></table></figure><p>使用别人打包好的镜像:</p><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 基础镜像</span></span><br><span class="line"><span class="keyword">FROM</span> openjdk:<span class="number">11.0</span>-jre-buster</span><br><span class="line"><span class="comment"># 设定时区</span></span><br><span class="line"><span class="keyword">ENV</span> TZ=Asia/Shanghai</span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">ln</span> -snf /usr/share/zoneinfo/<span class="variable">$TZ</span> /etc/localtime && <span class="built_in">echo</span> <span class="variable">$TZ</span> > /etc/timezone</span></span><br><span class="line"><span class="comment"># 拷贝jar包</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> docker-demo.jar /app.jar</span></span><br><span class="line"><span class="comment"># 入口</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="language-bash"> [<span class="string">"java"</span>, <span class="string">"-jar"</span>, <span class="string">"/app.jar"</span>]</span></span><br></pre></td></tr></table></figure><h3 id="docker-build命令使用">docker build命令使用</h3><blockquote><p>当编写好Dockerfile,可以使用docker build来进行打包</p></blockquote><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build -t myImage:10 .</span><br></pre></td></tr></table></figure><ul><li><strong>-t</strong>:是给镜像起名,格式为repository:tag的格式,不指定tag时,默认为latest</li><li><strong>.</strong> :是指定Dockerfile所在的目录,如果就在当前目录,则指定为“<strong>.</strong>”</li></ul><h2 id="docker-网络">Docker 网络</h2><blockquote><p>默认情况下,所有容器都是以bridge方式连接到docker的一个虚拟网桥(docker0;172.17.0.1/16)上 加入自定义网络的容器才可以通过容器名相互访问。</p></blockquote><table><colgroup><col style="width: 19%" /><col style="width: 8%" /><col style="width: 72%" /></colgroup><thead><tr><th>命令</th><th>说明</th><th>文档地址</th></tr></thead><tbody><tr><td>docker network create</td><td>创建一个网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/create/">dockernewwork create</a></td></tr><tr><td>docker network ls</td><td>查看所有网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/ls/">dockernetwork ls</a></td></tr><tr><td>docker network rm</td><td>删除指定网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/rm/">dockernetwork rm</a></td></tr><tr><td>docker network pruune</td><td>清除未使用的网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/pruune/">dockernetwork pruune</a></td></tr><tr><td>docker network connect</td><td>是指定容器加入某网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/connect/">dockernetwork connect</a></td></tr><tr><td>docker network disconnect</td><td>是指定容器连接离开网络</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/disconnect/">dockernetwork disconnect</a></td></tr><tr><td>docker newtwork inspect</td><td>查看网络详细信息</td><td><ahref="https://docs.docker.com/reference/cli/docker/network/inspect/">dockernetwork inspect</a></td></tr></tbody></table><p>创建一个网络:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network create 名字</span><br></pre></td></tr></table></figure><p>链接一个网络:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network connect 网络名字 容器名字</span><br></pre></td></tr></table></figure><p>创建时链接一个网络:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d --name 名字 -p 外部duank:内部端口 --network 网络名 镜像名</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h2 id="简单入门">简单入门</h2>
<h3 id="通过docker部署mysql">通过docker部署mysql</h3>
<figure class="highlight plaintext"><table><tr><td</summary>
<category term="学习笔记" scheme="https://blog.zs13.tech/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="linux" scheme="https://blog.zs13.tech/tags/linux/"/>
<category term="docker" scheme="https://blog.zs13.tech/tags/docker/"/>
</entry>
<entry>
<title>开源下载器aria2安装及配置(windows环境)</title>
<link href="https://blog.zs13.tech/posts/35411/"/>
<id>https://blog.zs13.tech/posts/35411/</id>
<published>2024-08-04T04:10:00.000Z</published>
<updated>2024-08-04T05:27:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="下载aria2">下载aria2</h2><div calss='anzhiyu-tag-link'><a class="tag-Link" target="_blank" href="https://github.com/aria2/aria2"> <div class="tag-link-tips">引用站外地址</div> <div class="tag-link-bottom"> <div class="tag-link-left" style=""> <i class="anzhiyufont anzhiyu-icon-link" style=""></i> </div> <div class="tag-link-right"> <div class="tag-link-title">aria2是一款开源支持多平台的下载器</div> <div class="tag-link-sitename">aria2</div> </div> <i class="anzhiyufont anzhiyu-icon-angle-right"></i> </div> </a></div><p>下载完成后解压即可。</p><h2 id="配置aria2">配置aria2</h2><p>aria2配置文件需要自己创建<code>aria2.conf</code>以下是我个人自用的aria2配置文件改自<code>PTERX</code>大佬的配置文件,同时创建<code>aria2.session</code>。<div calss='anzhiyu-tag-link'><a class="tag-Link" target="_blank" href="https://github.com/P3TERX/aria2.conf"> <div class="tag-link-tips">引用站外地址</div> <div class="tag-link-bottom"> <div class="tag-link-left" style=""> <i class="anzhiyufont anzhiyu-icon-link" style=""></i> </div> <div class="tag-link-right"> <div class="tag-link-title">Aria2完美配置</div> <div class="tag-link-sitename">PTERX</div> </div> <i class="anzhiyufont anzhiyu-icon-angle-right"></i> </div> </a></div></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br></pre></td><td class="code"><pre><span class="line">#</span><br><span class="line"># https://github.com/P3TERX/aria2.conf</span><br><span class="line"># File name:aria2.conf</span><br><span class="line"># Description: Awesome Aria2 configuration file</span><br><span class="line"># Version: 2021.09.15</span><br><span class="line">#</span><br><span class="line"># Copyright (c) 2018-2021 P3TERX <https://p3terx.com></span><br><span class="line">#</span><br><span class="line"># This is free software, licensed under the MIT License.</span><br><span class="line"># See /LICENSE for more information.</span><br><span class="line">#</span><br><span class="line"> </span><br><span class="line">## 文件保存设置 ##</span><br><span class="line"> </span><br><span class="line"># 下载目录。可使用绝对路径或相对路径, 默认: 当前启动位置</span><br><span class="line">dir=C:\Users\lingz\Downloads</span><br><span class="line"> </span><br><span class="line"># 磁盘缓存, 0 为禁用缓存,默认:16M</span><br><span class="line"># 磁盘缓存的作用是把下载的数据块临时存储在内存中,然后集中写入硬盘,以减少磁盘 I/O ,提升读写性能,延长硬盘寿命。</span><br><span class="line"># 建议在有足够的内存空闲情况下适当增加,但不要超过剩余可用内存空间大小。</span><br><span class="line"># 此项值仅决定上限,实际对内存的占用取决于网速(带宽)和设备性能等其它因素。</span><br><span class="line">disk-cache=64M</span><br><span class="line"></span><br><span class="line"># 文件预分配方式, 可选:none, prealloc, trunc, falloc, 默认:prealloc</span><br><span class="line"># 预分配对于机械硬盘可有效降低磁盘碎片、提升磁盘读写性能、延长磁盘寿命。</span><br><span class="line"># 机械硬盘使用 ext4(具有扩展支持),btrfs,xfs 或 NTFS(仅 MinGW 编译版本)等文件系统建议设置为 falloc</span><br><span class="line"># 若无法下载,提示 fallocate failed.cause:Operation not supported 则说明不支持,请设置为 none</span><br><span class="line"># prealloc 分配速度慢, trunc 无实际作用,不推荐使用。</span><br><span class="line"># 固态硬盘不需要预分配,只建议设置为 none ,否则可能会导致双倍文件大小的数据写入,从而影响寿命。</span><br><span class="line"></span><br><span class="line">file-allocation=none</span><br><span class="line"></span><br><span class="line"># 文件预分配大小限制。小于此选项值大小的文件不预分配空间,单位 K 或 M,默认:5M</span><br><span class="line">no-file-allocation-limit=64M</span><br><span class="line"> </span><br><span class="line"># 断点续传</span><br><span class="line">continue=true</span><br><span class="line"> </span><br><span class="line"># 始终尝试断点续传,无法断点续传则终止下载,默认:true</span><br><span class="line">always-resume=false</span><br><span class="line"></span><br><span class="line"># 不支持断点续传的 URI 数值,当 always-resume=false 时生效。</span><br><span class="line"># 达到这个数值从将头开始下载,值为 0 时所有 URI 不支持断点续传时才从头开始下载。</span><br><span class="line">max-resume-failure-tries=0</span><br><span class="line"></span><br><span class="line"># 获取服务器文件时间,默认:false</span><br><span class="line">remote-time=true</span><br><span class="line"></span><br><span class="line">## 进度保存设置 ##</span><br><span class="line"># 从会话文件中读取下载任务</span><br><span class="line">input-file=D:\aria2\aria2.session</span><br><span class="line"></span><br><span class="line"># 会话文件保存路径</span><br><span class="line"># Aria2 退出时或指定的时间间隔会保存`错误/未完成`的下载任务到会话文件</span><br><span class="line">save-session=D:\aria2\aria2.session</span><br><span class="line"></span><br><span class="line"># 任务状态改变后保存会话的间隔时间(秒), 0 为仅在进程正常退出时保存, 默认:0</span><br><span class="line"># 为了及时保存任务状态、防止任务丢失,此项值只建议设置为 1</span><br><span class="line">save-session-interval=1</span><br><span class="line"></span><br><span class="line"># 自动保存任务进度到控制文件(*.aria2)的间隔时间(秒),0 为仅在进程正常退出时保存,默认:60</span><br><span class="line"># 此项值也会间接影响从内存中把缓存的数据写入磁盘的频率</span><br><span class="line"># 想降低磁盘 IOPS (每秒读写次数)则提高间隔时间</span><br><span class="line"># 想在意外非正常退出时尽量保存更多的下载进度则降低间隔时间</span><br><span class="line"># 非正常退出:进程崩溃、系统崩溃、SIGKILL 信号、设备断电等</span><br><span class="line">auto-save-interval=60</span><br><span class="line"></span><br><span class="line"># 强制保存,即使任务已完成也保存信息到会话文件, 默认:false</span><br><span class="line"># 开启后会在任务完成后保留 .aria2 文件,文件被移除且任务存在的情况下重启后会重新下载。</span><br><span class="line"># 关闭后已完成的任务列表会在重启后清空。</span><br><span class="line">force-save=false</span><br><span class="line">## 下载连接设置 ##</span><br><span class="line"># 文件未找到重试次数,默认:0 (禁用)</span><br><span class="line"># 重试时同时会记录重试次数,所以也需要设置 max-tries 这个选项</span><br><span class="line">max-file-not-found=10</span><br><span class="line"></span><br><span class="line"># 最大尝试次数,0 表示无限,默认:5</span><br><span class="line">max-tries=0</span><br><span class="line"></span><br><span class="line"># 重试等待时间(秒), 默认:0 (禁用)</span><br><span class="line">retry-wait=10</span><br><span class="line"></span><br><span class="line"># 连接超时时间(秒)。默认:60</span><br><span class="line">connect-timeout=10</span><br><span class="line"></span><br><span class="line"># 超时时间(秒)。默认:60</span><br><span class="line">timeout=10</span><br><span class="line"></span><br><span class="line"># 最大同时下载任务数, 运行时可修改, 默认:5</span><br><span class="line">max-concurrent-downloads=5</span><br><span class="line"></span><br><span class="line"># 单服务器最大连接线程数, 任务添加时可指定, 默认:1</span><br><span class="line"># 最大值为 16 (增强版无限制), 且受限于单任务最大连接线程数(split)所设定的值。</span><br><span class="line">max-connection-per-server=16</span><br><span class="line"></span><br><span class="line"># 单任务最大连接线程数, 任务添加时可指定, 默认:5</span><br><span class="line">split=64</span><br><span class="line"></span><br><span class="line"># 文件最小分段大小, 添加时可指定, 取值范围 1M-1024M (增强版最小值为 1K), 默认:20M</span><br><span class="line"># 比如此项值为 10M, 当文件为 20MB 会分成两段并使用两个来源下载, 文件为 15MB 则只使用一个来源下载。</span><br><span class="line"># 理论上值越小使用下载分段就越多,所能获得的实际线程数就越大,下载速度就越快,但受限于所下载文件服务器的策略。</span><br><span class="line">min-split-size=4M</span><br><span class="line"></span><br><span class="line"># HTTP/FTP 下载分片大小,所有分割都必须是此项值的倍数,最小值为 1M (增强版为 1K),默认:1M</span><br><span class="line">piece-length=1M</span><br><span class="line"></span><br><span class="line"># 允许分片大小变化。默认:false</span><br><span class="line"># false:当分片大小与控制文件中的不同时将会中止下载</span><br><span class="line"># true:丢失部分下载进度继续下载</span><br><span class="line">allow-piece-length-change=true</span><br><span class="line"></span><br><span class="line"># 最低下载速度限制。当下载速度低于或等于此选项的值时关闭连接(增强版本为重连),此选项与 BT 下载无关。单位 K 或 M ,默认:0 (无限制)</span><br><span class="line">lowest-speed-limit=0</span><br><span class="line"></span><br><span class="line"># 全局最大下载速度限制, 运行时可修改, 默认:0 (无限制)</span><br><span class="line">max-overall-download-limit=0</span><br><span class="line"></span><br><span class="line"># 单任务下载速度限制, 默认:0 (无限制)</span><br><span class="line">max-download-limit=0</span><br><span class="line"></span><br><span class="line"># 禁用 IPv6, 默认:false</span><br><span class="line">disable-ipv6=false</span><br><span class="line"></span><br><span class="line"># GZip 支持,默认:false</span><br><span class="line">http-accept-gzip=true</span><br><span class="line"></span><br><span class="line"># URI 复用,默认: true</span><br><span class="line">reuse-uri=false</span><br><span class="line"></span><br><span class="line"># 禁用 netrc 支持,默认:false</span><br><span class="line">no-netrc=true</span><br><span class="line"># 允许覆盖,当相关控制文件(.aria2)不存在时从头开始重新下载。默认:false</span><br><span class="line">allow-overwrite=false</span><br><span class="line"># 文件自动重命名,此选项仅在 HTTP(S)/FTP 下载中有效。新文件名在名称之后扩展名之前加上一个点和一个数字(1..9999)。默认:true</span><br><span class="line">auto-file-renaming=true</span><br><span class="line"># 使用 UTF-8 处理 Content-Disposition ,默认:false</span><br><span class="line">content-disposition-default-utf8=true</span><br><span class="line"></span><br><span class="line"># 最低 TLS 版本,可选:TLSv1.1、TLSv1.2、TLSv1.3 默认:TLSv1.2</span><br><span class="line">#min-tls-version=TLSv1.2</span><br><span class="line"></span><br><span class="line">## BT/PT 下载设置 ##</span><br><span class="line"></span><br><span class="line"># BT 监听端口(TCP), 默认:6881-6999</span><br><span class="line"># 直通外网的设备,比如 VPS ,务必配置防火墙和安全组策略允许此端口入站</span><br><span class="line"># 内网环境的设备,比如 NAS ,除了防火墙设置,还需在路由器设置外网端口转发到此端口</span><br><span class="line">listen-port=51413</span><br><span class="line"></span><br><span class="line"># DHT 网络与 UDP tracker 监听端口(UDP), 默认:6881-6999</span><br><span class="line"># 因协议不同,可以与 BT 监听端口使用相同的端口,方便配置防火墙和端口转发策略。</span><br><span class="line">dht-listen-port=51413</span><br><span class="line"></span><br><span class="line"># 启用 IPv4 DHT 功能, PT 下载(私有种子)会自动禁用, 默认:true</span><br><span class="line">enable-dht=true</span><br><span class="line"></span><br><span class="line"># 启用 IPv6 DHT 功能, PT 下载(私有种子)会自动禁用,默认:false</span><br><span class="line"># 在没有 IPv6 支持的环境开启可能会导致 DHT 功能异常</span><br><span class="line">enable-dht6=false</span><br><span class="line"></span><br><span class="line"># 指定 BT 和 DHT 网络中的 IP 地址</span><br><span class="line"># 使用场景:在家庭宽带没有公网 IP 的情况下可以把 BT 和 DHT 监听端口转发至具有公网 IP 的服务器,在此填写服务器的 IP ,可以提升 BT 下载速率。</span><br><span class="line">#bt-external-ip=</span><br><span class="line"></span><br><span class="line"># IPv4 DHT 文件路径,默认:$HOME/.aria2/dht.dat</span><br><span class="line">dht-file-path=D:\aria2\dht.dat</span><br><span class="line"></span><br><span class="line"># IPv6 DHT 文件路径,默认:$HOME/.aria2/dht6.dat</span><br><span class="line">dht-file-path6=D:\aria2\dht6.dat</span><br><span class="line"></span><br><span class="line"># IPv4 DHT 网络引导节点</span><br><span class="line">dht-entry-point=dht.transmissionbt.com:6881</span><br><span class="line"></span><br><span class="line"># IPv6 DHT 网络引导节点</span><br><span class="line">dht-entry-point6=dht.transmissionbt.com:6881</span><br><span class="line"></span><br><span class="line"># 本地节点发现, PT 下载(私有种子)会自动禁用 默认:false</span><br><span class="line">bt-enable-lpd=false</span><br><span class="line"></span><br><span class="line"># 指定用于本地节点发现的接口,可能的值:接口,IP地址</span><br><span class="line"># 如果未指定此选项,则选择默认接口。</span><br><span class="line">#bt-lpd-interface=</span><br><span class="line"></span><br><span class="line"># 启用节点交换, PT 下载(私有种子)会自动禁用, 默认:true</span><br><span class="line">enable-peer-exchange=true</span><br><span class="line"></span><br><span class="line"># BT 下载最大连接数(单任务),运行时可修改。0 为不限制,默认:55</span><br><span class="line"># 理想情况下连接数越多下载越快,但在实际情况是只有少部分连接到的做种者上传速度快,其余的上传慢或者不上传。</span><br><span class="line"># 如果不限制,当下载非常热门的种子或任务数非常多时可能会因连接数过多导致进程崩溃或网络阻塞。</span><br><span class="line"># 进程崩溃:如果设备 CPU 性能一般,连接数过多导致 CPU 占用过高,因资源不足 Aria2 进程会强制被终结。</span><br><span class="line"># 网络阻塞:在内网环境下,即使下载没有占满带宽也会导致其它设备无法正常上网。因远古低性能路由器的转发性能瓶颈导致。</span><br><span class="line">bt-max-peers=55</span><br><span class="line"></span><br><span class="line"># BT 下载期望速度值(单任务),运行时可修改。单位 K 或 M 。默认:50K</span><br><span class="line"># BT 下载速度低于此选项值时会临时提高连接数来获得更快的下载速度,不过前提是有更多的做种者可供连接。</span><br><span class="line"># 实测临时提高连接数没有上限,但不会像不做限制一样无限增加,会根据算法进行合理的动态调节。</span><br><span class="line">bt-request-peer-speed-limit=50K</span><br><span class="line"></span><br><span class="line"># 全局最大上传速度限制, 运行时可修改, 默认:0 (无限制)</span><br><span class="line"># 设置过低可能影响 BT 下载速度</span><br><span class="line">max-overall-upload-limit=2M</span><br><span class="line"></span><br><span class="line"># 单任务上传速度限制, 默认:0 (无限制)</span><br><span class="line">max-upload-limit=0</span><br><span class="line"></span><br><span class="line"># 最小分享率。当种子的分享率达到此选项设置的值时停止做种, 0 为一直做种, 默认:1.0</span><br><span class="line"># 强烈建议您将此选项设置为大于等于 1.0</span><br><span class="line">seed-ratio=1.0</span><br><span class="line"></span><br><span class="line"># 最小做种时间(分钟)。设置为 0 时将在 BT 任务下载完成后停止做种。</span><br><span class="line">seed-time=3600</span><br><span class="line"># 做种前检查文件哈希, 默认:true</span><br><span class="line">bt-hash-check-seed=true</span><br><span class="line"></span><br><span class="line"># 继续之前的BT任务时, 无需再次校验, 默认:false</span><br><span class="line">bt-seed-unverified=false</span><br><span class="line"></span><br><span class="line"># BT tracker 服务器连接超时时间(秒)。默认:60</span><br><span class="line"># 建立连接后,此选项无效,将使用 bt-tracker-timeout 选项的值</span><br><span class="line">bt-tracker-connect-timeout=10</span><br><span class="line"></span><br><span class="line"># BT tracker 服务器超时时间(秒)。默认:60</span><br><span class="line">bt-tracker-timeout=10</span><br><span class="line"></span><br><span class="line"># BT 服务器连接间隔时间(秒)。默认:0 (自动)</span><br><span class="line">#bt-tracker-interval=0</span><br><span class="line"># BT 下载优先下载文件开头或结尾</span><br><span class="line">bt-prioritize-piece=head=32M,tail=32M</span><br><span class="line"></span><br><span class="line"># 保存通过 WebUI(RPC) 上传的种子文件(.torrent),默认:true</span><br><span class="line"># 所有涉及种子文件保存的选项都建议开启,不保存种子文件有任务丢失的风险。</span><br><span class="line"># 通过 RPC 自定义临时下载目录可能不会保存种子文件。</span><br><span class="line">rpc-save-upload-metadata=true</span><br><span class="line"></span><br><span class="line"># 下载种子文件(.torrent)自动开始下载, 默认:true,可选:false|mem</span><br><span class="line"># true:保存种子文件</span><br><span class="line"># false:仅下载种子文件</span><br><span class="line"># mem:将种子保存在内存中</span><br><span class="line">follow-torrent=true</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 种子文件下载完后暂停任务,默认:false</span><br><span class="line"># 在开启 follow-torrent 选项后下载种子文件或磁力会自动开始下载任务进行下载,而同时开启当此选项后会建立相关任务并暂停。</span><br><span class="line">pause-metadata=false</span><br><span class="line"></span><br><span class="line"># 保存磁力链接元数据为种子文件(.torrent), 默认:false</span><br><span class="line">bt-save-metadata=true</span><br><span class="line"></span><br><span class="line"># 加载已保存的元数据文件(.torrent),默认:false</span><br><span class="line">bt-load-saved-metadata=true</span><br><span class="line"></span><br><span class="line"># 删除 BT 下载任务中未选择文件,默认:false</span><br><span class="line">bt-remove-unselected-file=true</span><br><span class="line"></span><br><span class="line"># BT强制加密, 默认: false</span><br><span class="line"># 启用后将拒绝旧的 BT 握手协议并仅使用混淆握手及加密。可以解决部分运营商对 BT 下载的封锁,且有一定的防版权投诉与迅雷吸血效果。</span><br><span class="line"># 此选项相当于后面两个选项(bt-require-crypto=true, bt-min-crypto-level=arc4)的快捷开启方式,但不会修改这两个选项的值。</span><br><span class="line">bt-force-encryption=true</span><br><span class="line"></span><br><span class="line"># BT加密需求,默认:false</span><br><span class="line"># 启用后拒绝与旧的 BitTorrent 握手协议(\19BitTorrent protocol)建立连接,始终使用混淆处理握手。</span><br><span class="line">#bt-require-crypto=true</span><br><span class="line"></span><br><span class="line"># BT最低加密等级,可选:plain(明文),arc4(加密),默认:plain</span><br><span class="line">#bt-min-crypto-level=arc4</span><br><span class="line"></span><br><span class="line"># 分离仅做种任务,默认:false</span><br><span class="line"># 从正在下载的任务中排除已经下载完成且正在做种的任务,并开始等待列表中的下一个任务。</span><br><span class="line">bt-detach-seed-only=true</span><br><span class="line"></span><br><span class="line">## 客户端伪装 ##</span><br><span class="line"># 自定义 User Agent</span><br><span class="line">user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.47</span><br><span class="line"></span><br><span class="line"># BT 客户端伪装</span><br><span class="line"># PT 下载需要保持 user-agent 和 peer-agent 两个参数一致</span><br><span class="line"># 部分 PT 站对 Aria2 有特殊封禁机制,客户端伪装不一定有效,且有封禁账号的风险。</span><br><span class="line">#user-agent=Deluge 1.3.15</span><br><span class="line"># peer-agent=Deluge 1.3.15</span><br><span class="line"># peer-id-prefix=-DE13F0-</span><br><span class="line"></span><br><span class="line">## 执行额外命令 ##</span><br><span class="line"></span><br><span class="line"># 下载停止后执行的命令</span><br><span class="line"># 从 正在下载 到 删除、错误、完成 时触发。暂停被标记为未开始下载,故与此项无关。</span><br><span class="line"># on-download-stop=/root/.aria2/delete.sh</span><br><span class="line"># 下载完成后执行的命令</span><br><span class="line"># 此项未定义则执行 下载停止后执行的命令 (on-download-stop)</span><br><span class="line"># on-download-complete=/root/.aria2/clean.sh</span><br><span class="line"></span><br><span class="line"># 下载错误后执行的命令</span><br><span class="line"># 此项未定义则执行 下载停止后执行的命令 (on-download-stop)</span><br><span class="line">#on-download-error=</span><br><span class="line"># 下载暂停后执行的命令</span><br><span class="line">#on-download-pause=</span><br><span class="line"># 下载开始后执行的命令</span><br><span class="line">#on-download-start=</span><br><span class="line"># BT 下载完成后执行的命令</span><br><span class="line">#on-bt-download-complete=</span><br><span class="line">## RPC 设置 ##</span><br><span class="line"></span><br><span class="line"># 启用 JSON-RPC/XML-RPC 服务器, 默认:false</span><br><span class="line">enable-rpc=true</span><br><span class="line"></span><br><span class="line"># 接受所有远程请求, 默认:false</span><br><span class="line">rpc-allow-origin-all=false</span><br><span class="line"></span><br><span class="line"># 允许外部访问, 默认:false</span><br><span class="line">rpc-listen-all=false</span><br><span class="line"></span><br><span class="line"># RPC 监听端口, 默认:6800</span><br><span class="line">rpc-listen-port=6800</span><br><span class="line"></span><br><span class="line"># RPC 密钥</span><br><span class="line">rpc-secret=P3TERX</span><br><span class="line"></span><br><span class="line"># RPC 最大请求大小</span><br><span class="line">rpc-max-request-size=10M</span><br><span class="line"></span><br><span class="line"># RPC 服务 SSL/TLS 加密, 默认:false</span><br><span class="line"># 启用加密后必须使用 https 或者 wss 协议连接</span><br><span class="line"># 不推荐开启,建议使用 web server 反向代理,比如 Nginx、Caddy ,灵活性更强。</span><br><span class="line">#rpc-secure=false</span><br><span class="line"># 在 RPC 服务中启用 SSL/TLS 加密时的证书文件(.pem/.crt)</span><br><span class="line">#rpc-certificate=/root/.aria2/xxx.pem</span><br><span class="line"># 在 RPC 服务中启用 SSL/TLS 加密时的私钥文件(.key)</span><br><span class="line">#rpc-private-key=/root/.aria2/xxx.key</span><br><span class="line"># 事件轮询方式, 可选:epoll, kqueue, port, poll, select, 不同系统默认值不同</span><br><span class="line">#event-poll=select</span><br><span class="line"></span><br><span class="line">## 高级选项 ##</span><br><span class="line"># 启用异步 DNS 功能。默认:true</span><br><span class="line">#async-dns=true</span><br><span class="line"># 指定异步 DNS 服务器列表,未指定则从 /etc/resolv.conf 中读取。</span><br><span class="line">#async-dns-server=119.29.29.29,223.5.5.5,8.8.8.8,1.1.1.1</span><br><span class="line"></span><br><span class="line"># 指定单个网络接口,可能的值:接口,IP地址,主机名</span><br><span class="line"># 如果接口具有多个 IP 地址,则建议指定 IP 地址。</span><br><span class="line"># 已知指定网络接口会影响依赖本地 RPC 的连接的功能场景,即通过 localhost 和 127.0.0.1 无法与 Aria2 服务端进行讯通。</span><br><span class="line">#interface=</span><br><span class="line"></span><br><span class="line"># 指定多个网络接口,多个值之间使用逗号(,)分隔。</span><br><span class="line"># 使用 interface 选项时会忽略此项。</span><br><span class="line">#multiple-interface=</span><br><span class="line"></span><br><span class="line">## 日志设置 ##</span><br><span class="line"></span><br><span class="line"># 日志文件保存路径,忽略或设置为空为不保存,默认:不保存</span><br><span class="line">#log=</span><br><span class="line"># 日志级别,可选 debug, info, notice, warn, error 。默认:debug</span><br><span class="line">#log-level=warn</span><br><span class="line"></span><br><span class="line"># 控制台日志级别,可选 debug, info, notice, warn, error ,默认:notice</span><br><span class="line">console-log-level=notice</span><br><span class="line"></span><br><span class="line"># 安静模式,禁止在控制台输出日志,默认:false</span><br><span class="line">quiet=false</span><br><span class="line"></span><br><span class="line"># 下载进度摘要输出间隔时间(秒),0 为禁止输出。默认:60</span><br><span class="line">summary-interval=0</span><br><span class="line"></span><br><span class="line"># 关闭控制台进度条输出,避免日志里面打印大量空行</span><br><span class="line">show-console-readout=false</span><br><span class="line"></span><br><span class="line">## BitTorrent trackers ##</span><br><span class="line">bt-tracker=</span><br></pre></td></tr></table></figure><h3 id="配置自启动">配置自启动</h3><p>创建隐藏命令行窗口的启动文件<code>HideRun.vbs</code></p><figure class="highlight vbs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">CreateObject</span>(<span class="string">"WScript.Shell"</span>).Run <span class="string">"D:\aria2\aria2c.exe --conf-path=D:\aria2\aria2.conf"</span>,<span class="number">0</span></span><br></pre></td></tr></table></figure><p>在<code>计算机管理</code>里创建开机自启动任务 <imgsrc="https://bu.dusays.com/2024/08/04/66af10583708a.webp"alt="image.png" /></p><p><img src="https://bu.dusays.com/2024/08/04/66af10364aa82.webp"alt="image.png" /> <imgsrc="https://bu.dusays.com/2024/08/04/66af1066b22f3.webp"alt="image.png" /></p><h2 id="安装游览器插件">安装游览器插件</h2><p>firfox: <div calss='anzhiyu-tag-link'><a class="tag-Link" target="_blank" href="https://addons.mozilla.org/zh-CN/firefox/addon/aria2-integration/"> <div class="tag-link-tips">引用站外地址</div> <div class="tag-link-bottom"> <div class="tag-link-left" style=""> <i class="anzhiyufont anzhiyu-icon-link" style=""></i> </div> <div class="tag-link-right"> <div class="tag-link-title">Aria2 下载器集成组件</div> <div class="tag-link-sitename">Ross Wang</div> </div> <i class="anzhiyufont anzhiyu-icon-angle-right"></i> </div> </a></div></p>]]></content>
<summary type="html"><h2 id="下载aria2">下载aria2</h2>
<div calss='anzhiyu-tag-link'><a class="tag-Link" target="_blank" href="https://github.com/aria2/aria2">
</summary>
<category term="Windows日常" scheme="https://blog.zs13.tech/categories/Windows%E6%97%A5%E5%B8%B8/"/>
<category term="aria2" scheme="https://blog.zs13.tech/tags/aria2/"/>
<category term="windows" scheme="https://blog.zs13.tech/tags/windows/"/>
</entry>
<entry>
<title>vue入门(回忆.img)-黑马vue+spring项目学习笔记</title>
<link href="https://blog.zs13.tech/posts/5401/"/>
<id>https://blog.zs13.tech/posts/5401/</id>
<published>2024-07-01T00:47:00.000Z</published>
<updated>2024-07-23T05:27:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="vue入门">Vue入门</h2><h3 id="vue安装">Vue安装</h3><h4 id="通过es-模块快速将vue3导入到一个页面中">通过ES模块快速将vue3导入到一个页面中</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span>{{ message }}<span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp, ref } <span class="keyword">from</span> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">setup</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">const</span> message = <span class="title function_">ref</span>(<span class="string">'Hello Vue!'</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> message</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">'#app'</span>)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure><h3 id="v提供的常用指令">V提供的常用指令</h3><table><colgroup><col style="width: 42%" /><col style="width: 57%" /></colgroup><thead><tr><th>指令</th><th>作用</th></tr></thead><tbody><tr><td></td><td>列表渲染,遍历容器的元素或者对象的属性</td></tr><tr><td></td><td>为HTML标签绑定属性,如设置href,css样式</td></tr><tr><td></td><td>条件性的渲染某元素,判定为true时渲染,否则不渲染</td></tr><tr><td></td><td>根据条件展示某元素,区别在于切换的是display属性的值</td></tr><tr><td></td><td>在表单元素上创建双向数据绑定</td></tr><tr><td></td><td>为HTML标签绑定事件</td></tr></tbody></table><h4 id="v-for">v-for</h4><ul><li>作用:列表渲染,遍历容器的元素或者对象的属性</li><li>语法:v-for = “(item,index) in items”<ul><li>参数说明:<ul><li>items 为遍历的数组</li><li>item 为遍历出来的元素</li><li>index为索引/下标,从0开始;可以省略,省略index语法:v-for = “item initems”</li></ul></li></ul></li></ul><blockquote><p>简单案例</p></blockquote><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">table</span> <span class="attr">border</span>=<span class="string">"1 solid"</span> <span class="attr">colspa</span>=<span class="string">"0"</span> <span class="attr">cellspacing</span>=<span class="string">"0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>文章标题<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>分类<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>发表时间<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>状态<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>操作<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">tr</span> <span class="attr">v-for</span>=<span class="string">"(article,index) in articleList"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.title}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.category}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.time}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.state}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span>></span>编辑<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span>></span>删除<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">table</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//导入vue模块</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp} <span class="keyword">from</span></span></span><br><span class="line"><span class="language-javascript"> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//创建应用实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">data</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">articleList</span>:[</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>:<span class="string">"医疗反腐绝非砍医护收入"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>:<span class="string">"时事"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>:<span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>:<span class="string">"已发布"</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>:<span class="string">"中国男篮缘何一败涂地?"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>:<span class="string">"篮球"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>:<span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>:<span class="string">"草稿"</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>:<span class="string">"华山景区已受大风影响阵风达7-8级,未来24小时将持续"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>:<span class="string">"旅游"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>:<span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>:<span class="string">"已发布"</span></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> ]</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">"#app"</span>)<span class="comment">//控制页面元素</span></span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><p><img src="https://r2.zs13.eu.org/2024/07/202407010925331.webp" /></p><h4 id="v-bind">v-bind</h4><ul><li>作用:动态为HTML标签绑定属性值,如果设置href,sec,style样式等。</li><li>语法:v-bind:<code>属性名</code>:=“属性值”</li><li>简化::<code>属性名</code>=“属性值”</li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> <span class="comment"><!-- <a v-bind:href="URL">黑马官网</a> --></span></span><br><span class="line"> <span class="tag"><<span class="name">a</span> <span class="attr">:href</span>=<span class="string">"URL"</span>></span>黑马官网<span class="tag"></<span class="name">a</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//引入vue模块</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp} <span class="keyword">from</span></span></span><br><span class="line"><span class="language-javascript"> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//创建vue应用实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">data</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable constant_">URL</span> : <span class="string">'https://www.itheima.com'</span></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">"#app"</span>)<span class="comment">//控制html元素</span></span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><h4 id="v-ifv-show">v-if&v-show</h4><ul><li>作用:通过这两类指令,都是用来控制元素的显示与隐藏的</li><li>v-if<ul><li>语法:v-if=“表达式”,表达式值为 true,显示;false, 隐藏</li><li>其他:可以配合 v-else-if/v-else 进行链式调用条件判断</li><li>原理:<mark class="hl-label red">基于条件判断,来控制创建或移除元素节点(条件渲染)</mark> </li><li>场景:要么显示,要么不显示,不频繁切换的场景</li></ul></li><li>v-show<ul><li>语法:v-show=“表达式”,表达式值为 true,显示;false,隐藏</li><li>原理:<mark class="hl-label red">基于CSS样式display来控制显示与隐藏</mark> </li><li>场景:频繁切换显示的场景 <div class="note info flat"><p>v-if简单案例</p></div></li></ul></li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> 手链价格为:</span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-if</span>=<span class="string">"customer.level>=0 && customer.level<=1"</span>></span>9.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-else-if</span>=<span class="string">"customer.level>=2 && customer.level<=4"</span>></span>19.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-else</span>=></span>29.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> 手链价格为:</span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-show</span>=<span class="string">"customer.level>=0 && customer.level<=1"</span>></span>9.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-show</span>=<span class="string">"customer.level>=2 && customer.level<=4"</span>></span>19.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span> <span class="attr">v-show</span>=<span class="string">"customer.level>=5"</span>></span>29.9<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//导入vue模块</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp } <span class="keyword">from</span> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//创建vue应用实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">data</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">customer</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">name</span>: <span class="string">'张三'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">level</span>: <span class="number">2</span></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">"#app"</span>)<span class="comment">//控制html元素</span></span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><h4 id="v-on">v-on</h4><ul><li>作用:为html绑定事件</li><li>语法:<ul><li>v-on:事件名=“函数名”</li><li>简写为@时间名=“函数名”</li></ul></li><li><mark class="hl-label red">函数需要定义在methods内</mark> </li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> <span class="attr">v-on:click</span>=<span class="string">"money"</span>></span>点我有惊喜<span class="tag"></<span class="name">button</span>></span> <span class="symbol">&nbsp;</span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> @<span class="attr">click</span>=<span class="string">"love"</span>></span>再点更惊喜<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//导入vue模块</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp } <span class="keyword">from</span> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//创建vue应用实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">data</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//定义数据</span></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }, <span class="attr">methods</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">money</span>: <span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">alert</span>(<span class="string">"送你钱"</span>)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">love</span>: <span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">alert</span>(<span class="string">"爱你一万年"</span>)</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">"#app"</span>);<span class="comment">//控制html元素</span></span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><h4 id="v-model">v-model</h4><ul><li>作用:在表单元素上使用,<mark class="hl-label orange">双向数据绑定</mark> 。可以方便的<mark class="hl-label pink">获取或设置</mark> 表单项数据</li><li>语法:v-model=“变量名” <div class="note warning flat"><p>v-model 中绑定的变量,必须在data中定义。</p></div></li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>></span></span><br><span class="line"> 文章分类: <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">v-model</span>=<span class="string">"searchConditions.category"</span> /></span><span class="tag"><<span class="name">span</span>></span>{{searchConditions.category}}<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> 发布状态: <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">v-model</span>=<span class="string">"searchConditions.state"</span> /></span><span class="tag"><<span class="name">span</span>></span>{{searchConditions.state}}<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span>></span>搜索<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span> <span class="attr">v-on:click</span>=<span class="string">"clear"</span>></span>重置<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">br</span> /></span></span><br><span class="line"> <span class="tag"><<span class="name">br</span> /></span></span><br><span class="line"> <span class="tag"><<span class="name">table</span> <span class="attr">border</span>=<span class="string">"1 solid"</span> <span class="attr">colspa</span>=<span class="string">"0"</span> <span class="attr">cellspacing</span>=<span class="string">"0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>文章标题<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>分类<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>发表时间<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>状态<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">th</span>></span>操作<span class="tag"></<span class="name">th</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">tr</span> <span class="attr">v-for</span>=<span class="string">"(article,index) in articleList"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.title}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.category}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.time}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span>{{article.state}}<span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span>></span>编辑<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">button</span>></span>删除<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">td</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">tr</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">table</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"module"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//导入vue模块</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">import</span> { createApp } <span class="keyword">from</span> <span class="string">'https://unpkg.com/vue@3/dist/vue.esm-browser.js'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//创建vue应用实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">createApp</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">data</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">searchConditions</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>: <span class="string">''</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>: <span class="string">''</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//定义数据</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">articleList</span>: [{</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: <span class="string">"医疗反腐绝非砍医护收入"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>: <span class="string">"时事"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>: <span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>: <span class="string">"已发布"</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: <span class="string">"中国男篮缘何一败涂地?"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>: <span class="string">"篮球"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>: <span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>: <span class="string">"草稿"</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: <span class="string">"华山景区已受大风影响阵风达7-8级,未来24小时将持续"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>: <span class="string">"旅游"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>: <span class="string">"2023-09-5"</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">state</span>: <span class="string">"已发布"</span></span></span><br><span class="line"><span class="language-javascript"> }]</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">methods</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">clear</span>: <span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//在methods对应的方法里面,使用this就代表式vue实例,可以使用this获取到vue实例</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">searchConditions</span>.<span class="property">category</span> = <span class="string">""</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">searchConditions</span>.<span class="property">state</span> = <span class="string">''</span>;</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">mount</span>(<span class="string">"#app"</span>)<span class="comment">//控制html元素</span></span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><h2 id="vue生命周期">vue生命周期</h2><h3 id="钩子函数">钩子函数</h3><ul><li>生命周期的八个阶段:每个阶段会自动执行一个生命周期方法(钩子),让开发者有机会在特定的阶段执行自己的代码</li></ul><table><thead><tr><th>状态</th><th>阶段周期</th></tr></thead><tbody><tr><td>beforeCreate</td><td>创建前</td></tr><tr><td>created</td><td>创建后</td></tr><tr><td>beforeMount</td><td>载入前</td></tr><tr><td>mounted</td><td>挂载完成</td></tr><tr><td>beforeUpdate</td><td>数据更新前</td></tr><tr><td>updated</td><td>数据更新后</td></tr><tr><td>beforeUnmount</td><td>组件销毁前</td></tr><tr><td>unmounted</td><td>组件销毁后</td></tr></tbody></table><div class="note info flat"><p><code>mounted</code>最为重要</p></div><h2 id="axios异步请求">Axios异步请求</h2><ul><li>介绍:Axios对原生的Ajax进行了封装,简化书写,快速开发。</li><li>官网:<ahref="https://www.axios-http.cn">https://www.axios-http.cn</a></li></ul><h3 id="axios使用">Axios使用</h3><ul><li>引入Axios的js文件</li><li>使用Axios发生请求,并获取相应结果 安装Axios</li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://unpkg.com/axios/dist/axios.min.js"</span>></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure><h4 id="axios别名请求">Axios别名请求</h4><h5 id="get使用">get使用</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">script</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">axios.<span class="title function_">get</span>(<span class="string">"http://localhost:8080/article/getAll"</span>).<span class="title function_">then</span>(<span class="function"><span class="params">result</span>=></span>{</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//成功的回调</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//result代表服务器响应的所有数据,包含了响应头响应体</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>);</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">catch</span>(</span></span><br><span class="line"><span class="language-javascript"> <span class="function"><span class="params">result</span>=></span>{</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(err);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> );</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure><h5 id="post添加数据">post添加数据</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag"><<span class="name">script</span>></span><span class="language-javascript"> </span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">let</span> article={</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>:<span class="string">'明天会更好'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">category</span>:<span class="string">'生活'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">time</span>:<span class="string">'2000-02-02'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">stata</span>:<span class="string">'已发布'</span></span></span><br><span class="line"><span class="language-javascript"> } axios.<span class="title function_">post</span>(<span class="string">"http://localhost:8080/article/add"</span>,article).<span class="title function_">then</span>(<span class="function"><span class="params">result</span>=></span>{</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//成功的回调</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">//result代表服务器响应的所有数据,包含了响应头响应体</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>);</span></span><br><span class="line"><span class="language-javascript"> }).<span class="title function_">catch</span>(</span></span><br><span class="line"><span class="language-javascript"> <span class="function"><span class="params">result</span>=></span>{</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(err);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> );</span></span><br><span class="line"><span class="language-javascript"> </span><span class="tag"></<span class="name">script</span>></span></span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h2 id="vue入门">Vue入门</h2>
<h3 id="vue安装">Vue安装</h3>
<h4 id="通过es-模块快速将vue3导入到一个页面中">通过ES
模块快速将vue3导入到一个页面中</h4>
<figure class="highlight</summary>
<category term="黑马程序 vue+spring项目实现" scheme="https://blog.zs13.tech/categories/%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F-vue-spring%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/"/>
<category term="vue" scheme="https://blog.zs13.tech/tags/vue/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
</entry>
<entry>
<title>spring项目 文章篇-黑马vue+spring项目学习笔记</title>
<link href="https://blog.zs13.tech/posts/13529/"/>
<id>https://blog.zs13.tech/posts/13529/</id>
<published>2024-06-28T07:45:00.000Z</published>
<updated>2024-07-23T05:27:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="新增文章分类">新增文章分类</h2><div class="note flat"><ul><li>使用validation完成参数校验</li><li>在service层需要为Category的createUser、createTime、updateTime属性赋值</li></ul></div><h2 id="获取文章分类">获取文章分类</h2><h3 id="修改传出时间的json格式">修改传出时间的json格式</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//创建时间 </span></span><br><span class="line"><span class="meta">@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")</span> </span><br><span class="line"><span class="keyword">private</span> LocalDateTime createTime; </span><br><span class="line"><span class="comment">//更新时间 </span></span><br><span class="line"><span class="meta">@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")</span> </span><br><span class="line"><span class="keyword">private</span> LocalDateTime updateTime;</span><br></pre></td></tr></table></figure><h2 id="获取文章分页">获取文章分页</h2><blockquote><p>对应非必要参数可以在参数前面加上<code>@RequestParam(required = false)</code></p></blockquote>]]></content>
<summary type="html"><h2 id="新增文章分类">新增文章分类</h2>
<div class="note</summary>
<category term="文章分类" scheme="https://blog.zs13.tech/categories/%E6%96%87%E7%AB%A0%E5%88%86%E7%B1%BB/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="spring" scheme="https://blog.zs13.tech/tags/spring/"/>
<category term="spring项目" scheme="https://blog.zs13.tech/tags/spring%E9%A1%B9%E7%9B%AE/"/>
</entry>
<entry>
<title>spring项目 登录篇-黑马vue+spring项目学习笔记</title>
<link href="https://blog.zs13.tech/posts/2607/"/>
<id>https://blog.zs13.tech/posts/2607/</id>
<published>2024-06-27T08:12:00.000Z</published>
<updated>2024-07-23T05:28:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="登录认证">登录认证</h2><div class="note primary flat"><p>目标:让为登录的用户无法访问特定网页</p></div><h3 id="jwt令牌">JWT令牌</h3><p> 令牌是一段字符串 <div class="note info flat"><ul><li>承载业务数据,减少后续请求查询数据库的次数</li><li>防篡改,保证信息的合法性和有效性</li></ul></div></p><ul><li>全称 JSON Web Token(https://jwt.io/)</li><li>定义了一种简洁的、自包含的格式、用于通信双方以<code>json</code>格式<code>安全</code>的传输信息。</li><li>组成<ul><li>第一部分:Header,记录令牌类型、签名算法等。</li><li>第二部分:Payload(有效载荷),携带一些自定义信息、默认信息。</li><li>第三部分:Signature(签名),防止Token被篡改、确保安全性。将header、payload,并加入指定密钥,通过与指定签名算法而来。</li><li>通过Base64进行编码</li></ul></li></ul><h4 id="jwt相关依赖">JWT相关依赖</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.auth0<span class="tag"></<span class="name">groupId</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>java-jwt<span class="tag"></<span class="name">artifactId</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>4.4.0<span class="tag"></<span class="name">version</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></table></figure><h4 id="jwt令牌的生成">JWT令牌的生成</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> <span class="title function_">genToke</span><span class="params">()</span>{ </span><br><span class="line"> Map<String,Object> claims = <span class="keyword">new</span> <span class="title class_">HashMap</span><>(); </span><br><span class="line"> claims.put(<span class="string">"id"</span>,<span class="number">1</span>); </span><br><span class="line"> claims.put(<span class="string">"username"</span>,<span class="string">"zhangsan"</span>); </span><br><span class="line"> <span class="type">String</span> <span class="variable">Token</span> <span class="operator">=</span> JWT.create() </span><br><span class="line"> .withClaim(<span class="string">"user"</span>, claims) </span><br><span class="line"> .withExpiresAt(<span class="keyword">new</span> <span class="title class_">Date</span>(System.currentTimeMillis() + <span class="number">1000</span> * <span class="number">60</span> * <span class="number">60</span> * <span class="number">12</span>)) </span><br><span class="line"> .sign(Algorithm.HMAC256(<span class="string">"密钥"</span>)); </span><br><span class="line"> </span><br><span class="line"> System.out.println(Token); </span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="jwt令牌验证">JWT令牌验证</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">void</span> <span class="title function_">parseToken</span><span class="params">()</span>{</span><br><span class="line"> String token=<span class="string">"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"</span>+</span><br><span class="line"> <span class="string">".eyJ1c2VyIjp7ImlkIjoxLCJ1c2VybmFtZSI6InpoYW5nc2FuIn0sImV4cCI6MTcxOTUzNDgyNn0"</span>+</span><br><span class="line"> <span class="string">".RPFa6dpp3hYTAqsiBUnwkITSn9XWNBAnFhYacuuJBbw"</span>;</span><br><span class="line"> <span class="type">JWTVerifier</span> <span class="variable">jwtverifier</span> <span class="operator">=</span> JWT.require(Algorithm.HMAC256(<span class="string">"密钥"</span>)).build();</span><br><span class="line"> <span class="type">DecodedJWT</span> <span class="variable">decodedJWT</span> <span class="operator">=</span> jwtverifier.verify(token);</span><br><span class="line"> Map<String, Claim> claimMap = decodedJWT.getClaims();</span><br><span class="line"> System.out.println(claimMap.get(<span class="string">"user"</span>));</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="jwt工具类">JWT工具类</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> com.auth0.jwt.JWT; </span><br><span class="line"><span class="keyword">import</span> com. auth0.jwt.algorithms.Algorithm; </span><br><span class="line"><span class="keyword">import</span> java.util.Date; </span><br><span class="line"><span class="keyword">import</span> java.util.Map; </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JwtUtil</span> { </span><br><span class="line"> </span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">String</span> <span class="variable">KEY</span> <span class="operator">=</span> <span class="string">"lingzxl"</span>; </span><br><span class="line"> </span><br><span class="line"> <span class="comment">//接收业务数据,生成token并返回 </span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">genToken</span><span class="params">(Map<String, Object> claims)</span> { </span><br><span class="line"> <span class="keyword">return</span> JWT.create() </span><br><span class="line"> .withClaim(<span class="string">"claims"</span>, claims) </span><br><span class="line"> .withExpiresAt(<span class="keyword">new</span> <span class="title class_">Date</span>(System.currentTimeMillis() + <span class="number">1000</span> * <span class="number">60</span> * <span class="number">60</span> * <span class="number">12</span>)) </span><br><span class="line"> .sign(Algorithm.HMAC256(KEY)); </span><br><span class="line"> } </span><br><span class="line"> </span><br><span class="line"> <span class="comment">//接收token,验证token,并返回业务数据 </span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> Map<String, Object> <span class="title function_">parseToken</span><span class="params">(String token)</span> { </span><br><span class="line"> <span class="keyword">return</span> JWT.require(Algorithm.HMAC256(KEY)) </span><br><span class="line"> .build() </span><br><span class="line"> .verify(token) </span><br><span class="line"> .getClaim(<span class="string">"claims"</span>) </span><br><span class="line"> .asMap(); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="前置拦截器token验证">前置拦截器Token验证</h3><ol type="1"><li>创建<code>interceptors</code>包</li><li>创建<code>LoginInterceptor</code>类并实现<code>HandlerInterceptor</code></li><li>重写<code>preHandle</code>方法 >参考代码</li></ol><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">LoginInterceptor</span> <span class="keyword">implements</span> <span class="title class_">HandlerInterceptor</span> { </span><br><span class="line"> <span class="meta">@Override</span> </span><br><span class="line"> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">preHandle</span><span class="params">(HttpServletRequest request, HttpServletResponse response, Object handler)</span> <span class="keyword">throws</span> Exception { </span><br><span class="line"> <span class="type">String</span> <span class="variable">token</span> <span class="operator">=</span> request.getHeader(<span class="string">"Authorization"</span>); </span><br><span class="line"> <span class="keyword">try</span>{ </span><br><span class="line"> Map<String, Object> claims = JwtUtil.parseToken(token); </span><br><span class="line"> } <span class="keyword">catch</span> (Exception e){ </span><br><span class="line"> <span class="comment">//登录失败</span></span><br><span class="line"> <span class="comment">//设置http响应码为401 </span></span><br><span class="line"> response.setStatus(<span class="number">401</span>); </span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>; </span><br><span class="line"> } </span><br><span class="line"> <span class="comment">//登录成功</span></span><br><span class="line"> <span class="keyword">return</span> <span class="literal">true</span>; </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><ol start="4" type="1"><li>注册拦截器</li></ol><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebConfig</span> <span class="keyword">implements</span> <span class="title class_">WebMvcConfigurer</span> { </span><br><span class="line"> <span class="keyword">private</span> LoginInterceptor loginInterceptor; </span><br><span class="line"> <span class="meta">@Autowired</span> </span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setLoginInterceptor</span><span class="params">(LoginInterceptor loginInterceptor)</span>{ </span><br><span class="line"> <span class="built_in">this</span>.loginInterceptor=loginInterceptor; </span><br><span class="line"> } </span><br><span class="line"> <span class="meta">@Override</span> </span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">addInterceptors</span><span class="params">(InterceptorRegistry registry)</span> { </span><br><span class="line"> <span class="comment">//登录和注册接口不拦截 </span></span><br><span class="line"> registry.addInterceptor(loginInterceptor).excludePathPatterns(<span class="string">"/user/login"</span>,<span class="string">"/user/register"</span>); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2id="使得返回json数据是不传出password参数">使得返回json数据是不传出password参数</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@JsonIgnore</span> </span><br><span class="line"><span class="keyword">private</span> String password;</span><br></pre></td></tr></table></figure><h3 id="threadlocal">ThreadLocal</h3><p>提供线程局部变量 <div class="note info flat"><ul><li>用于存取数据:set()/get()</li><li>使用Threadloacl存储的数据,<code>线程安全</code></li><li>用完记得调用remove方法释放</li></ul></div></p><h4 id="使用原因">使用原因</h4><p> 使得解析Token之类的操作只进行一次,减少计算资源的消耗。</p><h4 id="工具代码">工具代码</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ThreadLocalUtil</span> { </span><br><span class="line"> <span class="comment">//提供ThreadLocal对象, </span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">ThreadLocal</span> <span class="variable">THREAD_LOCAL</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ThreadLocal</span>(); </span><br><span class="line"> </span><br><span class="line"> <span class="comment">//根据键获取值 </span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <T> T <span class="title function_">get</span><span class="params">()</span>{ </span><br><span class="line"> <span class="keyword">return</span> (T) THREAD_LOCAL.get(); </span><br><span class="line"> } </span><br><span class="line"> <span class="comment">//存储键值对 </span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">set</span><span class="params">(Object value)</span>{ </span><br><span class="line"> THREAD_LOCAL.set(value); </span><br><span class="line"> } </span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"> <span class="comment">//清除ThreadLocal 防止内存泄漏 </span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">remove</span><span class="params">()</span>{ </span><br><span class="line"> THREAD_LOCAL.remove(); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="后置拦截器">后置拦截器</h4><div class="note default flat"><ul><li>用于清除tomcat服务完一个请求后本地线程里的变量,防止内存泄漏</li></ul></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//后置拦截器 </span></span><br><span class="line"><span class="meta">@Override</span> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">afterCompletion</span><span class="params">(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)</span> <span class="keyword">throws</span> Exception { </span><br><span class="line"> <span class="comment">//清除ThreadLocal中的数据 </span></span><br><span class="line"> ThreadLocalUtil.remove(); </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="更新用户基本信息">更新用户基本信息</h2><div class="note flat"><ul><li>使用<code>@PutMapping("/update")</code>接收</li><li>在接受参数处写上<code>@RequestBody</code>用于把前端传入的json数据转换成User对象类</li></ul></div>]]></content>
<summary type="html"><h2 id="登录认证">登录认证</h2>
<div class="note primary flat"><p>目标:让为登录的用户无法访问特定网页</p>
</div>
<h3 id="jwt令牌">JWT令牌</h3>
<p> 令牌是一段字符串 <div</summary>
<category term="黑马程序 vue+spring项目实现" scheme="https://blog.zs13.tech/categories/%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F-vue-spring%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/categories/%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F-vue-spring%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="spring项目" scheme="https://blog.zs13.tech/tags/spring%E9%A1%B9%E7%9B%AE/"/>
</entry>
<entry>
<title>spring框架及使用-黑马vue+spring项目学习笔记</title>
<link href="https://blog.zs13.tech/posts/36171/"/>
<id>https://blog.zs13.tech/posts/36171/</id>
<published>2024-06-27T06:57:00.000Z</published>
<updated>2024-07-23T05:32:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="spring-validation">Spring Validation</h2><blockquote><p>spring提供的一个参数校验框架,使用预定义的注解完成参数校验 -直接写<code>if语句</code>数据校验过于繁琐一个参选可能就要写出好几个条件参数一多容易记混写错,同时代码阅读性差</p></blockquote><table><thead><tr><th>注解</th><th>作用</th></tr></thead><tbody><tr><td><span class="citation" data-cites="Pattern">@Pattern</span></td><td>通过正则表达式校验数据</td></tr><tr><td><span class="citation" data-cites="NotNull">@NotNull</span></td><td>值不能为Null</td></tr><tr><td><span class="citation" data-cites="NotEmpty">@NotEmpty</span></td><td>值不能为Null,并且内容不为空</td></tr><tr><td><span class="citation" data-cites="Email">@Email</span></td><td>满足邮箱格式</td></tr><tr><td><span class="citation" data-cites="URL">@URL</span></td><td>满足URL格式</td></tr></tbody></table><h3 id="pattern使用步骤"><span class="citation"data-cites="Pattern使用步骤">@Pattern使用步骤</span></h3><ol type="1"><li>引入Spring Validation起步依赖</li></ol><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><!--在maven项目的pom.xml中添加--></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-validation<span class="tag"></<span class="name">artifactId</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></table></figure><ol start="2" type="1"><li>在参数前面添加@Pattern注解</li></ol><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//使用正则表达 5-16个字符</span></span><br><span class="line"><span class="keyword">public</span> Result <span class="title function_">result</span><span class="params">(<span class="meta">@Pattern(regexp = "^\\S{5,16}$")</span> String username, <span class="meta">@Pattern(regexp = "^\\S{5,16}$")</span> String password)</span>{}</span><br></pre></td></tr></table></figure><ol start="3" type="1"><li>在Controller类上添加Validated</li></ol><h3 id="使用后一些问题的解决">使用后一些问题的解决</h3><h4 id="参数校验失败异常处理">参数校验失败异常处理</h4><ol type="1"><li>创建<code>exception</code>包存放异常处理类</li><li>创建全局异常处理类<code>GlobalExceptionHandler</code></li><li>在类上添加<code>@RestControllerAdvice</code>注解</li><li>使用springframework包下的StringUtils的hasLength可以判断e.gemMessage中是否有封装错误信息</li><li>不想用默认的报错信息也可以选择在@Pattern注解中传入message参数自定义报错信息</li></ol><ul><li>样例</li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">@RestControllerAdvice </span><br><span class="line">public class GlobalExceptionHandler { </span><br><span class="line"> @ExceptionHandler(Exception.class) </span><br><span class="line"> public Result handleException(Exception e) { </span><br><span class="line"> e.printStackTrace(); </span><br><span class="line"> return Result.error(StringUtils.hasLength(e.getMessage())? e.getMessage(): "未知错误"); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><div class="note info flat"><p>使用前效果</p></div><p><img src="https://r2.zs13.eu.org/2024/06/202406271504258.webp"alt="使用前效果" /> <div class="note success flat"><p>使用后效果</p></div> <imgsrc="https://r2.zs13.eu.org/2024/06/202406271540357.webp" /><imgsrc="https://r2.zs13.eu.org/2024/06/202406271540948.webp" /></p><h3 id="validated的使用"><span class="citation"data-cites="Validated的使用">@Validated的使用</span></h3><table><thead><tr><th>注解</th><th>作用</th></tr></thead><tbody><tr><td><span class="citation" data-cites="NotNull">@NotNull</span></td><td>值不能为Null</td></tr><tr><td><span class="citation" data-cites="NotEmpty">@NotEmpty</span></td><td>值不能为Null,并且内容不为空</td></tr><tr><td><span class="citation" data-cites="Email">@Email</span></td><td>满足邮箱格式</td></tr><tr><td><span class="citation" data-cites="Validated">@Validated</span></td><td>加在方法参数对象前面才可以使数据类中是注解生效</td></tr></tbody></table><h3 id="分组校验">分组校验</h3><blockquote><p>把校验项进行归类分组,在完成不同的功能的时候校验指定组中的校验项1.定义分组 2.定义校验项目时指定归属的分组 3.校验时指定要校验的分组</p></blockquote><h4 id="定义分组">定义分组</h4><div class="note info flat"><p>假设有有两个分组,分别为Add和Update,则在对应的pojo类中写出这两个名字的接口</p></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//设置分组</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">Add</span>{ </span><br><span class="line"> <span class="comment">//无内容</span></span><br><span class="line">} </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">Update</span>{ </span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="定义校验项目时指定归属的分组">定义校验项目时指定归属的分组</h4><div class="note info flat"><p>在要校验的对应属性的注解上添加grups分组</p></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//主键ID </span></span><br><span class="line"><span class="meta">@NotNull(groups = Update.class)</span> </span><br><span class="line"><span class="keyword">private</span> Integer id; </span><br><span class="line"><span class="comment">//分类名称 </span></span><br><span class="line"><span class="meta">@NotEmpty(groups = {Update.class,Add.class})</span> </span><br><span class="line"><span class="keyword">private</span> String categoryName;</span><br></pre></td></tr></table></figure><h4 id="校验时指定要校验的分组">校验时指定要校验的分组</h4><div class="note info flat"><p>在要校验的传入值的@Validated</p></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@PutMapping</span> </span><br><span class="line"><span class="keyword">public</span> Result <span class="title function_">update</span><span class="params">(<span class="meta">@RequestBody</span> <span class="meta">@Validated(Category.Update.class)</span> Category category)</span>{ </span><br><span class="line"> categoryService.update(category); </span><br><span class="line"> <span class="keyword">return</span> Result.success(); </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="默认分组及分组的继承">默认分组及分组的继承</h4><div class="note info flat"><p>如果说某个校验项没有指定分组,默认属于Default分组。分组之间可以继承,A extends B 那么A中拥有的B中所有的</p></div><h3 id="自定义校验">自定义校验</h3><blockquote><p>已有的注解不能满足所有的校验需求,特殊的情况下需要自定义校验(自定义校验注解)1.自定义注解State2.自定义校验数据的类StateValidation实现ConstraintValidator接口3.在需要校验的地方使用自定义校验</p></blockquote><h4 id="自定义注解state">自定义注解State</h4><blockquote><p>创建注解类State 注解类State中注解的含义</p></blockquote><table><colgroup><col style="width: 63%" /><col style="width: 36%" /></colgroup><thead><tr><th>注解</th><th>作用</th></tr></thead><tbody><tr><td><span class="citation"data-cites="Documented">@Documented</span></td><td>元注解</td></tr><tr><td><span class="citation"data-cites="Target">@Target</span>({ElementType.FIELD})</td><td>元注解 表面注解能用在什么上面</td></tr><tr><td><span class="citation"data-cites="Retention">@Retention</span>(RetentionPolicy.RUNTIME)</td><td>元注解 用于标注保留到什么阶段</td></tr><tr><td><span class="citation"data-cites="Constraint">@Constraint</span>(validatedBy ={StateValidation.class})</td><td>指定提供校验规则的类</td></tr></tbody></table><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//元注解 </span></span><br><span class="line"><span class="meta">@Documented</span> </span><br><span class="line"><span class="comment">//元注解 表面注解能用在什么上门 </span></span><br><span class="line"><span class="meta">@Target({ElementType.FIELD})</span> </span><br><span class="line"><span class="comment">//元注解 用于标注保留到什么阶段 </span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span> </span><br><span class="line"><span class="comment">//指定提供校验规则的类 </span></span><br><span class="line"><span class="meta">@Constraint(validatedBy = {StateValidation.class})</span> </span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> State { </span><br><span class="line"> <span class="comment">//提供校验失败后失败的提示信息 </span></span><br><span class="line"> String <span class="title function_">message</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">"state参数的值只能是已发布或者草稿"</span>; </span><br><span class="line"> <span class="comment">//指定分组 </span></span><br><span class="line"> Class<?>[] groups() <span class="keyword">default</span> {}; </span><br><span class="line"> <span class="comment">//负载 获取到State注解的附加信息 </span></span><br><span class="line"> Class<? <span class="keyword">extends</span> <span class="title class_">Payload</span>>[] payload() <span class="keyword">default</span> {}; </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4id="自定义校验数据的类statevalidation实现constraintvalidator接口">自定义校验数据的类StateValidation实现ConstraintValidator接口</h4><blockquote><p>创建StateValidation并实现ConstraintValidator<给那个注解提供校验规则,校验的数据类型>接口重写 <code>isValid</code>方法 如果返回<code>false</code>就不通过 返回<code>true</code> 通过</p></blockquote><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StateValidation</span> <span class="keyword">implements</span> <span class="title class_">ConstraintValidator</span><State,String> { </span><br><span class="line"> </span><br><span class="line"> <span class="comment">/** </span></span><br><span class="line"><span class="comment"> * * <span class="doctag">@param</span> s 将来要校验的数据 </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> constraintValidatorContext </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> 如果返回false就不通过 返回 true 通过 </span></span><br><span class="line"><span class="comment"> */</span> </span><br><span class="line"> <span class="meta">@Override</span> </span><br><span class="line"> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">isValid</span><span class="params">(String s, ConstraintValidatorContext constraintValidatorContext)</span> { </span><br><span class="line"> <span class="comment">//提供校验规则 </span></span><br><span class="line"> <span class="keyword">if</span>(s==<span class="literal">null</span>){ </span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>; </span><br><span class="line"> } </span><br><span class="line"> <span class="keyword">return</span> <span class="string">"已发布"</span>.equals(s) || <span class="string">"草稿"</span>.equals(s); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="spring-cache">Spring Cache</h2><div class="note info flat"><p>Spring Cahe是一个框架,实现了基于<code>注解</code>的缓存功能,只需要简单的添加一个注解,就能实现缓存功能。Spring Cache 提供了一层抽象,底层可以切换不同的缓存实现,例如: -EHCache - Caffeine - Redis</p></div><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-cache<span class="tag"></<span class="name">artifactId</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></table></figure><h3 id="常用注解">常用注解</h3><table><colgroup><col style="width: 19%" /><col style="width: 80%" /></colgroup><thead><tr><th>注解</th><th>说明</th></tr></thead><tbody><tr><td><span class="citation"data-cites="EnableCaching">@EnableCaching</span></td><td>开启缓存功能,通常加在启动类上</td></tr><tr><td><span class="citation" data-cites="Cacheable">@Cacheable</span></td><td>在方法执行前先查询缓存中是否有数据,如果有数据,则直接返回缓存结果;如果没有缓存数据,调用方法并将方法返回值放到缓存中</td></tr><tr><td><span class="citation" data-cites="CachePut">@CachePut</span></td><td>将方法的返回值放到缓存中</td></tr></tbody></table><div class="line-block"><span class="citation"data-cites="CacheEvict">@CacheEvict</span><br />将一条或多条数据从缓存中删除</div><h4 id="cacheput"><span class="citation"data-cites="CachePut">@CachePut</span></h4><blockquote><p>Spring EL表达式是Spring表达式语言,支持在xml和注解中使用表达式,类似于JSP的EL,JSTL表达式语言。Spring开发中我们会经常涉及到调用各种资源的情况,包含普通文件、网址、正则表达式、系统变量、其他Bean的一些属性、配置文件、集合等等,我们就可以使用Spring的表达式语言实现资源的注入。Spring EL的格式为 <em><strong>#{ SpEL expression }</strong></em>。Spring表达式主要写在注解 <strong><span class="citation"data-cites="Value">@Value</span></strong>的参数中,它的作用是通过spring把值注入给某个属性。</p></blockquote><p><img src="https://r2.zs13.eu.org/2024/07/202407151407409.webp" /></p><h2 id="spring-task">Spring Task</h2><h3 id="spirng-task-介绍">Spirng Task 介绍</h3><p>应用场景: - 信用卡每月还款提醒 - 银行贷款每月还款提醒 -火车售票系统处理未支付订单 - 入职纪念日为用户发送通知</p><h3 id="spring-task入门案例">Spring Task入门案例</h3><ol type="1"><li>导入Maven坐标Spring-context</li><li>启动类添加注解@EnableScheduling开启任务调度</li><li>自定义定时任务类</li></ol><p>样例 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span> </span><br><span class="line"><span class="meta">@Slf4j</span> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyTask</span> { </span><br><span class="line"> <span class="meta">@Scheduled(cron = "0/5 * * * * ?")</span> </span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">executeTask</span><span class="params">()</span>{ </span><br><span class="line"> log.info(<span class="string">"定时任务开始执行:{}"</span>,<span class="keyword">new</span> <span class="title class_">Date</span>()); </span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>]]></content>
<summary type="html"><h2 id="spring-validation">Spring Validation</h2>
<blockquote>
<p>spring提供的一个参数校验框架,使用预定义的注解完成参数校验</summary>
<category term="黑马程序 vue+spring项目实现" scheme="https://blog.zs13.tech/categories/%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F-vue-spring%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/categories/%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F-vue-spring%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="spring" scheme="https://blog.zs13.tech/tags/spring/"/>
</entry>
<entry>
<title>时间复杂度和空间复杂度</title>
<link href="https://blog.zs13.tech/posts/40486/"/>
<id>https://blog.zs13.tech/posts/40486/</id>
<published>2024-06-10T05:05:00.000Z</published>
<updated>2024-07-30T08:38:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="基础">基础</h2><ol type="1"><li>常数操作,固定时间的操作,执行时间和数据量无关</li><li>时间复杂度,一个和数据量有关、只要高阶项、不要低阶项、不要常数项的操作次数表达式</li><li>严格固定流程的算法,一定要强调最差情况!比如插入排序</li><li>算法流程上利用随机行为作为重要部分的,要看平均或者期望的时间复杂度,因为最差的时间复杂度无意义用生成相邻值不同的数组来说明</li><li>算法流程上利用随机行为作为重要部分的,还有随机快速排序</li><li>时间复杂度的内涵:描述算法运行时间和数据量大小的关系,且当数据量很大很大时,这种关系相当的本质,并且排除了低级项、常数时间的干扰</li><li>空间复杂度,强调额外空间:常数项时间,放弃理论分析、选择实验来确定,因为不同常数操作的时间不同</li><li>什么叫最有解,先满足时间复杂度最优,然后用尽量少用空间的解</li><li>时间复杂度的均摊,用动态数组的扩容来说明(等比数列、均摊的意义)</li><li>不要用代码结构来判断时间复杂度,比如只有一个while循环的冒泡排序,其时间复杂度O(N^2)</li><li>不要用代码结构开判断时间复杂度,比如:N/1+N/2+N/3+…N/N,这个流程的时间复杂度时O(N*logN)</li><li>时间复杂度只能是对算法流程充分理解才能分析出来,而不是简单的看代码结构!这是一个常见的错误!甚至有些算法的实现用了多层循环嵌套,但时间复杂度是O(N)的。</li></ol><h2 id="知识点">知识点</h2><h3 id="求中点">求中点</h3><p> 正常想法为<code>mid</code>=(<code>L</code>+<code>R</code>)/2,但在特殊情况下可能会溢出导致结果的不准确如两个值都很大的时候<code>L+R</code>会<code>溢出</code>,此时可以把<code>L</code>提取出来变成<code>mid = L + (R-L)/2</code>。 > 在程序里可以写成 <code>mid = L + ((R-L) >> 1)</code>;算术左移一位等同于除以2 比使用<code>/</code>性能更好。</p><h3id="递归行为时间复杂度计算master公式">递归行为时间复杂度计算(master公式)</h3><p>T(N)=a*T(N/b)+O(N^c) 母 次 子</p><table><thead><tr><th>公式</th><th>时间复杂度</th><th></th></tr></thead><tbody><tr><td>logb(a) < c</td><td>O(N^c)</td><td></td></tr><tr><td>logb(a) > c</td><td>O(N^logb(a))</td><td></td></tr><tr><td>logb(a) == c</td><td>O(N^c*logN)</td><td></td></tr></tbody></table>]]></content>
<summary type="html"><h2 id="基础">基础</h2>
<ol</summary>
<category term="数据结构与算法" scheme="https://blog.zs13.tech/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="https://blog.zs13.tech/tags/%E7%AE%97%E6%B3%95/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="数据结构" scheme="https://blog.zs13.tech/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"/>
</entry>
<entry>
<title>认识O(NlogN) 递归</title>
<link href="https://blog.zs13.tech/posts/40486/"/>
<id>https://blog.zs13.tech/posts/40486/</id>
<published>2024-06-10T05:05:00.000Z</published>
<updated>2024-10-09T01:59:58.491Z</updated>
<content type="html"><![CDATA[<h1 id="知识点">知识点</h1><h2 id="求中点">求中点</h2><p> 正常想法为<code>mid</code>=(<code>L</code>+<code>R</code>)/2,但在特殊情况下可能会溢出导致结果的不准确如两个值都很大的时候<code>L+R</code>会<code>溢出</code>,此时可以把<code>L</code>提取出来变成<code>mid = L + (R-L)/2</code>。 > 在程序里可以写成 <code>mid = L + ((R-L) >> 1)</code>;算术左移一位等同于除以2 比使用<code>/</code>性能更好。 ##递归行为时间复杂度计算(master公式) T(N)=a*T(N/b)+O(N^d) 母 次 子</p><table><thead><tr><th>公式</th><th>时间复杂度</th><th></th></tr></thead><tbody><tr><td>logb(a) < d</td><td>O(N^d)</td><td></td></tr><tr><td>logb(a) > d</td><td>O(N^logb(a))</td><td></td></tr><tr><td>logb(a) == d</td><td>O(N^d*logN)</td><td></td></tr></tbody></table>]]></content>
<summary type="html"><h1 id="知识点">知识点</h1>
<h2 id="求中点">求中点</h2>
<p> </summary>
<category term="数据结构与算法" scheme="https://blog.zs13.tech/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="https://blog.zs13.tech/tags/%E7%AE%97%E6%B3%95/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="数据结构" scheme="https://blog.zs13.tech/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"/>
</entry>
<entry>
<title>复杂度与简单排序算法</title>
<link href="https://blog.zs13.tech/posts/21118/"/>
<id>https://blog.zs13.tech/posts/21118/</id>
<published>2024-06-05T05:42:00.000Z</published>
<updated>2024-08-02T09:06:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="前置知识点的学习">前置知识点的学习</h2><h3 id="计算机逻辑运算">计算机逻辑运算</h3><div class="note info flat"><ul><li>与 :当所有输入条件同时满足1,输出1;输入条件只要有0就输出0。java :&</li><li>或:输入条件有1即输出1;一个1也没有才输出0。java : |</li><li>非:输出结果与输入条件取反。0变1,1变0。 java : !</li><li>异或:仅当两输入取不同的值时异或结果为1;否则均为0。java : ^可以理解为无进位加法</li></ul></div><p><code>异或</code>的规则: 1. 0^N= N N^N=0 2. 符合交换律和结合率A<sup>B=B</sup>A (A<sup>B)</sup>B=A<sup>(B</sup>C)</p><h4 id="通过异或运算交换两个变量的值">通过异或运算交换两个变量的值</h4><div class="note warning flat"><p>如果a和b指向同一个内存会导致N^N=0,而出现问题,在平时不推荐使用。</p></div><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">main</span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> <span class="type">int</span> <span class="variable">a</span> <span class="operator">=</span> <span class="number">234</span>;</span><br><span class="line"> <span class="type">int</span> <span class="variable">b</span> <span class="operator">=</span> <span class="number">349</span>;</span><br><span class="line"> a = a ^ b;</span><br><span class="line"> b = a ^ b;</span><br><span class="line"> a = a ^ b;</span><br><span class="line"> System.out.println(<span class="string">"a:"</span>+a+<span class="string">" "</span>+<span class="string">"b:"</span>+b);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">//运行结果为a:349 b:234</span></span><br></pre></td></tr></table></figure><h2 id="复杂度计算">复杂度计算</h2><p> 以<code>冒泡排序</code>为例:冒泡排序每次循环所用的时间分别为1<sub>n-1,1</sub>n-2,1-n<sub>3,…,1</sub>2。为一个<code>d</code>为<code>1</code>的<code>等差数列</code>则这个算法的时间消耗为<code>Sn=n*a1+n(n-1)d/2</code>去掉<code>常数</code>和<code>低次幂的数</code>只保留<code>最高次幂的数</code>结果为O(n²)。 >时间复杂度按算法的最坏情况记。例:插入排序最好情况O(N),最坏情况O(N²)。</p><h2id="提取出一个二进制数最右的一个1所在的位置">提取出一个二进制数最右的一个1所在的位置</h2><table><thead><tr><th>变量名</th><th>二进制数</th></tr></thead><tbody><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr></tbody></table><div class="line-block"></div><h2id="常见排序算法时间复杂度和空间复杂度">常见排序算法时间复杂度和空间复杂度</h2><p><img src="https://r2.zs13.eu.org/2024/06/202406051749013.webp" /></p>]]></content>
<summary type="html"><h2 id="前置知识点的学习">前置知识点的学习</h2>
<h3 id="计算机逻辑运算">计算机逻辑运算</h3>
<div class="note info flat"><ul>
<li>与 :当所有输入条件同时满足1,输出1;输入条件只要有0就输出0。java</summary>
<category term="数据结构与算法" scheme="https://blog.zs13.tech/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="https://blog.zs13.tech/tags/%E7%AE%97%E6%B3%95/"/>
<category term="学习笔记" scheme="https://blog.zs13.tech/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<category term="数据结构" scheme="https://blog.zs13.tech/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"/>
</entry>
<entry>
<title>Windows重装后配置-软件安装篇</title>
<link href="https://blog.zs13.tech/posts/14369/"/>
<id>https://blog.zs13.tech/posts/14369/</id>
<published>2024-04-18T14:36:00.000Z</published>
<updated>2024-08-26T05:24:00.000Z</updated>
<content type="html"><![CDATA[<h2 id="前期准备">前期准备</h2><h3 id="必要的一些软件">必要的一些软件</h3><h4 id="图吧工具箱">图吧工具箱</h4><p>拥有安装系统(重装)后一些实用的软件,可以对硬件进行稳定性测试; <imgsrc="https://www.tbtool.cn/rc_images/__.png" /> <ahref="https://www.tbtool.cn/">点击前往官网</a></p><h4 id="加速访问github工具">加速访问github工具</h4><h4 id="steamwatt-toolkit">steam++(Watt Toolkit)</h4><p><img src="https://steampp.net/images/home/js.webp" /></p><table><colgroup><col style="width: 8%" /><col style="width: 91%" /></colgroup><thead><tr><th>下载地址</th><th>链接</th></tr></thead><tbody><tr><td>官网</td><td><a href="https://steampp.net/">Watt Toolkit</a></td></tr><tr><td>github</td><td>https://github.com/BeyondDimension/SteamTools</td></tr><tr><td>gitee</td><td>https://gitee.com/rmbgame/SteamTools</td></tr><tr><td>微软商店</td><td>https://apps.microsoft.com/detail/9mtcfhs560ng?hl=en-us&gl=US</td></tr></tbody></table><h4id="驱动安装软件可选推荐准备一个">驱动安装软件(可选,推荐准备一个)</h4><p>个别系统镜像安装后可能没有网卡驱动这时就需要一个带网卡驱动的驱动安装器帮忙安装驱动,如果系统安装后有网卡驱动则可以跳过windows会自带下载需要的驱动。<a href="http://drivergenius.com/wangka/">驱动精灵网卡版</a></p><h4 id="系统激活工具可选">系统激活工具(可选)</h4><p>有能力的推荐支持正版oem机器一般来说不需要这个,主板有会内置激活码自动激活windows。kms:https://github.com/zbezj/HEU_KMS_Activator/releases</p><h4 id="代理工具可选">代理工具(可选)</h4><p>因为国内网络下载编程所需的安装包有时很慢所以有使用外网的需求,没有使用外网的可以跳过。</p><table><colgroup><col style="width: 17%" /><col style="width: 82%" /></colgroup><thead><tr><th>代理工具</th><th>链接</th></tr></thead><tbody><tr><td>clash-verge-rev</td><td><ahref="https://github.com/clash-verge-rev/clash-verge-rev">clash-verge-rev</a></td></tr><tr><td>v2rayN</td><td><a href="https://github.com/2dust/v2rayN">v2rayN</a></td></tr></tbody></table><h3 id="系统盘制作">系统盘制作</h3><h5 id="系统盘制作工具">系统盘制作工具</h5><table><colgroup><col style="width: 2%" /><col style="width: 17%" /><col style="width: 2%" /><col style="width: 77%" /></colgroup><thead><tr><th>制作工具</th><th>链接</th><th>推荐等级</th><th>区别</th></tr></thead><tbody><tr><td>微PE工具箱</td><td>https://www.wepe.com.cn/download.html</td><td>★★★★★</td><td>优点:一款清量无广告的pe制作工具,内置了多个重装系统会用到的工具(磁盘管理,eif修复)可以方便的修复<mark class="hl-label blue">windows</mark> 系统。兼容性好。<br>缺点:只能用于<mark class="hl-label blue">windows</mark> 系统的安装,无法用于<mark class="hl-label orange">linux</mark> 系统。</td></tr><tr><td>ventoy</td><td>https://www.ventoy.net/cn/</td><td>★★★★☆</td><td>优点:支持多个操作系统,可用用来安装<mark class="hl-label orange">linux</mark> 系统,启动使用了grub支持自定义启动页面。<br>缺点:设置相对于微pe复杂需要进行一定的配置不自带磁盘管理之类的软件(可以导入微pe的iso曲线救国),兼容性不然微pe,在给别电脑上要关闭安全启动才可以被引导启动(比如我的联想拯救者)</td></tr><tr><td>rufus</td><td>https://rufus.ie/zh/</td><td>★★★☆☆</td><td>优点:一款功能简单命令的系统盘制作工具,选择系统精选然后制作即可,轻量快速。可以用来安装<mark class="hl-label orange">linux</mark> <br>缺点:只支持单一系统,不能同时存放多个系统如<mark class="hl-label blue">windows10</mark> 和<mark class="hl-label blue">windows11</mark> </td></tr></tbody></table><h5 id="系统镜像下载">系统镜像下载</h5><table><colgroup><col style="width: 8%" /><col style="width: 91%" /></colgroup><thead><tr><th>系统镜像</th><th>下载链接</th></tr></thead><tbody><tr><td>windows</td><td>老牌下载网站:<ahref="https://next.itellyou.cn/Identity/Account/Login?ReturnUrl=%2FOriginal%2FIndex">MSDN</a></td></tr><tr><td>ubuntu</td><td>https://cn.ubuntu.com/download</td></tr><tr><td>archlinux</td><td>https://archlinux.org/download/</td></tr></tbody></table><h2 id="安装完成激活系统后相关配置">安装完成激活系统后相关配置</h2><h3 id="安装防火墙软件">安装防火墙软件</h3><p>安装防火墙让windows defender闭嘴。 我安装的是<ahref="https://www.huorong.cn/">火绒</a>我不要去他杀毒能力有多好,我的需求就是轻量,然后能让Windowsdefender闭嘴。</p><h3 id="winget安装软件">winget安装软件</h3><p>使用winget安装的好处,不用到处下载软件包还要经常更新软件包,可以一个命令就安装最新的软件包。winget安装大量软件脚本生成网站:https://winstall.app/</p><h4 id="安装代理">安装代理</h4><p>winget不使用代理下载软件包会相当的慢,切换国内源也不能让第三方下的东西变快比如python的安装包。</p><h4 id="软件列表">软件列表</h4><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#游览器</span></span><br><span class="line">winget install <span class="literal">--id</span>=Mozilla.Firefox <span class="literal">-e</span> <span class="comment">#火狐</span></span><br><span class="line">winget install <span class="literal">--id</span>=Google.Chrome <span class="literal">-e</span> <span class="comment">#谷歌</span></span><br><span class="line"><span class="comment">#下载软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=c0re100.qBittorrent<span class="literal">-Enhanced-Edition</span> <span class="literal">-e</span> <span class="comment">#qbit增强版</span></span><br><span class="line">winget install <span class="literal">--id</span>=Alibaba.aDrive <span class="literal">-e</span> <span class="comment">#阿里网盘</span></span><br><span class="line"><span class="comment">#游戏</span></span><br><span class="line">winget install <span class="literal">--id</span>=Valve.Steam <span class="literal">-e</span> <span class="comment">#steam</span></span><br><span class="line"><span class="comment">#录屏</span></span><br><span class="line">winget install <span class="literal">--id</span>=OBSProject.OBSStudio <span class="literal">-e</span> <span class="comment">#obs</span></span><br><span class="line"><span class="comment">#makrdwon笔记(blog用)</span></span><br><span class="line">winget install <span class="literal">--id</span>=Obsidian.Obsidian <span class="literal">-e</span></span><br><span class="line">winget install <span class="literal">--id</span>=SaeraSoft.CaesiumImageCompressor <span class="literal">-e</span> <span class="comment">#图片压缩软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=PicGo.PicGo <span class="literal">-e</span> <span class="comment">#picgo 图片上次图床软件</span></span><br><span class="line"><span class="comment">#通讯软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=Xiaoyaoyixia.KOOK <span class="literal">-e</span> <span class="comment">#kook</span></span><br><span class="line">winget install <span class="literal">--id</span>=Tencent.QQ.NT <span class="literal">-e</span> <span class="comment">#qq</span></span><br><span class="line">winget install <span class="literal">--id</span>=Tencent.WeChat <span class="literal">-e</span> <span class="comment">#微信</span></span><br><span class="line">winget install <span class="literal">--id</span>=Alibaba.DingTalk <span class="literal">-e</span> <span class="comment">#钉钉</span></span><br><span class="line">winget install <span class="literal">--id</span>=Tencent.TencentMeeting <span class="literal">-e</span> <span class="comment">#腾讯会议</span></span><br><span class="line"><span class="comment">#音乐软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=Spotify.Spotify <span class="literal">-v</span> <span class="string">"undefined"</span> <span class="literal">-e</span> <span class="comment">#spotify</span></span><br><span class="line">winget install <span class="literal">--id</span>=NetEase.CloudMusic.Beta <span class="literal">-e</span> <span class="comment">#网易云音乐</span></span><br><span class="line"><span class="comment">#压缩软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=M2Team.NanaZip <span class="literal">-e</span> <span class="comment">#nana 7zip的分支项目支持win11的右键</span></span><br><span class="line">winget install <span class="literal">--id</span>=<span class="number">7</span>zip.<span class="number">7</span>zip <span class="literal">-e</span> <span class="comment">#7-zip</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#编程相关软件</span></span><br><span class="line">winget install <span class="literal">--id</span>=JetBrains.IntelliJIDEA.Ultimate <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=Git.Git <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=Microsoft.VisualStudioCode <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=PremiumSoft.NavicatPremium <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=Eugeny.Tabby <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=Canonical.Ubuntu.<span class="number">2204</span> <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=WinSCP.WinSCP <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=Oracle.MySQL <span class="literal">-e</span> ;</span><br><span class="line">winget install <span class="literal">--id</span>=OpenJS.NodeJS.LTS <span class="literal">-e</span> </span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h2 id="前期准备">前期准备</h2>
<h3 id="必要的一些软件">必要的一些软件</h3>
<h4 id="图吧工具箱">图吧工具箱</h4>
<p>拥有安装系统(重装)后一些实用的软件,可以对硬件进行稳定性测试;</summary>
<category term="Windows日常" scheme="https://blog.zs13.tech/categories/Windows%E6%97%A5%E5%B8%B8/"/>
<category term="软件" scheme="https://blog.zs13.tech/tags/%E8%BD%AF%E4%BB%B6/"/>
<category term="配置" scheme="https://blog.zs13.tech/tags/%E9%85%8D%E7%BD%AE/"/>
<category term="winget" scheme="https://blog.zs13.tech/tags/winget/"/>
<category term="windows" scheme="https://blog.zs13.tech/tags/windows/"/>
</entry>
<entry>
<title>archlinux 踩坑日记</title>
<link href="https://blog.zs13.tech/posts/50857/"/>
<id>https://blog.zs13.tech/posts/50857/</id>
<published>2024-01-07T04:40:00.000Z</published>
<updated>2024-07-23T05:25:00.000Z</updated>
<content type="html"><![CDATA[<p><imgsrc="https://cdn.jsdelivr.net/gh/lingzs13/img-cloud//img/screen_shot_.png" /></p><h2 id="n卡硬件解码">N卡硬件解码</h2><h3 id="安装必要的插件">安装必要的插件</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sudo pacman -S linux-headers #这个一定要装</span><br><span class="line">sudo pacman -S nvidia-dkms nvidia-settings nvidia-utils #nvidia相关驱动</span><br><span class="line">sudo pacman -S libva-utils #提供硬件解码的包 </span><br><span class="line">yay -S libva-nvidia-driver-git #重要!!!在我的电脑上libva-nvidia-driver这个包无法使用硬件加速git版才可以 浪费了我很多的时间!!!!</span><br></pre></td></tr></table></figure><h3 id="可选添加n卡驱动早启动">(可选)添加n卡驱动早启动</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /etc/mkinitcpio.conf</span><br><span class="line">在第一各MODULES=()添加nvidia、nvidia_modeset、nvidia_uvm 和nvidia_drm这几个参数</span><br><span class="line">-------------------------------------------------------------</span><br><span class="line">MODULES=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)</span><br><span class="line">-------------------------------------------------------------</span><br><span class="line">同时去掉下方HOOKS=()中的 kms 这个参数</span><br></pre></td></tr></table></figure><h3 id="修改gurb保证能够启动">修改gurb保证能够启动</h3><p>修改<code>/etc/default/grub</code>中的<code>GRUB_CMDLINE_LINUX_DEFAULT</code>选项添加<code>vidia_drm.modeset=1</code> 这一参数。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">以下是我的grub中前几行的参数</span><br><span class="line">—————————————————————————————————————————————————————————————</span><br><span class="line">GRUB_DEFAULT=0</span><br><span class="line">GRUB_TIMEOUT=5</span><br><span class="line">GRUB_DISTRIBUTOR="Arch"</span><br><span class="line">GRUB_CMDLINE_LINUX_DEFAULT="loglevel=5 nowatchdog nvidia_drm.modeset=1 "</span><br><span class="line">GRUB_CMDLINE_LINUX=""</span><br><span class="line">—————————————————————————————————————————————————————————————</span><br><span class="line">添加完成后使用</span><br><span class="line">sudo grub-mkconfig -o /boot/grub/grub.cfg</span><br><span class="line">来更新grub</span><br><span class="line">要记得重启哦!</span><br></pre></td></tr></table></figure><h3 id="检查va-api">检查va-api</h3><p>运行 <ahref="https://archlinux.org/packages/?name=libva-utils">libva-utils</a>包包提供的 <code>vainfo</code> 来检查 VA-API 的设置:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">以下是我的运行结果,没出来就代表未启动硬件加速</span><br><span class="line">-------------------------------------------------------------</span><br><span class="line">Trying display: wayland</span><br><span class="line">vainfo: VA-API version: 1.20 (libva 2.20.1)</span><br><span class="line">vainfo: Driver version: VA-API NVDEC driver [direct backend]</span><br><span class="line">vainfo: Supported profile and entrypoints</span><br><span class="line"> VAProfileMPEG2Simple :VAEntrypointVLD</span><br><span class="line"> VAProfileMPEG2Main :VAEntrypointVLD</span><br><span class="line"> VAProfileVC1Simple :VAEntrypointVLD</span><br><span class="line"> VAProfileVC1Main :VAEntrypointVLD</span><br><span class="line"> VAProfileVC1Advanced :VAEntrypointVLD</span><br><span class="line"> VAProfileH264Main :VAEntrypointVLD</span><br><span class="line"> VAProfileH264High :VAEntrypointVLD</span><br><span class="line"> VAProfileH264ConstrainedBaseline:VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain :VAEntrypointVLD</span><br><span class="line"> VAProfileVP8Version0_3 :VAEntrypointVLD</span><br><span class="line"> VAProfileVP9Profile0 :VAEntrypointVLD</span><br><span class="line"> VAProfileAV1Profile0 :VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain10 :VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain12 :VAEntrypointVLD</span><br><span class="line"> VAProfileVP9Profile2 :VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain444 :VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain444_10 :VAEntrypointVLD</span><br><span class="line"> VAProfileHEVCMain444_12 :VAEntrypointVLD</span><br></pre></td></tr></table></figure><h3 id="修改firefox配置启用硬件加速">修改firefox配置启用硬件加速</h3><p>这一段请参考<ahref="https://github.com/elFarto/nvidia-vaapi-driver/#firefox">官方文档</a></p>]]></content>
<summary type="html"><p><img
src="https://cdn.jsdelivr.net/gh/lingzs13/img-cloud//img/screen_shot_.png" /></p>
<h2 id="n卡硬件解码">N卡硬件解码</h2>
<h3</summary>
<category term="踩坑日记" scheme="https://blog.zs13.tech/categories/%E8%B8%A9%E5%9D%91%E6%97%A5%E8%AE%B0/"/>
<category term="硬件解码" scheme="https://blog.zs13.tech/tags/%E7%A1%AC%E4%BB%B6%E8%A7%A3%E7%A0%81/"/>
<category term="linux" scheme="https://blog.zs13.tech/tags/linux/"/>
<category term="nvidia" scheme="https://blog.zs13.tech/tags/nvidia/"/>
<category term="archlinux" scheme="https://blog.zs13.tech/tags/archlinux/"/>
</entry>
</feed>