-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
770 lines (369 loc) · 690 KB
/
search.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>使用electron打包静态页面</title>
<link href="/2024/07/08/%E4%BD%BF%E7%94%A8electron%E6%89%93%E5%8C%85%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2/"/>
<url>/2024/07/08/%E4%BD%BF%E7%94%A8electron%E6%89%93%E5%8C%85%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2/</url>
<content type="html"><![CDATA[<ol><li><p>先到静态页面包外面安装<code>electron-packager</code></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">npm install electron</span><br><span class="line"></span><br></pre></td></tr></table></figure><p>再安装<code>electron-packager</code></p><figure class="highlight bash"><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">npm install electron-packager</span><br><span class="line"></span><br></pre></td></tr></table></figure></li><li><p>到静态页面文件夹里面创建<code>main.js</code> 文件</p><figure class="highlight javascript"><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> {app,<span class="title class_">BrowserWindow</span>} = <span class="built_in">require</span>(<span class="string">'electron'</span>); <span class="comment">//引入electron</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> win;</span><br><span class="line"><span class="keyword">let</span> windowConfig = {</span><br><span class="line"> <span class="attr">width</span>: <span class="number">800</span>,</span><br><span class="line"> <span class="attr">height</span>: <span class="number">600</span></span><br><span class="line">}; <span class="comment">//窗口配置程序运行窗口的大小</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">createWindow</span>(<span class="params"></span>) {</span><br><span class="line"> win = <span class="keyword">new</span> <span class="title class_">BrowserWindow</span>(windowConfig); <span class="comment">//创建一个窗口</span></span><br><span class="line"> win.<span class="title function_">loadURL</span>(<span class="string">`file://<span class="subst">${__dirname}</span>/index.html`</span>); <span class="comment">//在窗口内要展示的内容index.html 就是打包生成的index.html</span></span><br><span class="line"> <span class="comment">//win.webContents.openDevTools(); //开启调试工具</span></span><br><span class="line"> win.<span class="title function_">on</span>(<span class="string">'close'</span>, <span class="function">() =></span> {</span><br><span class="line"> <span class="comment">//回收BrowserWindow对象</span></span><br><span class="line"> win = <span class="literal">null</span>;</span><br><span class="line"> });</span><br><span class="line"> win.<span class="title function_">on</span>(<span class="string">'resize'</span>, <span class="function">() =></span> {</span><br><span class="line"> win.<span class="title function_">reload</span>();</span><br><span class="line"> })</span><br><span class="line">}</span><br><span class="line">app.<span class="title function_">on</span>(<span class="string">'ready'</span>, createWindow);</span><br><span class="line">app.<span class="title function_">on</span>(<span class="string">'window-all-closed'</span>, <span class="function">() =></span> {</span><br><span class="line">app.<span class="title function_">quit</span>();</span><br><span class="line">});</span><br><span class="line">app.<span class="title function_">on</span>(<span class="string">'activate'</span>, <span class="function">() =></span> {</span><br><span class="line"><span class="keyword">if</span> (win == <span class="literal">null</span>) {</span><br><span class="line"> <span class="title function_">createWindow</span>();</span><br><span class="line">}</span><br><span class="line">});</span><br><span class="line"> </span><br><span class="line"></span><br></pre></td></tr></table></figure></li><li><p>在静态文件夹里面创建文件<code>package.json</code></p><figure class="highlight json"><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></pre></td><td class="code"><pre><span class="line"><span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"name"</span><span class="punctuation">:</span> <span class="string">"demo"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"productName"</span><span class="punctuation">:</span> <span class="string">"demo"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"author"</span><span class="punctuation">:</span> <span class="string">"reisen"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"version"</span><span class="punctuation">:</span> <span class="string">"1.1.1"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"main"</span><span class="punctuation">:</span> <span class="string">"main.js"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"description"</span><span class="punctuation">:</span> <span class="string">"a electron demo"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"scripts"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"pack"</span><span class="punctuation">:</span> <span class="string">"electron-builder --dir"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"dist"</span><span class="punctuation">:</span> <span class="string">"electron-builder"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"postinstall"</span><span class="punctuation">:</span> <span class="string">"electron-builder install-app-deps"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"build"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"electronVersion"</span><span class="punctuation">:</span> <span class="string">"11.5.0"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"win"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"requestedExecutionLevel"</span><span class="punctuation">:</span> <span class="string">"highestAvailable"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"target"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"target"</span><span class="punctuation">:</span> <span class="string">"nsis"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"arch"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="string">"x64"</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"appId"</span><span class="punctuation">:</span> <span class="string">"demo"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"artifactName"</span><span class="punctuation">:</span> <span class="string">"demo-version−{arch}.${ext}"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"nsis"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"artifactName"</span><span class="punctuation">:</span> <span class="string">"demo-version−{arch}.${ext}"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"extraResources"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"from"</span><span class="punctuation">:</span> <span class="string">""</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"to"</span><span class="punctuation">:</span> <span class="string">"app-server"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"filter"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="string">"**/*"</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"publish"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"provider"</span><span class="punctuation">:</span> <span class="string">"generic"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"url"</span><span class="punctuation">:</span> <span class="string">"reisen"</span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"devDependencies"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"electron"</span><span class="punctuation">:</span> <span class="string">"^31.1.0"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"electron-builder"</span><span class="punctuation">:</span> <span class="string">"^24.13.3"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"dependencies"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"core-js"</span><span class="punctuation">:</span> <span class="string">"^2.4.1"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"electron-packager"</span><span class="punctuation">:</span> <span class="string">"^12.1.0"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"electron-updater"</span><span class="punctuation">:</span> <span class="string">"^4.0.0"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"fs-extra"</span><span class="punctuation">:</span> <span class="string">"^4.0.1"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"install.js"</span><span class="punctuation">:</span> <span class="string">"^1.0.1"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"moment"</span><span class="punctuation">:</span> <span class="string">"^2.18.1"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"moment-es6"</span><span class="punctuation">:</span> <span class="string">"^1.0.0"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"license"</span><span class="punctuation">:</span> <span class="string">"ISC"</span></span><br><span class="line"><span class="punctuation">}</span></span><br><span class="line"> </span><br><span class="line"></span><br></pre></td></tr></table></figure></li><li><p>然后在静态文件夹外面的<code>package.json</code>里修改如下script</p><figure class="highlight javascript"><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="string">"scripts"</span>: {</span><br><span class="line"> <span class="string">"serve"</span>: <span class="string">"vue-cli-service serve"</span>,</span><br><span class="line"> <span class="string">"build"</span>: <span class="string">"vue-cli-service build"</span>,</span><br><span class="line"> <span class="string">"test"</span>: <span class="string">"vue-cli-service build --mode test"</span>,</span><br><span class="line"> <span class="string">"lint"</span>: <span class="string">"vue-cli-service lint"</span>,</span><br><span class="line"> <span class="string">"electron_dev"</span>: <span class="string">"npm run build && electron main.js"</span>,</span><br><span class="line"> <span class="string">"electron_build"</span>: <span class="string">"electron-packager ./dist demo --platform=win32 --arch=x64 --overwrite"</span>,</span><br><span class="line"> </span><br><span class="line"> <span class="string">"dist"</span>: <span class="string">"electron-packager ./dist name --platform=win32 --arch=ia32 --overwrite"</span> </span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>最后执行这个<code>electron_build</code>就能完成打包了,打完包能看到一个demo.exe启动就ok了</p></li></ol>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> electron </tag>
</tags>
</entry>
<entry>
<title>最详细的MySQL部署</title>
<link href="/2024/06/17/%E6%9C%80%E8%AF%A6%E7%BB%86%E7%9A%84MySQL%E9%83%A8%E7%BD%B2/"/>
<url>/2024/06/17/%E6%9C%80%E8%AF%A6%E7%BB%86%E7%9A%84MySQL%E9%83%A8%E7%BD%B2/</url>
<content type="html"><![CDATA[<h2 id="rpm安装MySQL"><a href="#rpm安装MySQL" class="headerlink" title="rpm安装MySQL"></a>rpm安装MySQL</h2><h3 id="先下载所需的包"><a href="#先下载所需的包" class="headerlink" title="先下载所需的包"></a>先下载所需的包</h3><p>分别下载 MySQL5.7的<code>common</code> 、<code>libs</code>、<code>client</code>、<code>server</code>4个RPM包:</p><figure class="highlight bash"><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">wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-community-common-5.7.33-1.el6.x86_64.rpm</span><br><span class="line"></span><br><span class="line">wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-community-libs-5.7.33-1.el6.x86_64.rpm</span><br><span class="line"></span><br><span class="line">wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-community-client-5.7.33-1.el6.x86_64.rpm</span><br><span class="line"></span><br><span class="line">wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-community-server-5.7.33-1.el6.x86_64.rpm</span><br></pre></td></tr></table></figure><h3 id="安装4个rmp包"><a href="#安装4个rmp包" class="headerlink" title="安装4个rmp包"></a>安装4个rmp包</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh *.rpm --nodeps –-force</span><br></pre></td></tr></table></figure><h3 id="配置MySQL的配置文件"><a href="#配置MySQL的配置文件" class="headerlink" title="配置MySQL的配置文件"></a>配置MySQL的配置文件</h3><p>在/etc/my.cnf 里面配置<code>MySQL</code>的配置</p><h3 id="启动MySQL服务"><a href="#启动MySQL服务" class="headerlink" title="启动MySQL服务"></a>启动MySQL服务</h3><p>启动MySQL服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">service mysqld start</span><br><span class="line">or</span><br><span class="line">systemctl start mysqld</span><br></pre></td></tr></table></figure><p>查看MySQL服务状态</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">service mysqld status</span><br><span class="line">or</span><br><span class="line">systemctl status mysqld</span><br></pre></td></tr></table></figure><hr><h2 id="yum安装MySQL"><a href="#yum安装MySQL" class="headerlink" title="yum安装MySQL"></a>yum安装MySQL</h2><h3 id="先卸载MySQL"><a href="#先卸载MySQL" class="headerlink" title="先卸载MySQL"></a>先卸载MySQL</h3><p>查看旧的MySQL</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep MySQL</span><br></pre></td></tr></table></figure><p>卸载所有 MySQL 服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -e xxxxxxxxxxxxx</span><br></pre></td></tr></table></figure><p>使用yum卸载MySQL</p><figure class="highlight bash"><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">yum list installed | grep mysql</span><br><span class="line">yum remove mysql</span><br></pre></td></tr></table></figure><h3 id="安装MySQL的yum源"><a href="#安装MySQL的yum源" class="headerlink" title="安装MySQL的yum源"></a>安装MySQL的yum源</h3><p>可以从下面这个网站选择对应的版本</p><blockquote><p><a href="http://repo.mysql.com/">http://repo.mysql.com/</a></p></blockquote><p>下载并安装yum源</p><figure class="highlight bash"><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">wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm</span><br><span class="line">sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm</span><br></pre></td></tr></table></figure><ul><li><p>执行完毕后克可以查看源文件:/etc/yum.repos.d/</p></li><li><p>会多出一个 MySQL 的 rpm 包和两个 MySQL 开头的源</p></li><li><p>该命令执行完成后,会在/etc/yum.repos.d/目录下创建一个mysql-community.repo文件,这就是mysql的yum源</p></li><li><p>当然你也可通过命令的方式查看mysql的yum源是否安装成功。</p> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum repolist enabled | grep <span class="string">"mysql.*-community.*"</span></span><br></pre></td></tr></table></figure></li></ul><h3 id="使用yum命令安装MySQL"><a href="#使用yum命令安装MySQL" class="headerlink" title="使用yum命令安装MySQL"></a>使用yum命令安装MySQL</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install mysql-server</span><br></pre></td></tr></table></figure><p>出现 Complete!即表示安装成功。<br>然后执行</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep MySQL</span><br></pre></td></tr></table></figure><p>列出MySQL的服务,表示安装成功</p><h3 id="启动服务"><a href="#启动服务" class="headerlink" title="启动服务"></a>启动服务</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysqld start</span><br></pre></td></tr></table></figure><hr><h2 id="Windows下使用文件夹安装"><a href="#Windows下使用文件夹安装" class="headerlink" title="Windows下使用文件夹安装"></a>Windows下使用文件夹安装</h2><h3 id="先到官网下载MySQL安装包"><a href="#先到官网下载MySQL安装包" class="headerlink" title="先到官网下载MySQL安装包"></a>先到官网下载MySQL安装包</h3><p>下载完成解压之后文件应该如下</p><p><img src="/img/posts/20240617013240.png" alt="alt"></p><h3 id="创建一个my-ini文件"><a href="#创建一个my-ini文件" class="headerlink" title="创建一个my.ini文件"></a>创建一个my.ini文件</h3><p>添加数据的配置</p><figure class="highlight text"><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">[mysqld]</span><br><span class="line">#设置3306端口号</span><br><span class="line">port=3306</span><br><span class="line">#设置MySQL的安装目录</span><br><span class="line">basedir=</span><br><span class="line">#设置MySQL数据库的数据存放目录</span><br><span class="line">datadir=</span><br><span class="line">#运行最大连接数</span><br><span class="line">max_connections=200</span><br><span class="line">#运行连接失败的次数。</span><br><span class="line">max_connect_errors=10</span><br><span class="line">#服务端使用的字符集默认为utf-8</span><br><span class="line">character-set-server=utf8</span><br><span class="line">[mysql]</span><br><span class="line">#客户端使用的字符集默认为utf8</span><br><span class="line">default-character-set=utf8</span><br><span class="line">[client]</span><br><span class="line">#客户端默认端口号为3306</span><br><span class="line">port=3306</span><br></pre></td></tr></table></figure><h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><figure class="highlight cmd"><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">mysqld --install</span><br><span class="line">mysqld --initialize --console</span><br></pre></td></tr></table></figure><p>可以看到密码</p><h3 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h3><p>打开Windows的服务,找到MySQL然后启动</p><hr><h2 id="5-7版本修改root的密码"><a href="#5-7版本修改root的密码" class="headerlink" title="5.7版本修改root的密码"></a>5.7版本修改root的密码</h2><h3 id="查看MySQL的密码"><a href="#查看MySQL的密码" class="headerlink" title="查看MySQL的密码"></a>查看MySQL的密码</h3><figure class="highlight bash"><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">cat</span> /var/log/mysqld.log | grep password</span><br></pre></td></tr></table></figure><p>如果更改了MySQL的配置文件,需要在里面查看mysql的日志路径</p><h3 id="登录MySQL服务器"><a href="#登录MySQL服务器" class="headerlink" title="登录MySQL服务器"></a>登录MySQL服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p </span><br></pre></td></tr></table></figure><p>输入用户名密码,密码就是刚才看的</p><h3 id="修改root登录密码"><a href="#修改root登录密码" class="headerlink" title="修改root登录密码"></a>修改root登录密码</h3><p>登录状态下<br>设置密码校验强度为最低级别</p><figure class="highlight bash"><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">set</span> global validate_password_policy=0;</span><br></pre></td></tr></table></figure><p>设置密码长度最少为4个字符</p><figure class="highlight bash"><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">set</span> global validate_password_length=4;</span><br></pre></td></tr></table></figure><p>修改密码</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter user <span class="string">'root'</span>@<span class="string">'localhost'</span> identified by <span class="string">'你的密码'</span>;</span><br></pre></td></tr></table></figure><p>刷新权限</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges; </span><br></pre></td></tr></table></figure><hr><h2 id="8-0版本修改密码"><a href="#8-0版本修改密码" class="headerlink" title="8.0版本修改密码"></a>8.0版本修改密码</h2><h3 id="先查看MySQL的密码"><a href="#先查看MySQL的密码" class="headerlink" title="先查看MySQL的密码"></a>先查看MySQL的密码</h3><h3 id="登录后到MySQL"><a href="#登录后到MySQL" class="headerlink" title="登录后到MySQL"></a>登录后到MySQL</h3><h3 id="修改密码策略"><a href="#修改密码策略" class="headerlink" title="修改密码策略"></a>修改密码策略</h3><p>查看密码策略</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> variables <span class="keyword">like</span> <span class="string">'validate%'</span>;</span><br></pre></td></tr></table></figure><p>修改策略</p><figure class="highlight sql"><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="comment">--密码验证策略低要求(0或LOW代表低级)</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">global</span> validate_password.policy<span class="operator">=</span>MEDIUM;</span><br><span class="line"></span><br><span class="line"><span class="comment">--密码至少要包含的小写字母个数和大写字母个数</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">global</span> validate_password.mixed_case_count<span class="operator">=</span><span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">--密码至少要包含的数字个数。</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">global</span> validate_password.number_count<span class="operator">=</span><span class="number">1</span>; </span><br><span class="line"></span><br><span class="line"><span class="comment">--密码至少要包含的特殊字符数</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">global</span> validate_password.special_char_count<span class="operator">=</span><span class="number">1</span>; </span><br><span class="line"></span><br><span class="line"><span class="comment">-- 密码长度</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">global</span> validate_password.length<span class="operator">=</span><span class="number">8</span>; </span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="修改密码"><a href="#修改密码" class="headerlink" title="修改密码"></a>修改密码</h3><p>如果密码为空直接修改</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">user</span> <span class="string">'root'</span>@<span class="string">'localhost'</span> IDENTIFIED <span class="keyword">BY</span> <span class="string">'你的密码'</span>; </span><br></pre></td></tr></table></figure><p>如果不为空</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">user</span> <span class="string">'root'</span>@<span class="string">'localhost'</span> identified <span class="keyword">with</span> mysql_native_password <span class="keyword">by</span> <span class="string">'你的密码'</span>;</span><br></pre></td></tr></table></figure><p>如果要远程连接改成<code>%</code></p><p>刷新权限</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> MySQL </tag>
</tags>
</entry>
<entry>
<title>加密yml文件</title>
<link href="/2024/06/16/%E5%8A%A0%E5%AF%86yml%E6%96%87%E4%BB%B6/"/>
<url>/2024/06/16/%E5%8A%A0%E5%AF%86yml%E6%96%87%E4%BB%B6/</url>
<content type="html"><![CDATA[<h3 id="1-低版本2-x"><a href="#1-低版本2-x" class="headerlink" title="1. 低版本2.x"></a>1. 低版本2.x</h3><h4 id="引入依赖"><a href="#引入依赖" class="headerlink" title="引入依赖"></a>引入依赖</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.github.ulisesbocchio<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt-spring-boot-starter<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.1.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><p>手动引入依赖(内网环境)</p><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><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="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.jasypt<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.9.2<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><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.github.ulisesbocchio<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt-spring-boot<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.1.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="生成密码"><a href="#生成密码" class="headerlink" title="生成密码"></a>生成密码</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><span class="line">20</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_">PasswordEncrypt</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="comment">// write your code here</span></span><br><span class="line"> <span class="type">StandardPBEStringEncryptor</span> <span class="variable">standardPBEStringEncryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StandardPBEStringEncryptor</span>();</span><br><span class="line"> <span class="type">EnvironmentPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">EnvironmentPBEConfig</span>();</span><br><span class="line"></span><br><span class="line"> config.setAlgorithm(<span class="string">"PBEWithMD5AndDES"</span>); <span class="comment">// 加密的算法,这个算法是默认的</span></span><br><span class="line"> config.setPassword(<span class="string">"sigtuna"</span>); <span class="comment">// 加密的密钥,随便自己填写,很重要千万不要告诉别人</span></span><br><span class="line"> standardPBEStringEncryptor.setConfig(config);</span><br><span class="line"> <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">"jdbc:mysql://xxx.xxx.xxx.xxx:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=FALSE&serverTimezone=UTC&useOldAliasMetadataBehavior=true"</span>; <span class="comment">//自己的密码</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">root</span> <span class="operator">=</span> <span class="string">"test"</span>; <span class="comment">//自己的密码</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">pwd</span> <span class="operator">=</span> <span class="string">"test"</span>; <span class="comment">//自己的密码</span></span><br><span class="line"></span><br><span class="line"> System.out.println(<span class="string">"url "</span>+ standardPBEStringEncryptor.encrypt(url));</span><br><span class="line"> System.out.println(<span class="string">"root "</span>+ standardPBEStringEncryptor.encrypt(root));</span><br><span class="line"> System.out.println(<span class="string">"pwd "</span>+ standardPBEStringEncryptor.encrypt(pwd));</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="解密"><a href="#解密" class="headerlink" title="解密"></a>解密</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> List<String> <span class="title function_">decrypt</span><span class="params">(String url, String username, String pwd)</span>{</span><br><span class="line"></span><br><span class="line"> <span class="type">StandardPBEStringEncryptor</span> <span class="variable">standardPBEStringEncryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StandardPBEStringEncryptor</span>();</span><br><span class="line"> <span class="type">EnvironmentPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">EnvironmentPBEConfig</span>();</span><br><span class="line"> </span><br><span class="line"> config.setAlgorithm(<span class="string">"PBEWithMD5AndDES"</span>);</span><br><span class="line"> config.setPassword(<span class="string">"sigtuna"</span>);</span><br><span class="line"> standardPBEStringEncryptor.setConfig(config);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUrl</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(url);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUser</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(username);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextPwd</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(pwd);</span><br><span class="line"> System.out.println(<span class="string">"url: "</span>+plainTextUrl);</span><br><span class="line"> System.out.println(<span class="string">"username: "</span>+plainTextUser);</span><br><span class="line"> System.out.println(<span class="string">"password: "</span>+plainTextPwd);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="自动获取yml文件里的数据库配置"><a href="#自动获取yml文件里的数据库配置" class="headerlink" title="自动获取yml文件里的数据库配置"></a>自动获取yml文件里的数据库配置</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><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">PasswordDecrypt</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 class="keyword">throws</span> FileNotFoundException {</span><br><span class="line"><span class="comment">// decrypt("秘钥",</span></span><br><span class="line"><span class="comment">// "秘钥",</span></span><br><span class="line"><span class="comment">// "秘钥");</span></span><br><span class="line"> EaseDecrypt();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> List<String> <span class="title function_">Encrypt</span><span class="params">(String url,String username,String pwd)</span>{</span><br><span class="line"></span><br><span class="line"> <span class="type">StandardPBEStringEncryptor</span> <span class="variable">standardPBEStringEncryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StandardPBEStringEncryptor</span>();</span><br><span class="line"> <span class="type">EnvironmentPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">EnvironmentPBEConfig</span>();</span><br><span class="line"></span><br><span class="line"> config.setAlgorithm(<span class="string">"PBEWithMD5AndDES"</span>); <span class="comment">// 加密的算法,这个算法是默认的</span></span><br><span class="line"> config.setPassword(<span class="string">"sigtuna"</span>); <span class="comment">// 加密的密钥,随便自己填写,很重要千万不要告诉别人</span></span><br><span class="line"> standardPBEStringEncryptor.setConfig(config);</span><br><span class="line"> <span class="comment">// String url = "jdbc:mysql://xxx.xxxx.xxx.xxx:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false"; //自己的密码</span></span><br><span class="line"> <span class="comment">// String root = "test"; //自己的密码</span></span><br><span class="line"> <span class="comment">// String pwd = "test"; //自己的密码</span></span><br><span class="line"></span><br><span class="line"> System.out.println(<span class="string">"url "</span>+ standardPBEStringEncryptor.encrypt(url));</span><br><span class="line"> System.out.println(<span class="string">"root "</span>+ standardPBEStringEncryptor.encrypt(username));</span><br><span class="line"> System.out.println(<span class="string">"pwd "</span>+ standardPBEStringEncryptor.encrypt(pwd));</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> List<String> <span class="title function_">decrypt</span><span class="params">(String url, String username, String pwd)</span>{</span><br><span class="line"></span><br><span class="line"> <span class="type">StandardPBEStringEncryptor</span> <span class="variable">standardPBEStringEncryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StandardPBEStringEncryptor</span>();</span><br><span class="line"> <span class="type">EnvironmentPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">EnvironmentPBEConfig</span>();</span><br><span class="line"> </span><br><span class="line"> config.setAlgorithm(<span class="string">"PBEWithMD5AndDES"</span>);</span><br><span class="line"> config.setPassword(<span class="string">"sigtuna"</span>);</span><br><span class="line"> standardPBEStringEncryptor.setConfig(config);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUrl</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(url);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUser</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(username);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextPwd</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(pwd);</span><br><span class="line"> System.out.println(<span class="string">"url: "</span>+plainTextUrl);</span><br><span class="line"> System.out.println(<span class="string">"username: "</span>+plainTextUser);</span><br><span class="line"> System.out.println(<span class="string">"password: "</span>+plainTextPwd);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> List<String> <span class="title function_">EaseDecrypt</span><span class="params">()</span> <span class="keyword">throws</span> FileNotFoundException{</span><br><span class="line"></span><br><span class="line"> <span class="comment">// System.out.println("输入解密的配置文件地址");</span></span><br><span class="line"> <span class="comment">// Scanner scanner = new Scanner(System.in);</span></span><br><span class="line"> <span class="comment">// String filePath = scanner.nextLine();</span></span><br><span class="line"> <span class="type">InputStream</span> <span class="variable">io</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(<span class="string">"x:\\xxx\\application-dev.yml"</span>);</span><br><span class="line"> Yaml yaml=<span class="keyword">new</span> <span class="title class_">Yaml</span>();</span><br><span class="line"> Map<String, Object> map =yaml.load(io);</span><br><span class="line"> <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">username</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">pwd</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">// System.out.println(map);</span></span><br><span class="line"><span class="comment">// System.out.println(map.get("spring"));</span></span><br><span class="line"><span class="comment">// System.out.println();</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// 获得url</span></span><br><span class="line"> <span class="keyword">if</span> (map.get(<span class="string">"spring"</span>) != <span class="literal">null</span> && !map.get(<span class="string">"spring"</span>).equals(<span class="string">""</span>)) {</span><br><span class="line"> Map<String,Object> mapd = (Map<String, Object>) map.get(<span class="string">"spring"</span>);</span><br><span class="line"> <span class="keyword">if</span> (mapd.get(<span class="string">"datasource"</span>) != <span class="literal">null</span>) {</span><br><span class="line"> Map<String,Object> mapdata = (Map<String, Object>) mapd.get(<span class="string">"datasource"</span>);</span><br><span class="line"> <span class="keyword">if</span> (mapdata.get(<span class="string">"druid"</span>) != <span class="literal">null</span>) {</span><br><span class="line"> Map<String,Object> mapdata1 = (Map<String, Object>) mapdata.get(<span class="string">"druid"</span>);</span><br><span class="line"> <span class="keyword">if</span> (mapdata1.get(<span class="string">"master"</span>) != <span class="literal">null</span>) {</span><br><span class="line"> Map<String,Object> mapdata2 = (Map<String, Object>) mapdata1.get(<span class="string">"master"</span>);</span><br><span class="line"> <span class="keyword">if</span> (mapdata2.get(<span class="string">"url"</span>) != <span class="literal">null</span>) {</span><br><span class="line"> url = (String) mapdata2.get(<span class="string">"url"</span>);</span><br><span class="line"> username = (String) mapdata2.get(<span class="string">"username"</span>);</span><br><span class="line"> pwd = (String) mapdata2.get(<span class="string">"password"</span>);;</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"></span><br><span class="line"> <span class="comment">// 获得加密密码</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">algorithm</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">password</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">prefix</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">suffix</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">if</span> (map.get(<span class="string">"jasypt"</span>) != <span class="literal">null</span> && !map.get(<span class="string">"jasypt"</span>).equals(<span class="string">""</span>)) {</span><br><span class="line"> Map<String,Object> mapd = (Map<String, Object>) map.get(<span class="string">"jasypt"</span>);</span><br><span class="line"> <span class="keyword">if</span> (mapd.get(<span class="string">"encryptor"</span>) != <span class="literal">null</span>) {</span><br><span class="line"> Map<String,Object> mapdata = (Map<String, Object>) mapd.get(<span class="string">"encryptor"</span>);</span><br><span class="line"> algorithm = (String) mapdata.get(<span class="string">"algorithm"</span>);</span><br><span class="line"> password = (String) mapdata.get(<span class="string">"password"</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(mapdata.get(<span class="string">"property"</span>)!= <span class="literal">null</span>){</span><br><span class="line"> Map<String,Object> mapdata1 = (Map<String, Object>) mapdata.get(<span class="string">"property"</span>);</span><br><span class="line"> prefix = (String) mapdata1.get(<span class="string">"prefix"</span>);</span><br><span class="line"> suffix = (String) mapdata1.get(<span class="string">"suffix"</span>);</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"> <span class="type">StandardPBEStringEncryptor</span> <span class="variable">standardPBEStringEncryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StandardPBEStringEncryptor</span>();</span><br><span class="line"> <span class="comment">// 去除前缀</span></span><br><span class="line"> url = removePro(url,prefix,suffix);</span><br><span class="line"> username = removePro(username,prefix,suffix);</span><br><span class="line"> pwd = removePro(pwd,prefix,suffix);</span><br><span class="line"></span><br><span class="line"> <span class="type">EnvironmentPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">EnvironmentPBEConfig</span>();</span><br><span class="line"> </span><br><span class="line"> config.setAlgorithm(algorithm);</span><br><span class="line"> config.setPassword(password);</span><br><span class="line"> standardPBEStringEncryptor.setConfig(config);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUrl</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(url);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextUser</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(username);</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainTextPwd</span> <span class="operator">=</span> standardPBEStringEncryptor.decrypt(pwd);</span><br><span class="line"> System.out.println(<span class="string">"url: "</span>+plainTextUrl);</span><br><span class="line"> System.out.println(<span class="string">"username: "</span>+plainTextUser);</span><br><span class="line"> System.out.println(<span class="string">"password: "</span>+plainTextPwd);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">removePro</span><span class="params">(String oString,String prefix,String suffix)</span>{</span><br><span class="line"></span><br><span class="line"> <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> oString;</span><br><span class="line"> <span class="keyword">if</span> (prefix!=<span class="literal">null</span>) {</span><br><span class="line"> str = oString.substring(prefix.length(), oString.length());</span><br><span class="line"> oString = str;</span><br><span class="line"> <span class="keyword">if</span> (suffix!=<span class="literal">null</span>) {</span><br><span class="line"> str = oString.substring(<span class="number">0</span>, oString.length()-suffix.length());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> str;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> List<String> <span class="title function_">getMapKey</span><span class="params">(String key , Map<String,Object> map)</span>{</span><br><span class="line"></span><br><span class="line"> List<String> list = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> Map<String,Object> keyMap = <span class="keyword">new</span> <span class="title class_">HashMap</span><>();</span><br><span class="line"> <span class="keyword">if</span> (key != <span class="literal">null</span>) {</span><br><span class="line"> <span class="keyword">if</span> (map.get(key) != <span class="literal">null</span>) {</span><br><span class="line"> keyMap = (Map<String, Object>) map.get(key);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> keyMap = map;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(String x : keyMap.keySet()){</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">} </span><br></pre></td></tr></table></figure><h4 id="yml配置"><a href="#yml配置" class="headerlink" title="yml配置"></a>yml配置</h4><figure class="highlight yml"><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="attr">jasypt:</span></span><br><span class="line"> <span class="attr">encryptor:</span></span><br><span class="line"> <span class="attr">algorithm:</span> <span class="string">PBEWithMD5AndDES</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">sigtuna</span></span><br><span class="line"> <span class="attr">property:</span></span><br><span class="line"> <span class="attr">prefix:</span> <span class="string">reisen</span></span><br><span class="line"> <span class="attr">suffix:</span></span><br></pre></td></tr></table></figure><p>数据库的配置用reisen包裹就可以了,这块可以自定义,默认的ENC</p><h3 id="2-高版本3-x"><a href="#2-高版本3-x" class="headerlink" title="2.高版本3.x"></a>2.高版本3.x</h3><h4 id="引入依赖包"><a href="#引入依赖包" class="headerlink" title="引入依赖包"></a>引入依赖包</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.github.ulisesbocchio<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt-spring-boot-starter<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>3.0.3<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><p>内网情况如下</p><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><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="comment"><!-- https://mvnrepository.com/artifact/org.jasypt/jasypt --></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.jasypt<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.9.3<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><span class="line"><span class="comment"><!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot --></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>com.github.ulisesbocchio<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jasypt-spring-boot<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>3.0.3<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="生成秘钥"><a href="#生成秘钥" class="headerlink" title="生成秘钥"></a>生成秘钥</h4><p>下面是一个工具类</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><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></pre></td><td class="code"><pre><span class="line"> </span><br><span class="line"><span class="keyword">import</span> org.jasypt.encryption.pbe.PooledPBEStringEncryptor;</span><br><span class="line"><span class="keyword">import</span> org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JasypUtil</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">PBEWITHHMACSHA512ANDAES_256</span> <span class="operator">=</span> <span class="string">"PBEWITHHMACSHA512ANDAES_256"</span>;</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">@Description</span>: Jasyp 加密(PBEWITHHMACSHA512ANDAES_256)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span>: Rambo</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@CreateDate</span>: 2020/7/25 14:34</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@UpdateUser</span>: Rambo</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@UpdateDate</span>: 2020/7/25 14:34</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> plainText 待加密的原文</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> factor 加密秘钥</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> java.lang.String</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Version</span>: 1.0.0</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">encryptWithSHA512</span><span class="params">(String plainText, String factor)</span> {</span><br><span class="line"> <span class="comment">// 1. 创建加解密工具实例</span></span><br><span class="line"> <span class="type">PooledPBEStringEncryptor</span> <span class="variable">encryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">PooledPBEStringEncryptor</span>();</span><br><span class="line"> <span class="comment">// 2. 加解密配置</span></span><br><span class="line"> <span class="type">SimpleStringPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleStringPBEConfig</span>();</span><br><span class="line"> config.setPassword(factor);</span><br><span class="line"> config.setAlgorithm(PBEWITHHMACSHA512ANDAES_256);</span><br><span class="line"> <span class="comment">// 为减少配置文件的书写,以下都是 Jasyp 3.x 版本,配置文件默认配置</span></span><br><span class="line"> config.setKeyObtentionIterations( <span class="string">"1000"</span>);</span><br><span class="line"> config.setPoolSize(<span class="string">"1"</span>);</span><br><span class="line"> config.setProviderName(<span class="string">"SunJCE"</span>);</span><br><span class="line"> config.setSaltGeneratorClassName(<span class="string">"org.jasypt.salt.RandomSaltGenerator"</span>);</span><br><span class="line"> config.setIvGeneratorClassName(<span class="string">"org.jasypt.iv.RandomIvGenerator"</span>);</span><br><span class="line"> config.setStringOutputType(<span class="string">"base64"</span>);</span><br><span class="line"> encryptor.setConfig(config);</span><br><span class="line"> <span class="comment">// 3. 加密</span></span><br><span class="line"> <span class="keyword">return</span> encryptor.encrypt(plainText);</span><br><span class="line"> }</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">@Description</span>: Jaspy解密(PBEWITHHMACSHA512ANDAES_256)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span>: Rambo</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@CreateDate</span>: 2020/7/25 14:40</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@UpdateUser</span>: Rambo</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@UpdateDate</span>: 2020/7/25 14:40</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> encryptedText 待解密密文</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> factor 解密秘钥</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> java.lang.String</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Version</span>: 1.0.0</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">decryptWithSHA512</span><span class="params">(String encryptedText, String factor)</span> {</span><br><span class="line"> <span class="comment">// 1. 创建加解密工具实例</span></span><br><span class="line"> <span class="type">PooledPBEStringEncryptor</span> <span class="variable">encryptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">PooledPBEStringEncryptor</span>();</span><br><span class="line"> <span class="comment">// 2. 加解密配置</span></span><br><span class="line"> <span class="type">SimpleStringPBEConfig</span> <span class="variable">config</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleStringPBEConfig</span>();</span><br><span class="line"> config.setPassword(factor);</span><br><span class="line"> config.setAlgorithm(PBEWITHHMACSHA512ANDAES_256);</span><br><span class="line"> <span class="comment">// 为减少配置文件的书写,以下都是 Jasyp 3.x 版本,配置文件默认配置</span></span><br><span class="line"> config.setKeyObtentionIterations( <span class="string">"1000"</span>);</span><br><span class="line"> config.setPoolSize(<span class="string">"1"</span>);</span><br><span class="line"> config.setProviderName(<span class="string">"SunJCE"</span>);</span><br><span class="line"> config.setSaltGeneratorClassName(<span class="string">"org.jasypt.salt.RandomSaltGenerator"</span>);</span><br><span class="line"> config.setIvGeneratorClassName(<span class="string">"org.jasypt.iv.RandomIvGenerator"</span>);</span><br><span class="line"> config.setStringOutputType(<span class="string">"base64"</span>);</span><br><span class="line"> encryptor.setConfig(config);</span><br><span class="line"> <span class="comment">// 3. 解密</span></span><br><span class="line"> <span class="keyword">return</span> encryptor.decrypt(encryptedText);</span><br><span class="line"> }</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">String</span> <span class="variable">factor</span> <span class="operator">=</span> <span class="string">"Angel"</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">plainText</span> <span class="operator">=</span> <span class="string">"123456"</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="type">String</span> <span class="variable">encryptWithSHA512Str</span> <span class="operator">=</span> encryptWithSHA512(plainText, factor);</span><br><span class="line"> <span class="type">String</span> <span class="variable">decryptWithSHA512Str</span> <span class="operator">=</span> decryptWithSHA512(encryptWithSHA512Str, factor);</span><br><span class="line"> System.out.println(<span class="string">"采用AES256加密前原文密文:"</span> + encryptWithSHA512Str);</span><br><span class="line"> System.out.println(<span class="string">"采用AES256解密后密文原文:"</span> + decryptWithSHA512Str);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="yml的配置"><a href="#yml的配置" class="headerlink" title="yml的配置"></a>yml的配置</h4><figure class="highlight yml"><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="attr">spring:</span></span><br><span class="line"> <span class="attr">datasource:</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">ENC(8jLUdq0Fr7UhJGNwK/Nc6i6/WV4+UBpvtfBLDh4e3jZMJZAhPqfZdGlpFEUk24UZ)</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC</span></span><br><span class="line"> <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">jasypt:</span></span><br><span class="line"> <span class="attr">encryptor:</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">Angel</span></span><br><span class="line"> <span class="attr">algorithm:</span> <span class="string">PBEWITHHMACSHA512ANDAES_256</span></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>Vue2设置通知提醒框</title>
<link href="/2024/06/12/Vue2%E8%AE%BE%E7%BD%AE%E9%80%9A%E7%9F%A5%E6%8F%90%E9%86%92%E6%A1%86/"/>
<url>/2024/06/12/Vue2%E8%AE%BE%E7%BD%AE%E9%80%9A%E7%9F%A5%E6%8F%90%E9%86%92%E6%A1%86/</url>
<content type="html"><![CDATA[<p>可自定义设置以下属性:</p><ul><li>自动关闭的延时时长(duration),单位ms,默认4500ms</li><li>消息从顶部弹出时,距离顶部的位置(top),单位px,默认24px</li><li>消息从底部弹出时,距离底部的位置(bottom),单位px,默认24px</li><li>消息弹出位置(placement),可选:左上topLeft,右上topRight(默认),左下bottomLeft,右下bottomRight</li></ul><p>调用时可选以下五个方法对应五种不同样式:</p><ul><li>this.$refs.notification.open(notification) // 默认使用</li><li>this.$refs.notification.info(notification) // info调用</li><li>this.$refs.notification.success(notification) // success调用</li><li>this.$refs.notification.error(notification) // error调用</li><li>this.$refs.notification.warn(notification) // warn调用</li></ul><h3 id="创建通知框架组件命名为Notification"><a href="#创建通知框架组件命名为Notification" class="headerlink" title="创建通知框架组件命名为Notification"></a>创建通知框架组件命名为<code>Notification</code></h3><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><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">template</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">:class</span>=<span class="string">"['m-notification-wrap', placement]"</span> <span class="attr">:style</span>=<span class="string">"`top: ${placement.includes('top') ? top : ''}px; bottom: ${placement.includes('bottom') ? bottom : ''}px;`"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">transition-group</span> <span class="attr">name</span>=<span class="string">"slide-fade"</span> <span class="attr">tag</span>=<span class="string">"div"</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="attr">class</span>=<span class="string">"m-notification"</span></span></span><br><span class="line"><span class="tag"> @<span class="attr">mouseenter</span>=<span class="string">"onEnter(index)"</span></span></span><br><span class="line"><span class="tag"> @<span class="attr">mouseleave</span>=<span class="string">"onLeave(index)"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">v-show</span>=<span class="string">"!hideIndex.includes(index)"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">v-for</span>=<span class="string">"(data, index) in notificationData"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">:key</span>=<span class="string">"`n${index}`"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">svg</span> <span class="attr">class</span>=<span class="string">"u-status-svg"</span> <span class="attr">v-if</span>=<span class="string">"mode==='info'"</span> <span class="attr">:fill</span>=<span class="string">"colorStyle[mode]"</span> <span class="attr">viewBox</span>=<span class="string">"64 64 896 896"</span> <span class="attr">data-icon</span>=<span class="string">"info-circle"</span> <span class="attr">aria-hidden</span>=<span class="string">"true"</span> <span class="attr">focusable</span>=<span class="string">"false"</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"></<span class="name">svg</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">svg</span> <span class="attr">class</span>=<span class="string">"u-status-svg"</span> <span class="attr">v-if</span>=<span class="string">"mode==='success'"</span> <span class="attr">:fill</span>=<span class="string">"colorStyle[mode]"</span> <span class="attr">viewBox</span>=<span class="string">"64 64 896 896"</span> <span class="attr">data-icon</span>=<span class="string">"check-circle"</span> <span class="attr">aria-hidden</span>=<span class="string">"true"</span> <span class="attr">focusable</span>=<span class="string">"false"</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0 0 51.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"></<span class="name">svg</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">svg</span> <span class="attr">class</span>=<span class="string">"u-status-svg"</span> <span class="attr">v-if</span>=<span class="string">"mode==='warn'"</span> <span class="attr">:fill</span>=<span class="string">"colorStyle[mode]"</span> <span class="attr">viewBox</span>=<span class="string">"64 64 896 896"</span> <span class="attr">data-icon</span>=<span class="string">"exclamation-circle"</span> <span class="attr">aria-hidden</span>=<span class="string">"true"</span> <span class="attr">focusable</span>=<span class="string">"false"</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M464 688a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm24-112h48c4.4 0 8-3.6 8-8V296c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"></<span class="name">svg</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">svg</span> <span class="attr">class</span>=<span class="string">"u-status-svg"</span> <span class="attr">v-if</span>=<span class="string">"mode==='error'"</span> <span class="attr">:fill</span>=<span class="string">"colorStyle[mode]"</span> <span class="attr">viewBox</span>=<span class="string">"64 64 896 896"</span> <span class="attr">data-icon</span>=<span class="string">"close-circle"</span> <span class="attr">aria-hidden</span>=<span class="string">"true"</span> <span class="attr">focusable</span>=<span class="string">"false"</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"></<span class="name">svg</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">:class</span>=<span class="string">"['u-title', {'mb4': mode!=='open', 'ml48': mode!=='open'}]"</span>></span>{{ data.title || '--' }}<span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span> <span class="attr">:class</span>=<span class="string">"['u-description', {'ml48': mode!=='open'}]"</span>></span>{{ index + data.description || '--' }}<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">svg</span> <span class="attr">class</span>=<span class="string">"u-close"</span> @<span class="attr">click</span>=<span class="string">"onHideNotification(index)"</span> <span class="attr">viewBox</span>=<span class="string">"64 64 896 896"</span> <span class="attr">data-icon</span>=<span class="string">"close"</span> <span class="attr">aria-hidden</span>=<span class="string">"true"</span> <span class="attr">focusable</span>=<span class="string">"false"</span>></span><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"</span>></span><span class="tag"></<span class="name">path</span>></span><span class="tag"></<span class="name">svg</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">transition-group</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">template</span>></span></span><br><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">export</span> <span class="keyword">default</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">name</span>: <span class="string">'Notification'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">props</span>: {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">duration</span>: { <span class="comment">// 自动关闭的延时时长,单位ms,默认4500ms;设置null时,不自动关闭</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="title class_">Number</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">default</span>: <span class="number">4500</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">top</span>: { <span class="comment">// 消息从顶部弹出时,距离顶部的位置,单位像素px</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="title class_">Number</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">default</span>: <span class="number">24</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">bottom</span>: { <span class="comment">// 消息从底部弹出时,距离底部的位置,单位像素</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="title class_">Number</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">default</span>: <span class="number">24</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">placement</span>: { <span class="comment">// 消息弹出位置,可选topLeft,topRight,bottomLeft,bottomRight</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="title class_">String</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">default</span>: <span class="string">'topRight'</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"> data () {</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">colorStyle</span>: { <span class="comment">// 颜色主题对象</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">info</span>: <span class="string">'#1890FF'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">success</span>: <span class="string">'#52c41a'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">error</span>: <span class="string">'#f5222d'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">warn</span>: <span class="string">'#faad14'</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">mode</span>: <span class="string">'info'</span>, <span class="comment">// 调用方法对应的样式主题</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">resetTimer</span>: <span class="literal">null</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">hideIndex</span>: [],</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">hideTimers</span>: [],</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">notificationData</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">computed</span>: {</span></span><br><span class="line"><span class="language-javascript"> clear () { <span class="comment">// 所有提示是否已经全部变为false</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">hideIndex</span>.<span class="property">length</span> === <span class="variable language_">this</span>.<span class="property">notificationData</span>.<span class="property">length</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">watch</span>: {</span></span><br><span class="line"><span class="language-javascript"> clear (to, <span class="keyword">from</span>) { <span class="comment">// 所有提示都消失后重置</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (!<span class="keyword">from</span> && to) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">resetTimer</span> = <span class="built_in">setTimeout</span>(<span class="function">() =></span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">hideIndex</span>.<span class="title function_">splice</span>(<span class="number">0</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">notificationData</span>.<span class="title function_">splice</span>(<span class="number">0</span>)</span></span><br><span class="line"><span class="language-javascript"> }, <span class="number">500</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"> onEnter (index) {</span></span><br><span class="line"><span class="language-javascript"> <span class="built_in">clearTimeout</span>(<span class="variable language_">this</span>.<span class="property">hideTimers</span>[index])</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.$set(<span class="variable language_">this</span>.<span class="property">hideTimers</span>, index, <span class="literal">null</span>)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> onLeave (index) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (<span class="variable language_">this</span>.<span class="property">duration</span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.$set(<span class="variable language_">this</span>.<span class="property">hideTimers</span>, index, <span class="built_in">setTimeout</span>(<span class="function">() =></span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">onHideNotification</span>(index)</span></span><br><span class="line"><span class="language-javascript"> }, <span class="variable language_">this</span>.<span class="property">duration</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"> show (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="built_in">clearTimeout</span>(<span class="variable language_">this</span>.<span class="property">resetTimer</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">notificationData</span>.<span class="title function_">push</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">hideTimers</span>.<span class="title function_">push</span>(<span class="literal">null</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">const</span> index = <span class="variable language_">this</span>.<span class="property">notificationData</span>.<span class="property">length</span> - <span class="number">1</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (<span class="variable language_">this</span>.<span class="property">duration</span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.$set(<span class="variable language_">this</span>.<span class="property">hideTimers</span>, index, <span class="built_in">setTimeout</span>(<span class="function">() =></span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">onHideNotification</span>(index)</span></span><br><span class="line"><span class="language-javascript"> }, <span class="variable language_">this</span>.<span class="property">duration</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"> open (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">mode</span> = <span class="string">'open'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">show</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> info (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">mode</span> = <span class="string">'info'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">show</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> success (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">mode</span> = <span class="string">'success'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">show</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> error (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">mode</span> = <span class="string">'error'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">show</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> warn (notification) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">mode</span> = <span class="string">'warn'</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">show</span>(notification)</span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> onHideNotification (index) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">hideIndex</span>.<span class="title function_">push</span>(index)</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.$emit(<span class="string">'close'</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 class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">lang</span>=<span class="string">"less"</span> <span class="attr">scoped</span>></span><span class="language-css"></span></span><br><span class="line"><span class="language-css">// 渐变过渡效果</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.fade-enter-active</span>, <span class="selector-class">.fade-leave-active</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transition</span>: opacity .<span class="number">3s</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.fade-enter</span>, <span class="selector-class">.fade-leave-to</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">opacity</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css">// 滑动渐变过渡效果</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.slide-fade-enter-active</span>, <span class="selector-class">.slide-fade-leave-active</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transition</span>: all .<span class="number">3s</span> ease;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.slide-fade-enter</span>, <span class="selector-class">.slide-fade-leave-to</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transform</span>: <span class="built_in">translateX</span>(<span class="number">408px</span>);</span></span><br><span class="line"><span class="language-css"> -ms-<span class="attribute">transform</span>: <span class="built_in">translateX</span>(<span class="number">408px</span>); <span class="comment">/* IE 9 */</span></span></span><br><span class="line"><span class="language-css"> -webkit-<span class="attribute">transform</span>: <span class="built_in">translateX</span>(<span class="number">408px</span>); <span class="comment">/* Safari and Chrome */</span></span></span><br><span class="line"><span class="language-css"> <span class="attribute">opacity</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.topRight</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-right</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">right</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.topLeft</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-left</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">left</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.bottomRight</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-right</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">right</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.bottomLeft</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-left</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">left</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"><span class="selector-class">.m-notification-wrap</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">position</span>: fixed;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">z-index</span>: <span class="number">999</span>; // 突出显示该层级</span></span><br><span class="line"><span class="language-css"> <span class="attribute">width</span>: <span class="number">384px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="built_in">rgba</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,.<span class="number">65</span>);</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-size</span>: <span class="number">14px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.m-notification</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-bottom</span>: <span class="number">16px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">padding</span>: <span class="number">16px</span> <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">border-radius</span>: <span class="number">4px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">box-shadow</span>: <span class="number">0</span> <span class="number">4px</span> <span class="number">12px</span> <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">15%</span>);</span></span><br><span class="line"><span class="language-css"> <span class="attribute">line-height</span>: <span class="number">1.5</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background</span>: <span class="number">#fff</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transition</span>: all .<span class="number">3s</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">position</span>: relative;</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.u-status-svg</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">width</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">height</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">display</span>: inline-block;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">position</span>: absolute;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-left</span>: <span class="number">4px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.u-title</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">padding-right</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">display</span>: inline-block;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-bottom</span>: <span class="number">8px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="built_in">rgba</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,.<span class="number">85</span>);</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-size</span>: <span class="number">16px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">line-height</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.u-description</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-size</span>: <span class="number">14px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.mb4</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-bottom</span>: <span class="number">4px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.ml48</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin-left</span>: <span class="number">48px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.u-close</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">display</span>: inline-block;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">position</span>: absolute;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">top</span>: <span class="number">21px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">right</span>: <span class="number">24px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">width</span>: <span class="number">14px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">height</span>: <span class="number">14px</span>;</span></span><br><span class="line"><span class="language-css"> fill: <span class="built_in">rgba</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,.<span class="number">45</span>);</span></span><br><span class="line"><span class="language-css"> <span class="attribute">cursor</span>: pointer;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transition</span>: fill .<span class="number">3s</span> ease;</span></span><br><span class="line"><span class="language-css"> &<span class="selector-pseudo">:hover</span> {</span></span><br><span class="line"><span class="language-css"> fill: <span class="built_in">rgba</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,.<span class="number">75</span>);</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span><span class="tag"></<span class="name">style</span>></span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="在要使用的页面引入"><a href="#在要使用的页面引入" class="headerlink" title="在要使用的页面引入"></a>在要使用的页面引入</h3><figure class="highlight javascript"><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 class="title class_">Notification</span></span><br><span class="line"> ref=<span class="string">"notification"</span></span><br><span class="line"> placement=<span class="string">"topRight"</span></span><br><span class="line"> :duration=<span class="string">"null"</span></span><br><span class="line"> :top=<span class="string">"30"</span></span><br><span class="line"> @close=<span class="string">"onClose"</span> /></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">Notification</span> <span class="keyword">from</span> <span class="string">'@/components/Notification'</span></span><br><span class="line"><span class="attr">components</span>: {</span><br><span class="line"> <span class="title class_">Notification</span></span><br><span class="line">}</span><br><span class="line">onShowNotification () {</span><br><span class="line"> <span class="keyword">const</span> notification = {</span><br><span class="line"> <span class="attr">title</span>: <span class="string">'Notification Title'</span>,</span><br><span class="line"> <span class="attr">description</span>: <span class="string">'This is the content of the notification. This is the content of the notification. This is the content of the notification.'</span></span><br><span class="line"> }</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">$refs</span>.<span class="property">notification</span>.<span class="title function_">open</span>(notification) <span class="comment">// 默认使用</span></span><br><span class="line"> <span class="comment">// this.$refs.notification.info(notification) // info调用</span></span><br><span class="line"> <span class="comment">// this.$refs.notification.success(notification) // success调用</span></span><br><span class="line"> <span class="comment">// this.$refs.notification.error(notification) // error调用</span></span><br><span class="line"> <span class="comment">// this.$refs.notification.warn(notification) // warning调用</span></span><br><span class="line">},</span><br><span class="line">onClose () { <span class="comment">// 点击默认关闭按钮时触发的回调函数</span></span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">'关闭notification'</span>)</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 通知 </category>
</categories>
<tags>
<tag> Vue2 </tag>
</tags>
</entry>
<entry>
<title>Layui实现放大图片的效果</title>
<link href="/2024/06/03/Layui%E5%AE%9E%E7%8E%B0%E6%94%BE%E5%A4%A7%E5%9B%BE%E7%89%87%E7%9A%84%E6%95%88%E6%9E%9C/"/>
<url>/2024/06/03/Layui%E5%AE%9E%E7%8E%B0%E6%94%BE%E5%A4%A7%E5%9B%BE%E7%89%87%E7%9A%84%E6%95%88%E6%9E%9C/</url>
<content type="html"><![CDATA[<p>需要在表格里面添加查看图片的模板</p><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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">style</span>=<span class="string">"width: 400px;height: 200px"</span> <span class="attr">onclick</span>=<span class="string">"showLarge('../images/lidong.jpg')"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">img</span> <span class="attr">height</span>=<span class="string">"100%"</span> <span class="attr">width</span>=<span class="string">"100%"</span> <span class="attr">src</span>=<span class="string">"../images/lidong.jpg"</span> <span class="attr">alt</span>=<span class="string">""</span>></span></span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure><p>放大的function</p><figure class="highlight javascript"><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></pre></td><td class="code"><pre><span class="line"><script type=<span class="string">"text/javascript"</span> ></span><br><span class="line"><span class="comment">//查看大图</span></span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">showLarge</span>(<span class="params">src</span>) {</span><br><span class="line"> layer.<span class="title function_">photos</span>({</span><br><span class="line"> <span class="attr">photos</span>: {</span><br><span class="line"> <span class="string">"title"</span>: <span class="string">""</span>, <span class="comment">//相册标题</span></span><br><span class="line"> <span class="string">"id"</span>: <span class="number">123</span>, <span class="comment">//相册id</span></span><br><span class="line"> <span class="string">"start"</span>: <span class="number">0</span>, <span class="comment">//初始显示的图片序号,默认0</span></span><br><span class="line"> <span class="string">"data"</span>: [ <span class="comment">//相册包含的图片,数组格式</span></span><br><span class="line"> {</span><br><span class="line"> <span class="string">"alt"</span>: <span class="string">"图片名"</span>,</span><br><span class="line"> <span class="string">"pid"</span>: <span class="number">666</span>, <span class="comment">//图片id</span></span><br><span class="line"> <span class="string">"src"</span>: src, <span class="comment">//原图地址</span></span><br><span class="line"> <span class="string">"thumb"</span>: <span class="string">""</span> <span class="comment">//缩略图地址</span></span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="string">"alt"</span>: <span class="string">"图片名"</span>,</span><br><span class="line"> <span class="string">"pid"</span>: <span class="number">555</span>, <span class="comment">//图片id</span></span><br><span class="line"> <span class="string">"src"</span>: <span class="string">'../images/lidong.jpg'</span>, <span class="comment">//原图地址</span></span><br><span class="line"> <span class="string">"thumb"</span>: <span class="string">""</span> <span class="comment">//缩略图地址</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> ,<span class="attr">anim</span>: <span class="number">0</span> <span class="comment">//0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)</span></span><br><span class="line"> })</span><br><span class="line"> }</span><br><span class="line"></script></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Layui </tag>
</tags>
</entry>
<entry>
<title>镜像</title>
<link href="/2024/05/08/%E9%95%9C%E5%83%8F/"/>
<url>/2024/05/08/%E9%95%9C%E5%83%8F/</url>
<content type="html"><![CDATA[<p>npm </p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm config <span class="built_in">set</span> registry https://registry.npmmirror.com</span><br></pre></td></tr></table></figure><p>nvm</p><figure class="highlight bash"><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">node_mirror: https://npmmirror.com/mirrors/node/</span><br><span class="line">npm_mirror: https://npmmirror.com/mirrors/npm/</span><br></pre></td></tr></table></figure><p>python</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package</span><br></pre></td></tr></table></figure><p>kali</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line">中科大 </span><br><span class="line">deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib </span><br><span class="line">deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib</span><br><span class="line"> </span><br><span class="line">阿里云 </span><br><span class="line">deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib </span><br><span class="line">deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib</span><br><span class="line"> </span><br><span class="line">清华大学 </span><br><span class="line">deb http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free </span><br><span class="line">deb-src https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free</span><br><span class="line"> </span><br><span class="line">说明:deb代表软件的位置,deb-src代表软件的源代码位置</span><br><span class="line"> </span><br><span class="line">配置kali apt为阿里源实例:</span><br><span class="line">配置思路方法 修改 /etc/apt/sources.list,加入以下内容将相关url改成阿里云的源。 </span><br><span class="line"> </span><br><span class="line">deb https://mirrors.aliyun.com/kali kali-rolling main non-free contrib </span><br><span class="line">deb-src https://mirrors.aliyun.com/kali kali-rolling main non-free contrib</span><br><span class="line"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 小笔记 </category>
</categories>
</entry>
<entry>
<title>Vue2使用g2</title>
<link href="/2024/05/05/Vue2%E4%BD%BF%E7%94%A8g2/"/>
<url>/2024/05/05/Vue2%E4%BD%BF%E7%94%A8g2/</url>
<content type="html"><![CDATA[<h3 id="标题"><a href="#标题" class="headerlink" title="标题"></a>标题</h3><p><em>其实vue2和vue3用法差不多,使用的g2也是5.x的预防,其中的区别就是script块的写法不太一样,vue3更简洁更方便</em> </p><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><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">template</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">div</span> <span class="attr">ref</span>=<span class="string">"chartRef"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"></span><br><span class="line"></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">template</span>></span></span><br><span class="line"> </span><br><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">import</span> { <span class="title class_">Chart</span> } <span class="keyword">from</span> <span class="string">'@antv/g2'</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">export</span> <span class="keyword">default</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">name</span>: <span class="string">'ChartComponent'</span>, <span class="comment">// 组件名称 </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">chart</span>: <span class="literal">null</span>, <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></span><br><span class="line"><span class="language-javascript"> <span class="title function_">mounted</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="title function_">initChart</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="title function_">initChart</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">const</span> chartRef = <span class="variable language_">this</span>.<span class="property">$refs</span>.<span class="property">chartRef</span>; <span class="comment">// 使用 this.$refs 引用 DOM 元素 </span></span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">const</span> keys = <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">dataHeader</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(keys)</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">chart</span> = <span class="keyword">new</span> <span class="title class_">Chart</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">container</span>: chartRef,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">autoFit</span>: <span class="literal">true</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="comment">// ... 图表配置代码保持不变 ... </span></span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// chart.coordinate({ type: 'theta' });</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="variable language_">this</span>.<span class="property">chart</span></span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">title</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></span><br><span class="line"><span class="language-javascript"> <span class="comment">// .interval()</span></span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">data</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="string">'fetch'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">value</span>: process.<span class="property">env</span>.<span class="property">VUE_APP_HADOOP_BASE_API</span> + <span class="string">'/hdfs/read-csv/yuce?path=/output/hdfsJobByYear/part-r-00000'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// process.env.VUE_APP_HADOOP_BASE_API 为所访问的后端地址</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">format</span>: <span class="string">'csv'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">autoType</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">transform</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">type</span>: <span class="string">'map'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">callback</span>: <span class="function">(<span class="params">val</span>) =></span> { val[<span class="string">'年'</span>] = val[<span class="string">'时间'</span>] + <span class="string">'年'</span>; <span class="keyword">return</span> val; },</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="comment">// type: 'custom',</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// callback: (data) => {</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// const result = keys.map(key => {</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// const re = data.reduce((currentSum, item) => currentSum + item[key] , 0)</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// return data</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">// return result</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">// },</span></span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="string">'fold'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">fields</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">dataHeader</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">key</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartX</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">value</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartY</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">type</span>: <span class="string">'sortBy'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">fields</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">type</span>: <span class="string">'log'</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_">encode</span>(<span class="string">'x'</span>, <span class="string">'时间'</span>)</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">encode</span>(<span class="string">'y'</span>, <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartY</span>)</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">encode</span>(<span class="string">'color'</span>, <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartX</span>)</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">scale</span>(<span class="string">'x'</span>, {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">range</span>: [<span class="number">0</span>, <span class="number">1</span>],</span></span><br><span class="line"><span class="language-javascript"> })</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">scale</span>(<span class="string">'y'</span>, {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">nice</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> })</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">axis</span>(<span class="string">'x'</span>, { <span class="attr">title</span>: <span class="literal">null</span>, <span class="attr">line</span>: <span class="literal">true</span>, <span class="attr">tick</span>: <span class="literal">true</span> })</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">axis</span>(<span class="string">'y'</span>, {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: <span class="literal">null</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">line</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> })</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">chart</span>.<span class="title function_">line</span>().<span class="title function_">encode</span>(<span class="string">'shape'</span>, <span class="string">'smooth'</span>);</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">this</span>.<span class="property">chart</span>.<span class="title function_">render</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="comment">// 如果需要从父组件传递 prop,可以这样定义 </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></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><span class="line"> </span><br><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">scoped</span>></span><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-pseudo">:root</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-family</span>: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">line-height</span>: <span class="number">1.5</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-weight</span>: <span class="number">400</span>;</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>-scheme: light dark;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.87</span>);</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background-color</span>: <span class="number">#242424</span>;</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-synthesis</span>: none;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">text-rendering</span>: optimizeLegibility;</span></span><br><span class="line"><span class="language-css"> -webkit-<span class="attribute">font-smoothing</span>: antialiased;</span></span><br><span class="line"><span class="language-css"> -moz-osx-<span class="attribute">font-smoothing</span>: grayscale;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">a</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-weight</span>: <span class="number">500</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="number">#646cff</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">text-decoration</span>: inherit;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">a</span><span class="selector-pseudo">:hover</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="number">#535bf2</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">body</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css"> <span class="comment">/* display: flex; */</span></span></span><br><span class="line"><span class="language-css"> place-items: center;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">min-width</span>: <span class="number">320px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">width</span>: <span class="number">100%</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">min-height</span>: <span class="number">100vh</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">h1</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-size</span>: <span class="number">3.2em</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">line-height</span>: <span class="number">1.1</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">button</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">border-radius</span>: <span class="number">8px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">border</span>: <span class="number">1px</span> solid transparent;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">padding</span>: <span class="number">0.6em</span> <span class="number">1.2em</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-size</span>: <span class="number">1em</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-weight</span>: <span class="number">500</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">font-family</span>: inherit;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background-color</span>: <span class="number">#fffbfb</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">cursor</span>: pointer;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">transition</span>: border-color <span class="number">0.25s</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">button</span><span class="selector-pseudo">:hover</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">border-color</span>: <span class="number">#646cff</span>;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="selector-tag">button</span><span class="selector-pseudo">:focus</span>,</span></span><br><span class="line"><span class="language-css"><span class="selector-tag">button</span><span class="selector-pseudo">:focus</span>-visible {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">outline</span>: <span class="number">4px</span> auto -webkit-focus-ring-color;</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="comment">/* .card {</span></span></span><br><span class="line"><span class="comment"><span class="language-css"> padding: 2em;</span></span></span><br><span class="line"><span class="comment"><span class="language-css">} */</span></span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="comment">/* #app {</span></span></span><br><span class="line"><span class="comment"><span class="language-css"> max-width: 1280px;</span></span></span><br><span class="line"><span class="comment"><span class="language-css"> margin: 0 auto;</span></span></span><br><span class="line"><span class="comment"><span class="language-css"> padding: 2rem;</span></span></span><br><span class="line"><span class="comment"><span class="language-css"> text-align: center;</span></span></span><br><span class="line"><span class="comment"><span class="language-css">} */</span></span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"><span class="keyword">@media</span> (<span class="attribute">prefers-color-scheme</span>: light) {</span></span><br><span class="line"><span class="language-css"> <span class="selector-pseudo">:root</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="number">#213547</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background-color</span>: <span class="number">#ffffff</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"> <span class="selector-tag">a</span><span class="selector-pseudo">:hover</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">color</span>: <span class="number">#747bff</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"></span></span><br><span class="line"><span class="language-css"> <span class="selector-tag">button</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background-color</span>: <span class="number">#f9f9f9</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css">}</span></span><br><span class="line"><span class="language-css"></span><span class="tag"></<span class="name">style</span>></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> G2 </tag>
<tag> Vue </tag>
</tags>
</entry>
<entry>
<title>跨域访问</title>
<link href="/2024/05/03/%E8%B7%A8%E5%9F%9F%E8%AE%BF%E9%97%AE/"/>
<url>/2024/05/03/%E8%B7%A8%E5%9F%9F%E8%AE%BF%E9%97%AE/</url>
<content type="html"><![CDATA[<h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>使用Vue对后台的资源进行访问,发生跨域的请求,会产生如下的报错</p><blockquote><p>Access to fetch at ‘<a href="http://localhost:8080/hdfs/read-csv?path=/output/hdfsJobByMonth/part-r-00000">http://localhost:8080/hdfs/read-csv?path=/output/hdfsJobByMonth/part-r-00000</a>‘ from origin ‘<a href="http://localhost:9528/">http://localhost:9528</a>‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.</p></blockquote><p>这个错误表明前端应用(运行在 <a href="http://localhost:9528)试图通过">http://localhost:9528)试图通过</a> fetch API 访问后端服务(运行在 <a href="http://localhost:8080)的某个资源,但是由于跨域资源共享(CORS)策略的限制,这个请求被浏览器阻止了">http://localhost:8080)的某个资源,但是由于跨域资源共享(CORS)策略的限制,这个请求被浏览器阻止了</a> </p><p>CORS 策略要求服务器在响应中包含一些特定的 HTTP 头信息,比如 <code>Access-Control-Allow-Origin</code>,来告诉浏览器哪些源(即哪些域、协议和端口)有权访问该资源。在这个例子中,服务器没有在响应中包含这个必要的头信息。</p><p>要解决这个问题,有几种解决办法:</p><ol><li><p><strong>配置后端服务以支持 CORS</strong>:<br>在后端服务(<code>http://localhost:8080</code>)上添加 CORS 支持。这通常意味着在响应中包含适当的 HTTP 头,如 <code>Access-Control-Allow-Origin: *</code>(允许所有源)或 <code>Access-Control-Allow-Origin: http://localhost:9528</code>(仅允许来自 <code>http://localhost:9528</code> 的请求)。但是请注意,将 <code>Access-Control-Allow-Origin</code> 设置为 <code>*</code> 可能会带来安全风险,特别是如果服务涉及敏感数据。</p></li><li><p><strong>使用代理服务器</strong>:<br>可以在前端应用中设置一个代理服务器,该服务器将请求转发到后端服务,并在转发响应时添加 CORS 头。这通常可以通过配置开发服务器(如 webpack-dev-server、Create React App 的开发服务器等)来实现。</p></li><li><p><strong>使用 <code>no-cors</code> 模式</strong>(不推荐):<br>可以将 fetch 请求的模式设置为 <code>no-cors</code> 来绕过 CORS 策略,但这将导致响应变得不透明(opaque),前端无法读取响应的内容。因此,这通常不是一个好的解决方案,除非确实不需要读取响应的内容。</p></li><li><p><strong>在本地开发时禁用浏览器的 CORS 检查</strong>:<br>这可以通过在浏览器中使用插件或特殊模式来实现,但请注意,这只是一个临时的解决方案,并且不应该在生产环境中使用,因为它会暴露应用于安全风险。</p></li><li><p><strong>使用 JSONP</strong>(如果适用):<br>如果后端服务支持 JSONP,并且只是想获取 JSON 数据,那么可以使用 JSONP 来绕过 CORS 策略。但是,JSONP 有一些限制,比如它只支持 GET 请求,并且只能返回 JSONP 格式的响应。</p></li></ol><h2 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h2><p>使用第一种方式,在后端服务配置允许跨域访问<br>如下有几种方式:</p><h3 id="方法一:全局CORS配置"><a href="#方法一:全局CORS配置" class="headerlink" title="方法一:全局CORS配置"></a>方法一:全局CORS配置</h3><p>可以通过配置类中添加一个<code>WebMvcConfigurer</code> bean来全局配置CORS。</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><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="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.config.annotation.CorsRegistry;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.config.annotation.WebMvcConfigurer;</span><br><span class="line"></span><br><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><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_">addCorsMappings</span><span class="params">(CorsRegistry registry)</span> {</span><br><span class="line"> registry.addMapping(<span class="string">"/**"</span>) <span class="comment">// 允许所有路径</span></span><br><span class="line"> .allowedOrigins(<span class="string">"http://localhost:9528"</span>) <span class="comment">// 允许哪些源的请求</span></span><br><span class="line"> .allowedMethods(<span class="string">"GET"</span>, <span class="string">"POST"</span>, <span class="string">"PUT"</span>, <span class="string">"DELETE"</span>) <span class="comment">// 允许哪些方法</span></span><br><span class="line"> .allowedHeaders(<span class="string">"*"</span>) <span class="comment">// 允许哪些请求头</span></span><br><span class="line"> .allowCredentials(<span class="literal">true</span>) <span class="comment">// 是否允许携带认证信息(cookies, HTTP认证及客户端SSL证明等)</span></span><br><span class="line"> .maxAge(<span class="number">3600</span>); <span class="comment">// 缓存CORS信息的时间(秒),默认是1800秒</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="方法二:使用-CrossOrigin注解"><a href="#方法二:使用-CrossOrigin注解" class="headerlink" title="方法二:使用@CrossOrigin注解"></a>方法二:使用<code>@CrossOrigin</code>注解</h3><p>也可以在Controller类或者特定的方法上使用<code>@CrossOrigin</code>注解来启用CORS。</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.CrossOrigin;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.GetMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RestController;</span><br><span class="line"></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@CrossOrigin(origins = "http://localhost:9528")</span> <span class="comment">// 允许哪些源的请求</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyController</span> {</span><br><span class="line"></span><br><span class="line"> <span class="meta">@GetMapping("/hdfs/read-csv")</span></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">readCsv</span><span class="params">(<span class="meta">@RequestParam</span> String path)</span> {</span><br><span class="line"> <span class="comment">// ... 逻辑代码 ...</span></span><br><span class="line"> <span class="keyword">return</span> <span class="string">"Data from CSV"</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="方法三:自定义CORS过滤器"><a href="#方法三:自定义CORS过滤器" class="headerlink" title="方法三:自定义CORS过滤器"></a>方法三:自定义CORS过滤器</h3><p>需要更复杂的CORS配置,可以创建一个自定义的CORS过滤器。</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><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="keyword">import</span> org.springframework.core.Ordered;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.*;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"></span><br><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_">CustomCorsFilter</span> <span class="keyword">implements</span> <span class="title class_">Filter</span>, Ordered {</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_">doFilter</span><span class="params">(ServletRequest req, ServletResponse res, FilterChain chain)</span></span><br><span class="line"> <span class="keyword">throws</span> IOException, ServletException {</span><br><span class="line"> <span class="type">HttpServletResponse</span> <span class="variable">response</span> <span class="operator">=</span> (HttpServletResponse) res;</span><br><span class="line"> <span class="type">HttpServletRequest</span> <span class="variable">request</span> <span class="operator">=</span> (HttpServletRequest) req;</span><br><span class="line"> response.setHeader(<span class="string">"Access-Control-Allow-Origin"</span>, <span class="string">"http://localhost:9528"</span>);</span><br><span class="line"> response.setHeader(<span class="string">"Access-Control-Allow-Methods"</span>, <span class="string">"POST, GET, OPTIONS, DELETE"</span>);</span><br><span class="line"> response.setHeader(<span class="string">"Access-Control-Max-Age"</span>, <span class="string">"3600"</span>);</span><br><span class="line"> response.setHeader(<span class="string">"Access-Control-Allow-Headers"</span>, <span class="string">"x-requested-with"</span>);</span><br><span class="line"> chain.doFilter(req, res);</span><br><span class="line"> }</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="type">int</span> <span class="title function_">getOrder</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>; <span class="comment">// 设置过滤器顺序</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h3><ul><li>当使用<code>allowedOrigins</code>时,如果只想允许来自特定域名的请求,就指定那个域名。如果想允许来自任何域名的请求(注意:这可能会带来安全风险),可以使用<code>"*"</code>。</li><li><code>allowCredentials(true)</code>允许跨域请求携带认证信息(如cookies),但这要求<code>Access-Control-Allow-Origin</code>不能是<code>"*"</code>,而必须是一个明确的域名。</li><li>如果前端应用需要处理预检请求(OPTIONS请求),确保后端配置也支持这些请求。预检请求是浏览器在发送实际请求之前发送的,以检查服务器是否允许跨域请求。</li></ul>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> G2 </tag>
<tag> Vue </tag>
</tags>
</entry>
<entry>
<title>privateMap.get is not a function</title>
<link href="/2024/05/01/privateMap%20get%20is%20not%20a%20function/"/>
<url>/2024/05/01/privateMap%20get%20is%20not%20a%20function/</url>
<content type="html"><![CDATA[<h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><p>G2图绘制过程中,在渲染过程中前端报错其中报错信息如下</p><blockquote><p>tslib.es6.js:233 Uncaught (in promise) TypeError: privateMap.get is not a function</p></blockquote><p>在GitHub上找到相应的解答</p><h3 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h3><p>内部包缺少<code>tslib</code></p><figure class="highlight bash"><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">npm install --save tslib</span><br><span class="line">npm run start</span><br></pre></td></tr></table></figure><p>GitHub原文链接</p><p><a href="%5Bhttps://%5D(https://github.com/descope/react-sdk/issues/301)">TypeError: privateMap.get is not a function</a></p>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> G2 </tag>
</tags>
</entry>
<entry>
<title>Can't find dependent libraries</title>
<link href="/2024/04/30/Can't%20find%20dependent%20libraries/"/>
<url>/2024/04/30/Can't%20find%20dependent%20libraries/</url>
<content type="html"><![CDATA[<h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><p>在部署hadoop项目过程中,出现了这个报错<br><em>Exception in thread “main” java.lang.UnsatisfiedLinkError: E:\winutils-master\hadoop-3.3.5\bin\hadoop.dll: Can’t find dependent libraries</em><br>这个报错大概意思就是:dll缺所需的依赖 </p><h3 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h3><p>使用depends来查找所缺的依赖,该工具的下载地址:<a href="http://www.dependencywalker.com/">depends</a> </p><p>使用的时候直接把dll文件拽进去等着搜索就行了<br> <img src="/img/posts/20240430.png" alt="alt"><br>如图可以看到缺了哪些依赖,直接上网搜索添加即可<br>只需要查看第一层即可</p><h3 id="depends查找很慢"><a href="#depends查找很慢" class="headerlink" title="depends查找很慢"></a>depends查找很慢</h3><ul><li><p>创建run_depends.txt文件</p></li><li><p>输入以下内容(两行)</p> <figure class="highlight bat"><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="built_in">set</span> <span class="built_in">PATH</span>=""</span><br><span class="line">"D:\Tools\depends\depends22_x64\depends.exe"</span><br></pre></td></tr></table></figure><p><em>注意要讲上面的路径改成depends的路径</em></p></li><li><p>将run_depends.txt后缀名改为bat</p></li></ul><p>然后直接启动这个bat文件就可以了,这样查找很快速</p>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> Hadoop </tag>
</tags>
</entry>
<entry>
<title>炫酷的border样式</title>
<link href="/2024/04/28/%E7%82%AB%E9%85%B7%E7%9A%84border%E6%A0%B7%E5%BC%8F/"/>
<url>/2024/04/28/%E7%82%AB%E9%85%B7%E7%9A%84border%E6%A0%B7%E5%BC%8F/</url>
<content type="html"><![CDATA[<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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"item"</span> <span class="attr">info</span>=<span class="string">"彩虹边框"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight css"><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="selector-tag">div</span><span class="selector-class">.item</span> <span class="selector-tag">div</span>{ </span><br><span class="line"> <span class="attr">--borderWidth</span>: <span class="number">12px</span>;</span><br><span class="line"> <span class="attr">--bRadius</span>: <span class="number">5px</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">60%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">60%</span>;</span><br><span class="line"> <span class="attribute">position</span>: relative;</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">overflow</span>: hidden;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">2rem</span>;</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: --bRadius;</span><br><span class="line"></span><br><span class="line"> &<span class="selector-pseudo">::after</span>, &<span class="selector-pseudo">::before</span> {</span><br><span class="line"> <span class="attribute">box-sizing</span>: border-box;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> &<span class="selector-pseudo">::before</span> {</span><br><span class="line"> <span class="attribute">content</span>: <span class="string">''</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">left</span>: -<span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">top</span>: -<span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">200%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">200%</span>;</span><br><span class="line"> <span class="attribute">z-index</span>: -<span class="number">2</span>;</span><br><span class="line"> <span class="attribute">background-repeat</span>: no-repeat;</span><br><span class="line"> <span class="attribute">background-size</span>: <span class="number">50%</span> <span class="number">50%</span>, <span class="number">50%</span> <span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">background-position</span>: <span class="number">0</span> <span class="number">0</span>, <span class="number">100%</span> <span class="number">0</span>, <span class="number">100%</span> <span class="number">100%</span>, <span class="number">0</span> <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">background-image</span>: <span class="built_in">linear-gradient</span>(<span class="number">#399953</span>, <span class="number">#399953</span>), <span class="built_in">linear-gradient</span>(<span class="number">#fbb300</span>, <span class="number">#fbb300</span>), <span class="built_in">linear-gradient</span>(<span class="number">#d53e33</span>, <span class="number">#d53e33</span>), <span class="built_in">linear-gradient</span>(<span class="number">#377af5</span>, <span class="number">#377af5</span>);</span><br><span class="line"> <span class="attribute">animation</span>: rotate <span class="number">4s</span> linear infinite;</span><br><span class="line"> <span class="keyword">@keyframes</span> rotate {</span><br><span class="line"> <span class="number">100%</span> {</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">rotate</span>(<span class="number">1turn</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> &<span class="selector-pseudo">::after</span> {</span><br><span class="line"><span class="attribute">content</span>: <span class="string">''</span>;</span><br><span class="line"><span class="attribute">position</span>: absolute;</span><br><span class="line"><span class="attribute">z-index</span>: -<span class="number">1</span>;</span><br><span class="line"><span class="attribute">left</span>: <span class="built_in">calc</span>(<span class="built_in">var</span>(--borderWidth) / <span class="number">2</span>);</span><br><span class="line"><span class="attribute">top</span>: <span class="built_in">calc</span>(<span class="built_in">var</span>(--borderWidth) / <span class="number">2</span>);</span><br><span class="line"><span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="built_in">var</span>(--borderWidth));</span><br><span class="line"><span class="attribute">height</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="built_in">var</span>(--borderWidth));</span><br><span class="line"><span class="attribute">background</span>: white;</span><br><span class="line"><span class="attribute">border-radius</span>: --bRadius;</span><br><span class="line"> <span class="comment">/* 这一行是为了方便查看原来的样子的 */</span></span><br><span class="line"><span class="attribute">animation</span>: opacityChange <span class="number">3s</span> infinite alternate;</span><br><span class="line">}</span><br><span class="line"> <span class="keyword">@keyframes</span> opacityChange {</span><br><span class="line"> <span class="number">50%</span> {</span><br><span class="line"> <span class="attribute">opacity</span>:<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="number">100%</span> {</span><br><span class="line"> <span class="attribute">opacity</span>: .<span class="number">5</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"item"</span> <span class="attr">info</span>=<span class="string">"质感边框"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight css"><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">@keyframes</span> opacityChange {</span><br><span class="line"> <span class="number">50%</span> {</span><br><span class="line"> <span class="attribute">opacity</span>:.<span class="number">5</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="number">100%</span> {</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="keyword">@keyframes</span> rotate {</span><br><span class="line"><span class="number">100%</span> {</span><br><span class="line"><span class="attribute">transform</span>: <span class="built_in">rotate</span>(<span class="number">1turn</span>);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="selector-tag">div</span><span class="selector-class">.item</span> {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#000</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">20px</span>;</span><br><span class="line"> <span class="selector-tag">div</span>{ </span><br><span class="line"> <span class="attr">--borderWidth</span>: <span class="number">12px</span>;</span><br><span class="line"> <span class="attr">--bRadius</span>: <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">60%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">60%</span>;</span><br><span class="line"> <span class="attribute">position</span>: relative;</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">overflow</span>: hidden;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">2rem</span>;</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: --bRadius;</span><br><span class="line"> &<span class="selector-pseudo">::after</span>, &<span class="selector-pseudo">::before</span> {</span><br><span class="line"> <span class="attribute">box-sizing</span>: border-box;</span><br><span class="line"> }</span><br><span class="line"> &<span class="selector-pseudo">::before</span> {</span><br><span class="line"> <span class="attribute">content</span>: <span class="string">''</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">z-index</span>: -<span class="number">2</span>;</span><br><span class="line"> <span class="attribute">left</span>: -<span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">top</span>: -<span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">200%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">200%</span>;</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#1a232a</span>;</span><br><span class="line"> <span class="attribute">background-repeat</span>: no-repeat;</span><br><span class="line"> <span class="attribute">background-position</span>: <span class="number">0</span> <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">background-image</span>: <span class="built_in">conic-gradient</span>(transparent, <span class="built_in">rgba</span>(<span class="number">168</span>, <span class="number">239</span>, <span class="number">255</span>, <span class="number">1</span>), transparent <span class="number">30%</span>);</span><br><span class="line"> <span class="attribute">animation</span>: rotate <span class="number">4s</span> linear infinite;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> &<span class="selector-pseudo">::after</span> {</span><br><span class="line"> <span class="attribute">content</span>: <span class="string">''</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">z-index</span>: -<span class="number">1</span>;</span><br><span class="line"> <span class="attribute">left</span>: <span class="built_in">calc</span>(<span class="built_in">var</span>(--borderWidth) / <span class="number">2</span>);</span><br><span class="line"> <span class="attribute">top</span>: <span class="built_in">calc</span>(<span class="built_in">var</span>(--borderWidth) / <span class="number">2</span>);</span><br><span class="line"> <span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="built_in">var</span>(--borderWidth));</span><br><span class="line"> <span class="attribute">height</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="built_in">var</span>(--borderWidth));</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">#000</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">5px</span>;</span><br><span class="line"> <span class="comment">/* 这句效果打开有助于理解动画 */</span></span><br><span class="line"> <span class="comment">/*animation: opacityChange 5s infinite linear;*/</span></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"><span class="selector-tag">div</span><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">9</span>) <span class="selector-tag">div</span><span class="selector-pseudo">::after</span> {</span><br><span class="line"> <span class="attribute">animation</span>: opacityChange <span class="number">5s</span> infinite linear;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight css"><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></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="selector-tag">div</span><span class="selector-class">.item</span> {</span><br><span class="line"> <span class="attr">--bRadius</span>: <span class="number">10px</span>;</span><br><span class="line"> <span class="selector-tag">div</span>{</span><br><span class="line"> <span class="attribute">position</span>: relative;</span><br><span class="line"> <span class="attribute">text-align</span>: center;</span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">24px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">2px</span> solid <span class="built_in">rgb</span>(<span class="number">179</span>, <span class="number">191</span>, <span class="number">231</span>);</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="built_in">var</span>(--bRadius);</span><br><span class="line"> <span class="attribute">transition</span>: all .<span class="number">3s</span>;</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#eee</span>;</span><br><span class="line"> &<span class="selector-pseudo">::before</span>, &<span class="selector-pseudo">::after</span> {</span><br><span class="line"> <span class="attribute">content</span>: <span class="string">""</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">top</span>: -<span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">left</span>: -<span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">right</span>: -<span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">bottom</span>: -<span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">2px</span> solid <span class="built_in">rgb</span>(<span class="number">17</span>, <span class="number">36</span>, <span class="number">100</span>);</span><br><span class="line"> <span class="attribute">transition</span>: all .<span class="number">5s</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="built_in">var</span>(--bRadius);</span><br><span class="line"> <span class="attribute">animation</span>: clippath <span class="number">3s</span> infinite linear;</span><br><span class="line"> }</span><br><span class="line"> &<span class="selector-pseudo">::after</span> {</span><br><span class="line"> <span class="attribute">animation</span>: clippath <span class="number">3s</span> infinite -<span class="number">1.5s</span> linear;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">@keyframes</span> clippath {</span><br><span class="line"> <span class="number">0%</span>, <span class="number">100%</span> { <span class="attribute">clip-path</span>: <span class="built_in">inset</span>(<span class="number">0</span> <span class="number">0</span> <span class="number">98%</span> <span class="number">0</span>); }</span><br><span class="line"> <span class="number">25%</span> { <span class="attribute">clip-path</span>: <span class="built_in">inset</span>(<span class="number">0</span> <span class="number">98%</span> <span class="number">0</span> <span class="number">0</span>); }</span><br><span class="line"> <span class="number">50%</span> { <span class="attribute">clip-path</span>: <span class="built_in">inset</span>(<span class="number">98%</span> <span class="number">0</span> <span class="number">0</span> <span class="number">0</span>); }</span><br><span class="line"> <span class="number">75%</span> { <span class="attribute">clip-path</span>: <span class="built_in">inset</span>(<span class="number">0</span> <span class="number">0</span> <span class="number">0</span> <span class="number">98%</span>); }</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"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> css </tag>
</tags>
</entry>
<entry>
<title>自用-yml配置文件</title>
<link href="/2024/04/28/%EF%BC%88%E8%87%AA%E7%94%A8%EF%BC%89yml%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/"/>
<url>/2024/04/28/%EF%BC%88%E8%87%AA%E7%94%A8%EF%BC%89yml%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/</url>
<content type="html"><![CDATA[<figure class="highlight yml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">server :</span></span><br><span class="line"> <span class="attr">port :</span> <span class="number">8080</span></span><br><span class="line"> <span class="comment">##项目名字配置</span></span><br><span class="line"> <span class="comment">#servlet :</span></span><br><span class="line"> <span class="comment"># context-path : /demo</span></span><br><span class="line"> <span class="attr">tomcat :</span></span><br><span class="line"> <span class="attr">uri-encoding :</span> <span class="string">UTF-8</span></span><br><span class="line"> <span class="comment">#xx 报错修改的地方</span></span><br><span class="line"> <span class="attr">max-connections:</span> <span class="number">200000</span></span><br><span class="line"> <span class="attr">max-http-form-post-size:</span> <span class="number">9000000</span></span><br><span class="line"> <span class="attr">threads:</span></span><br><span class="line"> <span class="attr">max:</span> <span class="number">128</span></span><br><span class="line"> <span class="attr">min-spare:</span> <span class="number">5</span></span><br><span class="line"><span class="attr">spring :</span></span><br><span class="line"> <span class="comment"># 环境 dev|test|prod</span></span><br><span class="line"> <span class="attr">profiles :</span></span><br><span class="line"> <span class="attr">active :</span> <span class="string">dev</span></span><br><span class="line"> <span class="comment">#引入其他配置文件,例如ftpHX 未配置文件application-ftpHX.yml</span></span><br><span class="line"> <span class="comment">#include: ftpHX,ftpCloud</span></span><br><span class="line"> <span class="attr">servlet:</span></span><br><span class="line"> <span class="attr">multipart:</span></span><br><span class="line"> <span class="comment">#设置总上传的数据大小</span></span><br><span class="line"> <span class="attr">max-request-size:</span> <span class="string">100MB</span></span><br><span class="line"> <span class="comment">#单个文件大小</span></span><br><span class="line"> <span class="attr">maxFileSize :</span> <span class="string">30MB</span></span><br><span class="line"> <span class="comment">#xx 报错修改的地方</span></span><br><span class="line"> <span class="attr">max-connections:</span> <span class="number">200000</span></span><br><span class="line"> <span class="attr">max-http-post-size:</span> <span class="number">9000000</span></span><br><span class="line"> <span class="comment">#热部署模块</span></span><br><span class="line"> <span class="attr">devtools:</span></span><br><span class="line"> <span class="attr">restart:</span></span><br><span class="line"> <span class="comment">#热部署开关</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment">#指定热部署的目录</span></span><br><span class="line"> <span class="attr">additional-paths:</span> <span class="string">src/main/java</span></span><br><span class="line"> <span class="comment">#指定目录不更新</span></span><br><span class="line"> <span class="attr">exclude:</span> <span class="string">test/**</span></span><br><span class="line"> <span class="attr">mvc:</span> <span class="comment">#静态文件</span></span><br><span class="line"> <span class="attr">static-path-pattern :</span> <span class="string">/static/**</span></span><br><span class="line"> <span class="attr">pathmatch:</span></span><br><span class="line"> <span class="attr">matching-strategy:</span> <span class="string">ant_path_matcher</span></span><br><span class="line"> <span class="comment">#模板引擎</span></span><br><span class="line"> <span class="attr">thymeleaf:</span></span><br><span class="line"> <span class="attr">model:</span> <span class="string">HTML5</span></span><br><span class="line"> <span class="attr">prefix:</span> <span class="string">classpath:/templates/</span></span><br><span class="line"> <span class="attr">suffix:</span> <span class="string">.html</span></span><br><span class="line"> <span class="comment">#指定编码</span></span><br><span class="line"> <span class="attr">encoding:</span> <span class="string">utf-8</span></span><br><span class="line"> <span class="comment">#禁用缓存 默认false</span></span><br><span class="line"> <span class="attr">cache:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">jackson:</span></span><br><span class="line"> <span class="attr">time-zone:</span> <span class="string">GMT+8</span></span><br><span class="line"> <span class="attr">date-format:</span> <span class="string">yyyy-MM-dd</span> <span class="string">HH:mm:ss</span></span><br><span class="line"> <span class="attr">redis:</span></span><br><span class="line"> <span class="attr">ssl:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">database:</span> <span class="number">0</span></span><br><span class="line"> <span class="attr">host:</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">6379</span></span><br><span class="line"> <span class="attr">password:</span> </span><br><span class="line"> <span class="attr">timeout:</span> <span class="number">1000</span></span><br><span class="line"> <span class="attr">lettuce:</span></span><br><span class="line"> <span class="attr">pool:</span></span><br><span class="line"> <span class="attr">max-active:</span> <span class="number">200</span></span><br><span class="line"> <span class="attr">max-wait:</span> <span class="number">-1</span></span><br><span class="line"> <span class="attr">max-idle:</span> <span class="number">10</span></span><br><span class="line"> <span class="attr">min-idle:</span> <span class="number">0</span></span><br><span class="line"><span class="comment">#mybatis:</span></span><br><span class="line"><span class="comment"># #配置mapper的扫描,找到所有的mapper.xml映射文件</span></span><br><span class="line"><span class="comment"># mapperLocations : classpath*:mybatis/*/*.xml</span></span><br><span class="line"><span class="comment"># #mybatis提供三种sql执行器,分别是SIMPLE、REUSE、BATCH。</span></span><br><span class="line"><span class="comment"># executor-type : reuse</span></span><br><span class="line"><span class="comment"># #搜索指定包别名</span></span><br><span class="line"><span class="comment"># typeAliasesPackage : com.*.model</span></span><br><span class="line"><span class="comment"># #该配置项就是指将带有下划线的表字段映射为驼峰格式的实体类属性。</span></span><br><span class="line"><span class="comment"># configuration :</span></span><br><span class="line"><span class="comment"># map-underscore-to-camel-case : true</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 控制台输出sql、下划线转驼峰</span></span><br><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line"> <span class="attr">mapper-locations:</span> <span class="string">classpath:/mybatis-plus/*.xml</span></span><br><span class="line"> <span class="attr">typeAliasesPackage:</span> <span class="string">com.fc.pilotSchool.model</span></span><br><span class="line"> <span class="comment"># 控制台输出sql、下划线转驼峰</span></span><br><span class="line"> <span class="attr">configuration:</span></span><br><span class="line"> <span class="attr">log-impl:</span> <span class="string">org.apache.ibatis.logging.stdout.StdOutImpl</span></span><br><span class="line"> <span class="attr">map-underscore-to-camel-case:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#pagehelper分页插件</span></span><br><span class="line"><span class="attr">pagehelper:</span></span><br><span class="line"> <span class="attr">helperDialect:</span> <span class="string">mysql</span></span><br><span class="line"> <span class="attr">reasonable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">supportMethodsArguments:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">params:</span> <span class="string">count=countSql</span></span><br><span class="line"><span class="attr">oss:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">info:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">path-style-access:</span> <span class="literal">false</span> <span class="comment">#使用云OSS 需要关闭</span></span><br><span class="line"> <span class="attr">endpoint:</span> <span class="string">http://127.0.0.1:9000</span> <span class="comment">#对应上图 ③ 处配置</span></span><br><span class="line"> <span class="attr">access-key:</span> <span class="string">minioadmin</span> <span class="comment"># 上文创建的AK</span></span><br><span class="line"> <span class="attr">secret-key:</span> <span class="string">minioadmin</span> <span class="comment"># 上文创建的SK</span></span><br><span class="line"> <span class="attr">bucket-name:</span> <span class="string">v2-cloud</span> <span class="comment"># 上文创建的桶名称</span></span><br></pre></td></tr></table></figure><p>application-dev.yml文件</p><figure class="highlight yml"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#dev环境 mysql7.0</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">datasource:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">com.alibaba.druid.pool.DruidDataSource</span></span><br><span class="line"> <span class="attr">driverClassName:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line"> <span class="comment">#druid连接池配置</span></span><br><span class="line"> <span class="attr">druid:</span></span><br><span class="line"> <span class="comment">#主库数据源</span></span><br><span class="line"> <span class="attr">master:</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">xxxxx</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">xxxxx</span></span><br><span class="line"> <span class="comment">#备数据源 #关闭</span></span><br><span class="line"> <span class="attr">slave:</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">xxxx</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">xxxx</span></span><br><span class="line"> <span class="comment">#配置初始化连接数大小</span></span><br><span class="line"> <span class="attr">initial-size:</span> <span class="number">10</span></span><br><span class="line"> <span class="comment"># 最大连接数</span></span><br><span class="line"> <span class="attr">maxActive:</span> <span class="number">50</span></span><br><span class="line"> <span class="comment">#最小连接数</span></span><br><span class="line"> <span class="attr">minIdle:</span> <span class="number">10</span></span><br><span class="line"> <span class="comment">#获取连接等待超时时间</span></span><br><span class="line"> <span class="attr">maxWait:</span> <span class="number">5000</span></span><br><span class="line"> <span class="attr">poolPreparedStatements:</span> <span class="literal">true</span> <span class="comment">#是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。</span></span><br><span class="line"> <span class="attr">maxPoolPreparedStatementPerConnection-size:</span> <span class="number">20</span></span><br><span class="line"> <span class="attr">validationQuery:</span> <span class="string">SELECT</span> <span class="number">1</span> <span class="string">FROM</span> <span class="string">DUAL</span></span><br><span class="line"> <span class="attr">validationQueryTimeout:</span> <span class="number">20000</span></span><br><span class="line"> <span class="attr">testOnBorrow:</span> <span class="literal">false</span> <span class="comment">#申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。</span></span><br><span class="line"> <span class="attr">testOnReturn:</span> <span class="literal">false</span> <span class="comment">#归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。</span></span><br><span class="line"> <span class="attr">testWhileIdle:</span> <span class="literal">true</span> <span class="comment">#建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。</span></span><br><span class="line"> <span class="attr">timeBetweenEvictionRunsMillis:</span> <span class="number">60000</span> <span class="comment">#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒</span></span><br><span class="line"> <span class="attr">minEvictableIdleTimeMillis:</span> <span class="number">300000</span> <span class="comment">#一个连接在池中最小生存的时间,单位是毫秒</span></span><br><span class="line"> <span class="attr">maxEvictableIdleTimeMillis:</span> <span class="number">900000</span> <span class="comment"># 配置一个连接在池中最大生存的时间,单位是毫秒</span></span><br><span class="line"> <span class="comment">#StatViewServlet配置。(因为暴露的监控信息比较敏感,支持密码加密和访问ip限定)</span></span><br><span class="line"> <span class="attr">webStatFilter:</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">statViewServlet:</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">urlPattern:</span> <span class="string">/druid/*</span></span><br><span class="line"> <span class="comment">#可以增加访问账号密码【去掉注释就可以】</span></span><br><span class="line"> <span class="comment">#login-username: admin</span></span><br><span class="line"> <span class="comment">#login-password: admin</span></span><br><span class="line"> <span class="attr">filter:</span></span><br><span class="line"> <span class="attr">stat:</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># 慢SQL记录</span></span><br><span class="line"> <span class="attr">log-slow-sql:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">slow-sql-millis:</span> <span class="number">1000</span></span><br><span class="line"> <span class="attr">merge-sql:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">wall:</span></span><br><span class="line"> <span class="attr">config:</span></span><br><span class="line"> <span class="attr">multi-statement-allow:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#mysql 8.0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#spring:</span></span><br><span class="line"><span class="comment"># datasource:</span></span><br><span class="line"><span class="comment"># type: com.alibaba.druid.pool.DruidDataSource</span></span><br><span class="line"><span class="comment"># driverClassName: com.mysql.cj.jdbc.Driver</span></span><br><span class="line"><span class="comment"># #druid连接池配置</span></span><br><span class="line"><span class="comment"># druid:</span></span><br><span class="line"><span class="comment"># # 主库数据源</span></span><br><span class="line"><span class="comment"># master:</span></span><br><span class="line"><span class="comment"># url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false</span></span><br><span class="line"><span class="comment"># username: root</span></span><br><span class="line"><span class="comment"># password: root</span></span><br><span class="line"><span class="comment"># #树熊数据源</span></span><br><span class="line"><span class="comment"># slave:</span></span><br><span class="line"><span class="comment"># enabled : false</span></span><br><span class="line"><span class="comment"># url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false</span></span><br><span class="line"><span class="comment"># username: root</span></span><br><span class="line"><span class="comment"># password: root</span></span><br><span class="line"><span class="comment"># #配置初始化连接数大小</span></span><br><span class="line"><span class="comment"># initial-size: 10</span></span><br><span class="line"><span class="comment"># # 最大连接数</span></span><br><span class="line"><span class="comment"># max-active: 50</span></span><br><span class="line"><span class="comment"># #最小连接数</span></span><br><span class="line"><span class="comment"># min-idle: 10</span></span><br><span class="line"><span class="comment"># #获取连接等待超时时间</span></span><br><span class="line"><span class="comment"># max-wait: 5000</span></span><br><span class="line"><span class="comment"># pool-prepared-statements: true #是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。</span></span><br><span class="line"><span class="comment"># max-pool-prepared-statement-per-connection-size: 20</span></span><br><span class="line"><span class="comment"># validation-query: SELECT 1 FROM DUAL</span></span><br><span class="line"><span class="comment"># validation-query-timeout: 20000</span></span><br><span class="line"><span class="comment"># test-on-borrow: false #申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。</span></span><br><span class="line"><span class="comment"># test-on-return: false #归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。</span></span><br><span class="line"><span class="comment"># test-while-idle: true #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。</span></span><br><span class="line"><span class="comment"># time-between-eviction-runs-millis: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒</span></span><br><span class="line"><span class="comment"># min-evictable-idle-time-millis: 300000 #一个连接在池中最小生存的时间,单位是毫秒</span></span><br><span class="line"><span class="comment"># #StatViewServlet配置。(因为暴露的监控信息比较敏感,支持密码加密和访问ip限定)</span></span><br><span class="line"><span class="comment"># stat-view-servlet:</span></span><br><span class="line"><span class="comment"># enabled: true</span></span><br><span class="line"><span class="comment"># url-pattern: /druid/*</span></span><br><span class="line"><span class="comment"># #可以增加访问账号密码【去掉注释就可以】</span></span><br><span class="line"><span class="comment"># #login-username: admin</span></span><br><span class="line"><span class="comment"># #login-password: admin</span></span><br><span class="line"><span class="comment"># filter:</span></span><br><span class="line"><span class="comment"># stat:</span></span><br><span class="line"><span class="comment"># log-slow-sql: true</span></span><br><span class="line"><span class="comment"># slow-sql-millis: 1000</span></span><br><span class="line"><span class="comment"># merge-sql: true</span></span><br><span class="line"><span class="comment"># wall:</span></span><br><span class="line"><span class="comment"># config:</span></span><br><span class="line"><span class="comment"># multi-statement-allow: true</span></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> YML </tag>
</tags>
</entry>
<entry>
<title>Doris记录</title>
<link href="/2024/04/24/Doris%E8%AE%B0%E5%BD%95/"/>
<url>/2024/04/24/Doris%E8%AE%B0%E5%BD%95/</url>
<content type="html"><![CDATA[<h3 id="部署doris-遇到的问题"><a href="#部署doris-遇到的问题" class="headerlink" title="部署doris 遇到的问题"></a>部署doris 遇到的问题</h3><h4 id="部署fe报错:"><a href="#部署fe报错:" class="headerlink" title="部署fe报错:"></a>部署fe报错:</h4><blockquote><p>ip address range configured for priority_networks does not include the current IP address</p></blockquote><p>解决:报错信息为,设置的网段没有包含当前网络。需要在fe的conf下设置priority_networks网段<br>(需要设置本机的ip地址而不是服务器的公网ip地址)<br>使用命令查看ip掩码地址<br>ip addr show eth0 | grep inet | awk ‘{print $2}’ | awk -F’/‘ ‘{print $1}’</p><h4 id="启动be时报错:"><a href="#启动be时报错:" class="headerlink" title="启动be时报错:"></a>启动be时报错:</h4><blockquote><p>Please disable swap memory before installation</p></blockquote><p>Linux系统发现又swap分区正在使用,需要进行关闭<br>使用指令</p><ul><li>输入命令 “sudo /bin/bash” 进入管理员权限的shell。</li><li>输入命令 “sudo swapoff -a” 禁用所有交换分区。</li></ul><blockquote><p>The JAVA_HOME environment variable is not defined correctly </p></blockquote><p>需要设置JAVA_HOME</p><h4 id="启动fe出错:"><a href="#启动fe出错:" class="headerlink" title="启动fe出错:"></a>启动fe出错:</h4><blockquote><p>wait catalog to be ready. FE type: UNKNOWN. is ready: false, counter: 658341</p></blockquote><p>需要查看是否有虚拟ip地址,有则重新设置。</p>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> Doris </tag>
</tags>
</entry>
<entry>
<title>服务器巡检</title>
<link href="/2024/04/24/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%B7%A1%E6%A3%80/"/>
<url>/2024/04/24/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%B7%A1%E6%A3%80/</url>
<content type="html"><![CDATA[<h3 id="巡检命令"><a href="#巡检命令" class="headerlink" title="巡检命令"></a>巡检命令</h3><figure class="highlight bash"><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">top</span><br><span class="line"><span class="comment"># 查看cpu的空闲时间以及IO等待完成时间</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><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">free -h</span><br><span class="line"><span class="comment"># 查看avaliable的使用情况</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><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="built_in">df</span> -h</span><br><span class="line"><span class="comment"># 查看磁盘空间占用情况</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">getenforce</span><br><span class="line"><span class="comment"># 使用getenforce命令可以在Linux下查看是否开启了SELinux</span></span><br><span class="line"><span class="comment"># 如果为disable则有风险</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><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">systemctl status firewalld</span><br><span class="line"><span class="comment"># 查看防火墙是否开启</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><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">crontab -l</span><br><span class="line"><span class="comment"># 查看有没有未知的定时任务</span></span><br></pre></td></tr></table></figure><h3 id="数据库巡检"><a href="#数据库巡检" class="headerlink" title="数据库巡检"></a>数据库巡检</h3><hr><figure class="highlight sql"><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="keyword">select</span> instance_name,host_name,startup_time,status,database_status <span class="keyword">from</span> v$instance;</span><br><span class="line"><span class="comment">-- 查看Oracl实例的状态</span></span><br></pre></td></tr></table></figure><hr><figure class="highlight sql"><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="keyword">select</span> <span class="keyword">group</span>#,status,type,<span class="keyword">member</span> <span class="keyword">from</span> v$logfile; </span><br><span class="line"><span class="comment">-- 检查Oracle在线日志状态</span></span><br></pre></td></tr></table></figure><blockquote><p>在Oracle数据库中,<code>v$logfile</code>是一个动态性能视图,它提供了关于在线重做日志文件的信息。这些日志文件是Oracle用于记录所有数据库更改(如插入、更新和删除操作)的物理文件。这些更改随后可用于恢复操作,例如实例恢复或介质恢复。<br>从v$logfile视图中检索以下列的信息:</p><ol><li><strong>group#</strong> - 这是重做日志组的编号。在Oracle中,你可以有多个在线重做日志组,每个组可以有一个或多个成员(即物理文件)。</li></ol><ul><li><code>group#</code>列表示日志组的编号。</li></ul><ol start="2"><li><strong>status</strong> - 这列显示了重做日志的状态。可能的值包括:</li></ol><ul><li><p><code>CURRENT</code> - 表示该日志文件是当前正在写入的日志文件。</p></li><li><p><code>ACTIVE</code> - 表示该日志文件包含尚未被归档的更改。</p></li><li><p><code>INACTIVE</code> - 表示该日志文件不再用于写入,但可能包含尚未被覆盖的更改。</p></li><li><p><code>UNUSED</code> - 表示该日志文件尚未使用。</p></li></ul><ol start="3"><li><p><strong>type</strong> - 这列描述了重做日志文件的类型。对于在线重做日志文件,它通常显示为<code>ONLINE</code>。</p></li><li><p><strong>member</strong> - 这列显示了重做日志文件的完整路径和名称。每个日志组可以有多个成员,这意味着该组的日志数据被写入多个物理文件中。这提供了冗余和容错能力,因为如果一个物理文件损坏,其他文件仍然可用。</p></li></ol><p>通过查询<code>v$logfile</code>视图,数据库管理员可以了解当前哪些日志文件正在使用,哪些处于空闲状态,以及这些日志文件的物理位置。这对于诊断问题、规划磁盘空间以及进行恢复操作都非常重要。</p></blockquote><hr><figure class="highlight sql"><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="keyword">select</span> tablespace_name,status <span class="keyword">from</span> dba_tablespaces; </span><br><span class="line"><span class="comment">-- 检查Oracle表空间的状态</span></span><br></pre></td></tr></table></figure><hr><figure class="highlight sql"><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="keyword">select</span> name,status <span class="keyword">from</span> v$datafile;</span><br><span class="line"><span class="comment">-- 检查Oracle所有数据文件状态</span></span><br></pre></td></tr></table></figure><blockquote><ol><li><p><strong>name</strong> - 这列显示了数据文件的完整路径和名称。它提供了数据文件的物理位置信息。</p></li><li><p><strong>status</strong> - 这列描述了数据文件的状态。可能的状态值包括:</p><ul><li><code>AVAILABLE</code> - 数据文件可用,并且可以被访问。</li><li><code>RECOVER</code> - 数据文件正在恢复中,可能由于介质故障或其他原因。</li><li><code>OFFLINE</code> - 数据文件当前不可用,可能由于管理员手动将其设置为离线状态,或者由于其他原因(如磁盘故障)。</li><li><code>INVALID</code> - 数据文件的状态无效或损坏。</li><li><code>DELETED</code> - 数据文件已被标记为删除,但其空间可能尚未被释放。</li></ul></li></ol><p>通过查询<code>v$datafile</code>视图,数据库管理员可以了解数据库中所有数据文件的状态和位置。这对于诊断问题、管理磁盘空间、备份和恢复操作以及监控数据库的健康状况都至关重要。例如,如果某个数据文件的状态为<code>OFFLINE</code>,那么可能需要进一步调查为什么它不可用,并考虑将其恢复为<code>AVAILABLE</code>状态。同样,如果数据文件的状态为<code>INVALID</code>或<code>RECOVER</code>,则可能需要进行恢复操作以确保数据的完整性和可用性。</p></blockquote><figure class="highlight sql"><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="keyword">select</span> segment_name,status <span class="keyword">from</span> dba_rollback_segs;</span><br><span class="line"><span class="comment">-- 检查所有回滚段状态</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">Upper</span>(F.TABLESPACE_NAME) "表空间名",</span><br><span class="line"> D.TOT_GROOTTE_MB "表空间大小(M)",</span><br><span class="line"> D.TOT_GROOTTE_MB <span class="operator">-</span> F.TOTAL_BYTES "已使用空间(M)",</span><br><span class="line"> To_char(Round(( D.TOT_GROOTTE_MB <span class="operator">-</span> F.TOTAL_BYTES ) <span class="operator">/</span> D.TOT_GROOTTE_MB <span class="operator">*</span> <span class="number">100</span>, <span class="number">2</span>), <span class="string">'990.99'</span>)</span><br><span class="line"> <span class="operator">||</span> <span class="string">'%'</span> "使用比",</span><br><span class="line"> F.TOTAL_BYTES "空闲空间(M)",</span><br><span class="line"> F.MAX_BYTES "最大块(M)"</span><br><span class="line"><span class="keyword">FROM</span> (<span class="keyword">SELECT</span> TABLESPACE_NAME,</span><br><span class="line"> Round(<span class="built_in">Sum</span>(BYTES) <span class="operator">/</span> ( <span class="number">1024</span> <span class="operator">*</span> <span class="number">1024</span> ), <span class="number">2</span>) TOTAL_BYTES,</span><br><span class="line"> Round(<span class="built_in">Max</span>(BYTES) <span class="operator">/</span> ( <span class="number">1024</span> <span class="operator">*</span> <span class="number">1024</span> ), <span class="number">2</span>) MAX_BYTES</span><br><span class="line"> <span class="keyword">FROM</span> SYS.DBA_FREE_SPACE</span><br><span class="line"> <span class="keyword">GROUP</span> <span class="keyword">BY</span> TABLESPACE_NAME) F,</span><br><span class="line"> (<span class="keyword">SELECT</span> DD.TABLESPACE_NAME,</span><br><span class="line"> Round(<span class="built_in">Sum</span>(DD.BYTES) <span class="operator">/</span> ( <span class="number">1024</span> <span class="operator">*</span> <span class="number">1024</span> ), <span class="number">2</span>) TOT_GROOTTE_MB</span><br><span class="line"> <span class="keyword">FROM</span> SYS.DBA_DATA_FILES DD</span><br><span class="line"> <span class="keyword">GROUP</span> <span class="keyword">BY</span> DD.TABLESPACE_NAME) D</span><br><span class="line"><span class="keyword">WHERE</span> D.TABLESPACE_NAME <span class="operator">=</span> F.TABLESPACE_NAME</span><br><span class="line"><span class="keyword">ORDER</span> <span class="keyword">BY</span> <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 检查表空间使用情况</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">SELECT</span> a.VALUE <span class="operator">+</span> b.VALUE logical_reads,</span><br><span class="line"> c.VALUE phys_reads,</span><br><span class="line"> round(<span class="number">100</span> <span class="operator">*</span> (<span class="number">1</span> <span class="operator">-</span> c.value <span class="operator">/</span> (a.value <span class="operator">+</span> b.value)), <span class="number">4</span>) hit_ratio</span><br><span class="line"> <span class="keyword">FROM</span> v$sysstat a, v$sysstat b, v$sysstat c</span><br><span class="line"> <span class="keyword">WHERE</span> a.NAME <span class="operator">=</span> <span class="string">'db block gets'</span></span><br><span class="line"> <span class="keyword">AND</span> b.NAME <span class="operator">=</span> <span class="string">'consistent gets'</span></span><br><span class="line"> <span class="keyword">AND</span> c.NAME <span class="operator">=</span> <span class="string">'physical reads'</span>;</span><br><span class="line"><span class="comment">-- 检查缓冲区命中率</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">select</span> index_name, table_name, tablespace_name, status</span><br><span class="line"> <span class="keyword">From</span> dba_indexes</span><br><span class="line"> <span class="keyword">Where</span> owner <span class="operator">=</span> <span class="string">'CTAIS2'</span></span><br><span class="line"> <span class="keyword">And</span> status <span class="operator"><></span> <span class="string">'VALID'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 检查失效的索引</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">SELECT</span> owner, constraint_name, table_name, constraint_type, status</span><br><span class="line"> <span class="keyword">FROM</span> dba_constraints</span><br><span class="line"> <span class="keyword">WHERE</span> status <span class="operator">=</span> <span class="string">'DISABLE'</span></span><br><span class="line"><span class="keyword">and</span> constraint_type <span class="operator">=</span> <span class="string">'P'</span>;</span><br><span class="line"><span class="comment">-- 检查不起作用的约束</span></span><br></pre></td></tr></table></figure><p><em>下面的命令需要在sqlplus上执行</em> </p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">su - oracle</span><br><span class="line">sqlplus /nolog</span><br><span class="line">conn sys/ as sysdba;</span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">show</span> <span class="keyword">parameter</span> process; </span><br><span class="line"><span class="comment">-- 查看db_write_process数设定值</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">show</span> <span class="keyword">parameter</span> sessions; </span><br><span class="line"><span class="comment">-- 查看session数设定值</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">select</span> <span class="built_in">count</span>(<span class="operator">*</span>) <span class="keyword">from</span> v$session;</span><br><span class="line"><span class="comment">-- 查看session数实际值</span></span><br></pre></td></tr></table></figure><figure class="highlight sql"><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="keyword">select</span> <span class="built_in">sum</span>(percent_space_used) <span class="keyword">from</span> v$flash_recovery_area_usage;</span><br><span class="line"><span class="comment">-- 查看归档日志占比</span></span><br></pre></td></tr></table></figure><hr><h3 id="扩展表空间"><a href="#扩展表空间" class="headerlink" title="扩展表空间"></a>扩展表空间</h3><p>查看表空间使用百分比</p><figure class="highlight sql"><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span></span><br><span class="line"> b.file_id 文件ID号,</span><br><span class="line"> b.tablespace_name 表空间名,</span><br><span class="line"> b.bytes <span class="operator">/</span> <span class="number">1024</span> <span class="operator">/</span> <span class="number">1024</span> <span class="operator">||</span> <span class="string">'M'</span> 字节数,</span><br><span class="line"> (</span><br><span class="line"> b.bytes <span class="operator">-</span> <span class="built_in">sum</span>(nvl(a.bytes, <span class="number">0</span>))</span><br><span class="line"> ) <span class="operator">/</span> <span class="number">1024</span> <span class="operator">/</span> <span class="number">1024</span> <span class="operator">||</span> <span class="string">'M'</span> 已使用,</span><br><span class="line"> <span class="built_in">sum</span>(nvl(a.bytes, <span class="number">0</span>)) <span class="operator">/</span> <span class="number">1024</span> <span class="operator">/</span> <span class="number">1024</span> <span class="operator">||</span> <span class="string">'M'</span> 剩余空间,</span><br><span class="line"> <span class="number">100</span> <span class="operator">-</span> <span class="built_in">sum</span>(nvl(a.bytes, <span class="number">0</span>)) <span class="operator">/</span> (b.bytes) <span class="operator">*</span> <span class="number">100</span> 占用百分比</span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line"> dba_free_space a,</span><br><span class="line"> dba_data_files b</span><br><span class="line"><span class="keyword">WHERE</span></span><br><span class="line"> a.file_id <span class="operator">=</span> b.file_id</span><br><span class="line"><span class="keyword">GROUP</span> <span class="keyword">BY</span></span><br><span class="line"> b.tablespace_name,</span><br><span class="line"> b.file_id,</span><br><span class="line"> b.bytes</span><br><span class="line"><span class="keyword">ORDER</span> <span class="keyword">BY</span></span><br><span class="line"> b.file_id;</span><br></pre></td></tr></table></figure><p>查看表空间路径</p><figure class="highlight sql"><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="keyword">SELECT</span></span><br><span class="line"> tablespace_name,</span><br><span class="line"> file_id,</span><br><span class="line"> file_name,</span><br><span class="line"> round(bytes <span class="operator">/</span>(<span class="number">1024</span> <span class="operator">*</span> <span class="number">1024</span>), <span class="number">0</span>) total_space</span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line"> dba_data_files</span><br><span class="line"><span class="keyword">ORDER</span> <span class="keyword">BY</span></span><br><span class="line"> tablespace_name;</span><br></pre></td></tr></table></figure><p>扩展表空间</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span>SPACE USERS <span class="keyword">ADD</span> DATAFILE <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS04.DBF'</span> SIZE <span class="number">10000</span>M;</span><br></pre></td></tr></table></figure><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> DATABASE DATAFILE <span class="string">'+DATA/jhszws/datafile/phistablespace2017.ora'</span> RESIZE <span class="number">10</span>G;</span><br></pre></td></tr></table></figure><p>设置自动扩展</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> database datafile <span class="string">'/erp/TEST/db/data/cux_arch_03.dbf'</span> autoextend <span class="keyword">on</span> next <span class="number">1000</span>M maxsize <span class="number">16000</span>M;</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> Linux </tag>
</tags>
</entry>
<entry>
<title>Map的四种遍历方式</title>
<link href="/2024/04/24/map%E7%9A%84%E5%9B%9B%E7%A7%8D%E9%81%8D%E5%8E%86%E6%96%B9%E5%BC%8F/"/>
<url>/2024/04/24/map%E7%9A%84%E5%9B%9B%E7%A7%8D%E9%81%8D%E5%8E%86%E6%96%B9%E5%BC%8F/</url>
<content type="html"><![CDATA[<h2 id="Entry"><a href="#Entry" class="headerlink" title="Entry"></a>Entry</h2><p>由于Map中存放的元素均为键值对,故每一个键值对必然存在一个映射关系。<br>Map中采用Entry内部类来表示一个映射项,映射项包含Key和Value (我们总说键值对键值对, 每一个键值对也就是一个Entry)<br>Map.Entry里面包含getKey()和getValue()方法</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></pre></td><td class="code"><pre><span class="line">Iterator<Map.Entry<Integer, Integer>> it=map.entrySet().iterator();</span><br><span class="line"> <span class="keyword">while</span>(it.hasNext()) {</span><br><span class="line"> Map.Entry<Integer,Integer> entry=it.next();</span><br><span class="line"> <span class="type">int</span> key=entry.getKey();</span><br><span class="line"> <span class="type">int</span> value=entry.getValue();</span><br><span class="line"> System.out.println(key+<span class="string">" "</span>+value);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h2 id="entrySet"><a href="#entrySet" class="headerlink" title="entrySet"></a>entrySet</h2><p>entrySet是 java中 键-值 对的集合,Set里面的类型是Map.Entry,一般可以通过map.entrySet()得到。</p><p>entrySet实现了Set接口,里面存放的是键值对。一个K对应一个V。<br>用来遍历map的一种方法. </p><p>即通过getKey()得到K,getValue得到V。</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></pre></td><td class="code"><pre><span class="line">Set<Map.Entry<String, String>> entryseSet=map.entrySet();</span><br><span class="line"> </span><br><span class="line"><span class="keyword">for</span> (Map.Entry<String, String> entry:entryseSet) {</span><br><span class="line"> </span><br><span class="line"> System.out.println(entry.getKey()+<span class="string">","</span>+entry.getValue());</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="keySet"><a href="#keySet" class="headerlink" title="keySet"></a>keySet</h2><p>还有一种是keySet, keySet是键的集合,Set里面的类型即key的类型</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></pre></td><td class="code"><pre><span class="line">Set<String> set = map.keySet();</span><br><span class="line"> </span><br><span class="line"><span class="keyword">for</span> (String s:set) {</span><br><span class="line"> </span><br><span class="line"> System.out.println(s+<span class="string">","</span>+map.get(s));</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="value"><a href="#value" class="headerlink" title="value"></a>value</h2><p>通过使用map的value方法进行遍历<br><em>$\color{red}{不能遍历key}$</em></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></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (String v : map.values()) {</span><br><span class="line"> <span class="type">String</span> <span class="variable">value</span> <span class="operator">=</span> v;</span><br><span class="line"> System.out.println(value);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>四种遍历Map方式:</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><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></pre></td><td class="code"><pre><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><br><span class="line"> Map<String, String> map = <span class="keyword">new</span> <span class="title class_">HashMap</span><String, String>();</span><br><span class="line"> map.put(<span class="string">"1"</span>, <span class="string">"value1"</span>);</span><br><span class="line"> map.put(<span class="string">"2"</span>, <span class="string">"value2"</span>);</span><br><span class="line"> map.put(<span class="string">"3"</span>, <span class="string">"value3"</span>);</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//第一种:普遍使用,二次取值</span></span><br><span class="line"> System.out.println(<span class="string">"通过Map.keySet遍历key和value:"</span>);</span><br><span class="line"> <span class="keyword">for</span> (String key : map.keySet()) {</span><br><span class="line"> System.out.println(<span class="string">"key= "</span>+ key + <span class="string">" and value= "</span> + map.get(key));</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//第二种</span></span><br><span class="line"> System.out.println(<span class="string">"通过Map.entrySet使用iterator遍历key和value:"</span>);</span><br><span class="line"> Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();</span><br><span class="line"> <span class="keyword">while</span> (it.hasNext()) {</span><br><span class="line"> Map.Entry<String, String> entry = it.next();</span><br><span class="line"> System.out.println(<span class="string">"key= "</span> + entry.getKey() + <span class="string">" and value= "</span> + entry.getValue());</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//第三种:推荐,尤其是容量大时</span></span><br><span class="line"> System.out.println(<span class="string">"通过Map.entrySet遍历key和value"</span>);</span><br><span class="line"> <span class="keyword">for</span> (Map.Entry<String, String> entry : map.entrySet()) {</span><br><span class="line"> System.out.println(<span class="string">"key= "</span> + entry.getKey() + <span class="string">" and value= "</span> + entry.getValue());</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//第四种</span></span><br><span class="line"> System.out.println(<span class="string">"通过Map.values()遍历所有的value,但不能遍历key"</span>);</span><br><span class="line"> <span class="keyword">for</span> (String v : map.values()) {</span><br><span class="line"> System.out.println(<span class="string">"value= "</span> + v);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>G2图使用-创建简单的柱状图</title>
<link href="/2024/04/23/G2%E5%9B%BE%E4%BD%BF%E7%94%A8-%E5%88%9B%E5%BB%BA%E7%AE%80%E5%8D%95%E7%9A%84%E6%9F%B1%E7%8A%B6%E5%9B%BE/"/>
<url>/2024/04/23/G2%E5%9B%BE%E4%BD%BF%E7%94%A8-%E5%88%9B%E5%BB%BA%E7%AE%80%E5%8D%95%E7%9A%84%E6%9F%B1%E7%8A%B6%E5%9B%BE/</url>
<content type="html"><![CDATA[<blockquote><p>g2plot 是一套简单、易用、并具备一定扩展能力和组合能力的统计图表库,基于图形语法理论搭建而成,”g2plot”中的 g2 即意指图形语法 (the Gramma of Graphics),同时也致敬了 ggplot2。</p></blockquote><p>下面是一个简单的是用例子</p><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><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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">template</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">ref</span>=<span class="string">"chartRef"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">template</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">setup</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">import</span> { onMounted, ref, defineProps, toRefs } <span class="keyword">from</span> <span class="string">'vue'</span>;</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">import</span> { <span class="title class_">Chart</span> } <span class="keyword">from</span> <span class="string">'@antv/g2'</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> props = <span class="title function_">defineProps</span>({ <span class="attr">config</span>: <span class="title class_">Object</span> })</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> { config } = <span class="title function_">toRefs</span>(props)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> chartRef = <span class="title function_">ref</span>();</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> <span class="title function_">initChart</span> = (<span class="params"></span>) => {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">const</span> chart = <span class="keyword">new</span> <span class="title class_">Chart</span>({</span></span><br><span class="line"><span class="language-javascript"> ...config.<span class="property">value</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">container</span>: chartRef.<span class="property">value</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">autoFit</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">forceFit</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> })</span></span><br><span class="line"><span class="language-javascript"> chart</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// .theme({ type: 'classicDark' })</span></span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">title</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">title</span>: <span class="string">`月<span class="subst">${<span class="variable language_">window</span>.CONFIG.systemName}</span>分析`</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// subtitle: 'world',</span></span></span><br><span class="line"><span class="language-javascript"> })</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">interval</span>()</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">data</span>({</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="string">'fetch'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">value</span>: <span class="string">'/api/hdfs/read-csv?path=/output/hdfsJobByMonth/part-r-00000'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">format</span>: <span class="string">'csv'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 如果是csv文件,则自动判断数据类型</span></span></span><br><span class="line"><span class="language-javascript"> <span class="attr">autoType</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">transform</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">// type: 'log'</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">type</span>: <span class="string">'map'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">callback</span>: <span class="function">(<span class="params">val</span>) =></span> { val[<span class="string">'年月'</span>] = val[<span class="string">'时间'</span>] + <span class="string">'月'</span>; <span class="keyword">return</span> val; },</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">type</span>: <span class="string">'sortBy'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">fields</span>: [<span class="string">'时间'</span>], <span class="comment">// 根据 sold 字段排序</span></span></span><br><span class="line"><span class="language-javascript"> },</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// fold 这是生成一个key value 的map</span></span></span><br><span class="line"><span class="language-javascript"> {</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">type</span>: <span class="string">'fold'</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">fields</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">dataHeader</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">key</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartX</span>,</span></span><br><span class="line"><span class="language-javascript"> <span class="attr">value</span>: <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartY</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_">encode</span>(<span class="string">'x'</span>, <span class="string">'年月'</span>)</span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">encode</span>(<span class="string">'y'</span>, <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartY</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// dodgeX 生成 series 通道值为 color 通道的值,根据 series 通道实现分组效果</span></span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">transform</span>({ <span class="attr">type</span>: <span class="string">'dodgeX'</span> })</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 根据 window.CONFIG.chartX 颜色进行区分,如果不加,则显示全部数据颜色固定</span></span></span><br><span class="line"><span class="language-javascript"> .<span class="title function_">encode</span>(<span class="string">'color'</span>, <span class="variable language_">window</span>.<span class="property">CONFIG</span>.<span class="property">chartX</span>)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// .encode('shape', 'hv')</span></span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// .scale('x', {</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// range: [0, 1],</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">// .scale('y', {</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// nice: true,</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">// .axis('x', { title: null, line: true, tick: true })</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// .axis('y', { </span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// title: null, </span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// line: true, </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="comment">// chart.line()</span></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// // chart.line().encode('shape', 'smooth');</span></span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// chart.point().encode('shape', 'point').tooltip(false);</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"> chart.<span class="title function_">render</span>();</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> chart;</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_">onMounted</span>(<span class="function">() =></span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">console</span>.<span class="title function_">log</span>(chartRef.<span class="property">value</span>)</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">initChart</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 class="tag"></<span class="name">script</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">lang</span>=<span class="string">"scss"</span> <span class="attr">scoped</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">style</span>></span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p>其中需要注意的是: <em>.encode(‘color’, window.CONFIG.chartX)</em> 用来实现的是图例,图例的内容为 window.CONFIG.chartX ,其中color 可以进行变化</p><p>因为 <em>prop</em> 接受了主题的配置,所有的颜色都会根据主题的index.js进行变化</p><hr><p>另外 <em>fetch</em> 通过拉取 hdfs 中算好的 csv 文件来获得值,里面的 <em>transform</em> 对值进行转换,其中 <em>type fold</em> 能生成一个 <em>key value</em> 的map</p>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> G2 </tag>
<tag> Vue </tag>
</tags>
</entry>
<entry>
<title>获取汉字拼音首字母</title>
<link href="/2024/04/23/%E8%8E%B7%E5%8F%96%E6%B1%89%E5%AD%97%E6%8B%BC%E9%9F%B3%E9%A6%96%E5%AD%97%E6%AF%8D/"/>
<url>/2024/04/23/%E8%8E%B7%E5%8F%96%E6%B1%89%E5%AD%97%E6%8B%BC%E9%9F%B3%E9%A6%96%E5%AD%97%E6%AF%8D/</url>
<content type="html"><![CDATA[<blockquote><p>添加所需的依赖</p></blockquote><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.belerweb<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>pinyin4j<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.5.1<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><p>创建一个方法来,转换拼音</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">getPinYinHeadChar</span><span class="params">(String str)</span> {</span><br><span class="line"> <span class="keyword">if</span> (isNull(str)) {</span><br><span class="line"> <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="type">String</span> <span class="variable">convert</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">0</span>; j < str.length(); j++) {</span><br><span class="line"> <span class="type">char</span> <span class="variable">word</span> <span class="operator">=</span> str.charAt(j);</span><br><span class="line"> <span class="comment">// 提取汉字的首字母</span></span><br><span class="line"> String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);</span><br><span class="line"> <span class="keyword">if</span> (pinyinArray != <span class="literal">null</span>) {</span><br><span class="line"> convert += pinyinArray[<span class="number">0</span>].charAt(<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> convert += word;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> convert = string2AllTrim(convert);</span><br><span class="line"> <span class="keyword">return</span> convert.toLowerCase();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><em>其中PinyinHelper的方法能将汉字字符串转换成首字母拼音的字符串数组</em></p><p>main方法</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><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></pre></td><td class="code"><pre><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><br><span class="line"> <span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"> <span class="type">String</span> <span class="variable">s</span> <span class="operator">=</span> PingYinUtil.getPinYinHeadChar(<span class="string">"支付宝"</span>);</span><br><span class="line"> System.out.println(s);</span><br><span class="line"></span><br><span class="line"> List<String> str = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> List<String> pin = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> List<String> level = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="type">String</span> <span class="variable">fileName</span> <span class="operator">=</span> <span class="string">"D:\\bin\\桌面\\h_fever_outpatient_org_info.xlsx"</span>;</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="comment">//创建工作簿对象</span></span><br><span class="line"> <span class="type">XSSFWorkbook</span> <span class="variable">xssfWorkbook</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">new</span> <span class="title class_">XSSFWorkbook</span>(<span class="keyword">new</span> <span class="title class_">FileInputStream</span>(fileName));</span><br><span class="line"> <span class="comment">//获取工作簿下sheet的个数</span></span><br><span class="line"> <span class="type">int</span> <span class="variable">sheetNum</span> <span class="operator">=</span> xssfWorkbook.getNumberOfSheets();</span><br><span class="line"> System.out.println(<span class="string">"该excel文件中总共有:"</span>+sheetNum+<span class="string">"个sheet"</span>);</span><br><span class="line"> <span class="comment">//遍历工作簿中的所有数据</span></span><br><span class="line"> List<Grade> grades = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>;i<sheetNum;i++) {</span><br><span class="line"> <span class="comment">//读取第i个工作表</span></span><br><span class="line"> System.out.println(<span class="string">"读取第"</span>+(i+<span class="number">1</span>)+<span class="string">"个sheet"</span>);</span><br><span class="line"> <span class="type">XSSFSheet</span> <span class="variable">sheet</span> <span class="operator">=</span> xssfWorkbook.getSheetAt(i);</span><br><span class="line"> <span class="comment">//获取最后一行的num,即总行数。此处从0开始</span></span><br><span class="line"> <span class="type">int</span> <span class="variable">maxRow</span> <span class="operator">=</span> sheet.getLastRowNum();</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">row</span> <span class="operator">=</span> <span class="number">0</span>; row <= maxRow; row++) {</span><br><span class="line"> <span class="comment">//获取最后单元格num,即总单元格数 ***注意:此处从1开始计数***</span></span><br><span class="line"> <span class="type">int</span> <span class="variable">maxRol</span> <span class="operator">=</span> sheet.getRow(row).getLastCellNum();</span><br><span class="line"> <span class="comment">// System.out.println("--------第" + row + "行的数据如下--------");</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">a</span> <span class="operator">=</span> sheet.getRow(row).getCell(<span class="number">0</span>).toString();</span><br><span class="line"> str.add(a);</span><br><span class="line"> pin.add(PingYinUtil.getPinYinHeadChar(a));</span><br><span class="line"> level.add(sheet.getRow(row).getCell(<span class="number">2</span>).toString());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span> (<span class="comment">//创建工作薄对象</span></span><br><span class="line"> <span class="type">SXSSFWorkbook</span> <span class="variable">workbook</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SXSSFWorkbook</span>()) {</span><br><span class="line"> <span class="comment">//创建工作表对象</span></span><br><span class="line"> <span class="type">SXSSFSheet</span> <span class="variable">sheet</span> <span class="operator">=</span> workbook.createSheet();</span><br><span class="line"> <span class="comment">//创建工作表的行</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<str.size();i++){</span><br><span class="line"> <span class="type">SXSSFRow</span> <span class="variable">row</span> <span class="operator">=</span> sheet.createRow(i);<span class="comment">//设置第一行,从零开始</span></span><br><span class="line"> row.createCell(<span class="number">0</span>).setCellValue(str.get(i));<span class="comment">//第一行第一列为</span></span><br><span class="line"> row.createCell(<span class="number">1</span>).setCellValue(pin.get(i));<span class="comment">//第一行第二列为日期</span></span><br><span class="line"> row.createCell(<span class="number">2</span>).setCellValue(level.get(i));</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> workbook.setSheetName(<span class="number">0</span>,<span class="string">"sheet"</span>);<span class="comment">//设置sheet的Name</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//文档输出</span></span><br><span class="line"> <span class="type">FileOutputStream</span> <span class="variable">out</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileOutputStream</span>(<span class="string">"D:\\bin\\桌面\\"</span> + <span class="keyword">new</span> <span class="title class_">SimpleDateFormat</span>(<span class="string">"yyyyMMddHHmmss"</span>).format(<span class="keyword">new</span> <span class="title class_">Date</span>()).toString() +<span class="string">".xlsx"</span>);</span><br><span class="line"> workbook.write(out);</span><br><span class="line"> out.close();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>MySQL字节超长</title>
<link href="/2024/04/21/MYSQL%20%20ERROR%201118%20(42000)%20Row%20size%20too%20large/"/>
<url>/2024/04/21/MYSQL%20%20ERROR%201118%20(42000)%20Row%20size%20too%20large/</url>
<content type="html"><![CDATA[<p>报错信息如下:</p><figure class="highlight properties"><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="attr">ERROR</span> <span class="string">1118 (42000): Row size too large. </span></span><br><span class="line"> <span class="attr">The</span> <span class="string">maximum row size for the used table type, not counting BLOBs, is 65535. </span></span><br><span class="line"> <span class="attr">This</span> <span class="string">includes storage overhead, check the manual. </span></span><br><span class="line"> <span class="attr">You</span> <span class="string">have to change some columns to TEXT or BLOBs</span></span><br></pre></td></tr></table></figure><p>报错的信息很简单,就是创建表的时候,所有字段的字节长度加起来超过了65535</p><p>解决的办法就是:<br><strong>将长的字段格式改成longtext 或者是 longblob</strong></p><p><em>这两个类型的区别是:如果存放二进制文件就用longblob,如果存放长文本,就用longtext</em></p><p>到这里基本能解决了</p><h3 id="!!!"><a href="#!!!" class="headerlink" title="!!!"></a><code>!!!</code></h3><p>如果还是爆超长,则需要查看数据库的字符集类型<br>需要注意一下字符集:</p><p><strong>utf8与utf8mb4区别</strong></p><blockquote><p>utf8 使用1~4个字节,一种变长的编码格式,字符编码。utf8mb4 即most bytes 4,使用4个字节来表示完整的UTF-8</p></blockquote><p>结论:如果数据库的字符集是utf8mb4,那就改成utf8,<del><em>嗯,排序规则也改</em></del> ,65535其实是字节长度,如果是utf8mb4,会算成4个字节,很容易就会超长。</p>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> MySQL </tag>
</tags>
</entry>
<entry>
<title>nginx</title>
<link href="/2024/04/21/nginx/"/>
<url>/2024/04/21/nginx/</url>
<content type="html"><![CDATA[<h2 id="Ngixn-部分功能介绍"><a href="#Ngixn-部分功能介绍" class="headerlink" title="Ngixn 部分功能介绍"></a>Ngixn 部分功能介绍</h2><h3 id="1-http服务器"><a href="#1-http服务器" class="headerlink" title="1.http服务器"></a>1.http服务器</h3><figure class="highlight properties"><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="attr">当只有静态资源的时候,可以使用Nginx做HTTP服务器,可以将服务器上的静态文件(如HTML、图片)通过HTTP协议展现给客户端。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">动静分离常用于前后端分离,Nginx提供的动静分离是指把动态请求和静态请求分离开,合适的服务器处理相应的请求,使整个服务器系统的性能、效率更高。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Nginx可以根据配置对不同的请求做不同转发,这是动静分离的基础。静态请求对应的静态资源可以直接放在Nginx上做缓冲,更好的做法是放在相应的缓冲服务器上。动态请求由相应的后端服务器处理。</span></span><br></pre></td></tr></table></figure><h3 id="2-正向代理和反向代理"><a href="#2-正向代理和反向代理" class="headerlink" title="2.正向代理和反向代理"></a>2.正向代理和反向代理</h3><figure class="highlight properties"><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="attr">正向代理:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">正向代理,是一个位于客户端与原始服务器之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定原始目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">反向代理:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">客户端本来可以直接通过HTTP协议访问某网站应用服务器,网站管理员可以在中间加上一个Nginx,客户端请求Nginx,Nginx请求应用服务器,然后将结果返回给客户端,此时Nginx就是反向代理服务器。</span></span><br></pre></td></tr></table></figure><h3 id="3-负载均衡"><a href="#3-负载均衡" class="headerlink" title="3.负载均衡"></a>3.负载均衡</h3><figure class="highlight properties"><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="attr">负载均衡多在高并发情况下需要使用。原理是将数据流量分摊到多个服务器执行,减轻每台服务器的压力,多台服务器(集群)共同完成工作任务,从而提高了数据的吞吐量。同时带来的好处是,其中一台服务器万一宕机,只要还有其他服务器正常运行,就不会影响用户使用。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Nginx可以通过反向代理来实现负载均衡。Nginx可使用的负载均衡策略有:轮询(默认)、权重、ip_hash、url_hash(第三方模块)、fair(第三方模块)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">weight轮询(默认):接收到的请求按照顺序逐一分配到不同的后端服务器,即使在使用过程中,某一台后端服务器宕机,nginx会自动将该服务器剔除出队列,请求受理情况不会受到任何影响。</span> <span class="string">这种方式下,可以给不同的后端服务器设置一个权重值(weight),用于调整不同的服务器上请求的分配率;权重数据越大,被分配到请求的几率越大;该权重值,主要是针对实际工作环境中不同的后端服务器硬件配置进行调整的。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ip_hash:每个请求按照发起客户端的ip的hash结果进行匹配,这样的算法下一个固定ip地址的客户端总会访问到同一个后端服务器,这也在一定程度上解决了集群部署环境下session共享的问题。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">fair:智能调整调度算法,动态的根据后端服务器的请求处理到响应的时间进行均衡分配,响应时间短处理效率高的服务器分配到请求的概率高,响应时间长处理效率低的服务器分配到的请求少;结合了前两者的优点的一种调度算法。nginx默认不支持fair算法,如果要使用这种调度算法,需安装upstream_fair模块。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">url_hash:按照访问的url的hash结果分配请求,每个请求的url会指向后端固定的某个服务器,可以在nginx作为静态服务器的情况下提高缓存效率。nginx默认不支持这种调度算法,要使用的话需要安装nginx的hash软件包。</span> <span class="string"></span></span><br></pre></td></tr></table></figure><h3 id="4-Nginx模块"><a href="#4-Nginx模块" class="headerlink" title="4.Nginx模块"></a>4.Nginx模块</h3><h4 id="4-1-nginx状态信息"><a href="#4-1-nginx状态信息" class="headerlink" title="4.1 nginx状态信息"></a>4.1 nginx状态信息</h4><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">nginx中的stub_status模块主要用于查看Nginx的一些状态信息。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">本模块默认是不会编译进Nginx的,如果要使用该模块,则要在编译安装Nginx时指定。</span> <span class="string"></span></span><br></pre></td></tr></table></figure><h4 id="4-1-1-加载http-stub-status模块"><a href="#4-1-1-加载http-stub-status模块" class="headerlink" title="4.1.1 加载http_stub_status模块"></a>4.1.1 加载http_stub_status模块</h4><figure class="highlight properties"><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="attr">./configure</span> <span class="string">--prefix=/usr/local/nginx --with-http_stub_status_module</span></span><br><span class="line"><span class="attr">make</span> <span class="string">&& make install</span></span><br></pre></td></tr></table></figure><h4 id="4-1-2-修改nginx配置文件"><a href="#4-1-2-修改nginx配置文件" class="headerlink" title="4.1.2 修改nginx配置文件"></a>4.1.2 修改nginx配置文件</h4><figure class="highlight properties"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">在server中,添加如下代码:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">location</span> <span class="string">/NginxStatus {</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">stub_status</span> <span class="string">on;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">access_log</span> <span class="string">on;</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">auth_basic</span> <span class="string">"NginxStatus";</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">auth_basic_user_file</span> <span class="string">htpasswd;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"><span class="attr">命令行操作:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">htpasswd</span> <span class="string">-c /usr/local/nginx/conf/htpasswd nginx_focus #连续输入两次密码</span></span><br><span class="line"></span><br><span class="line"><span class="attr">New</span> <span class="string">password:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Re-type</span> <span class="string">new password:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Adding</span> <span class="string">password for user nginx_focus</span></span><br></pre></td></tr></table></figure><h4 id="4-1-3-打开nginx-的stub-status"><a href="#4-1-3-打开nginx-的stub-status" class="headerlink" title="4.1.3 打开nginx 的stub_status"></a>4.1.3 打开nginx 的stub_status</h4><figure class="highlight properties"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">可以通过页面链接看到如下信息</span>:<span class="string"></span></span><br><span class="line"></span><br><span class="line"><span class="attr">Active</span> <span class="string">connections: 145</span></span><br><span class="line"></span><br><span class="line"><span class="attr">server</span> <span class="string">accepts handled requests</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">1749</span> <span class="string">1749 3198</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Reading</span>: <span class="string">0 Writing: 3 Waiting: 142</span></span><br><span class="line"></span><br><span class="line"><span class="attr">参数详解:</span> <span class="string"></span></span><br><span class="line"></span><br><span class="line"><span class="attr">Active</span> <span class="string">connections:145 </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#nginx 正处理的活动连接数145个。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">server</span> <span class="string">accepts handled requests</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">1749</span> <span class="string">1749 3198 </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#nginx启动到现在共处理了 1749个连接 ,nginx启动到现在共成功创建 1749次握手 请求丢失数=(握手-连接),可以看出,我们没丢请求;总共处理了3198 次请求。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Reading</span>: <span class="string">0 Writing: 3 Waiting: 142</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#Reading :nginx读取到客户端的Header信息数。</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#Writing : nginx返回给客户端的Header信息数。</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#Waiting : Nginx已经处理完正在等候下一次请求指令的驻留连接.开启keep-alive的情况下,这个值等于active–(reading+writing)。 </span></span><br></pre></td></tr></table></figure><h4 id="4-1-4-访问量统计"><a href="#4-1-4-访问量统计" class="headerlink" title="4.1.4 访问量统计"></a>4.1.4 访问量统计</h4><figure class="highlight properties"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">1、叙述</span></span><br><span class="line"></span><br><span class="line"><span class="attr">PV(Page</span> <span class="string">View):即页面浏览量或者点击量,用户每一次对网站中每个页面访问均记录1个PV。用户对同一页面的多次访问,访问量累积。</span></span><br><span class="line"><span class="attr">UV(Unique</span> <span class="string">Visitor):指通过互联网浏览这个网页的人,电脑称为一个访客、手机也称为一个访客,一天之内相同的客户端只能被计算一次。</span></span><br><span class="line"><span class="attr">IP(Internet</span> <span class="string">Protocol):指独立IP访问站点的IP总数,一天内相同IP只能算一次。</span></span><br><span class="line"><span class="attr">VV(Visit</span> <span class="string">View):指所有访客一天内访问网站的次数,当访客完成所有浏览并最终关闭网站的所有页面时变完成了一次访问,同一访客一天内可能有多次访问行为,访问次数累积。 </span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">1.根据访问IP统计UV</span></span><br><span class="line"></span><br><span class="line"><span class="attr">awk</span> <span class="string">'{print $1}' access.log|sort | uniq -c |wc -l</span></span><br><span class="line"></span><br><span class="line"><span class="attr">2.统计访问URL统计PV</span></span><br><span class="line"></span><br><span class="line"><span class="attr">awk</span> <span class="string">'{print $7}' access.log|wc -l</span></span><br><span class="line"></span><br><span class="line"><span class="attr">3.查询访问最频繁的URL</span></span><br><span class="line"></span><br><span class="line"><span class="attr">awk</span> <span class="string">'{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more</span></span><br><span class="line"></span><br><span class="line"><span class="attr">4.查询访问最频繁的IP</span></span><br><span class="line"></span><br><span class="line"><span class="attr">awk</span> <span class="string">'{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more</span></span><br><span class="line"></span><br><span class="line"><span class="attr">5.根据时间段统计查看日志</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">cat</span> <span class="string">access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more </span></span><br></pre></td></tr></table></figure><h4 id="4-2-nginx健康检查机制"><a href="#4-2-nginx健康检查机制" class="headerlink" title="4.2 nginx健康检查机制"></a>4.2 nginx健康检查机制</h4><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">nginx原生的健康检测主要涉及两个模块</span>:<span class="string">ngx_http_proxy_module和ngx_http_upstream_module </span></span><br></pre></td></tr></table></figure><h4 id="4-2-1-ngx-http-proxy-module"><a href="#4-2-1-ngx-http-proxy-module" class="headerlink" title="4.2.1 ngx_http_proxy_module"></a>4.2.1 ngx_http_proxy_module</h4><figure class="highlight properties"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">upstream</span> <span class="string">backend {</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">server</span> <span class="string">127.0.0.1:8080 max_fails=3 fail_timeout=30s;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">}</span></span><br><span class="line"></span><br><span class="line"><span class="attr">1.max_fails</span></span><br><span class="line"></span><br><span class="line"><span class="attr">设定Nginx与服务器通信的尝试失败的次数。在fail_timeout参数定义的时间段内,如果失败的次数达到此值,Nginx就认为服务器不可用。在下一个fail_timeout时间段,服务器不会再被尝试。</span> <span class="string">失败的尝试次数默认是1。设为0就会停止统计尝试次数,认为服务器是一直可用的。 你可以通过指令proxy_next_upstream、fastcgi_next_upstream和 memcached_next_upstream来配置什么是失败的尝试。 默认配置时,http_404状态不被认为是失败的尝试。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">2.fail_timeout</span></span><br><span class="line"></span><br><span class="line"><span class="attr">设定服务器被认为不可用的时间段以及统计失败尝试次数的时间段。在这段时间中,服务器失败次数达到指定的尝试次数,服务器就被认为不可用。默认情况下,该超时时间是10秒。</span> <span class="string"></span></span><br></pre></td></tr></table></figure><h4 id="4-2-2-ngx-http-proxy-module"><a href="#4-2-2-ngx-http-proxy-module" class="headerlink" title="4.2.2 ngx_http_proxy_module"></a>4.2.2 ngx_http_proxy_module</h4><figure class="highlight properties"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">1.proxy_connect_timeout</span></span><br><span class="line"></span><br><span class="line"><span class="attr">与后端服务器建立连接的超时时间</span></span><br><span class="line"></span><br><span class="line"><span class="attr">2.proxy_read_timeout</span></span><br><span class="line"></span><br><span class="line"><span class="attr">定义从后端服务器读取响应的超时。此超时是指相邻两次读操作之间的最长时间间隔,而不是整个响应传输完成的最长时间。如果后端服务器在超时时间段内没有传输任何数据,连接将被关闭</span></span><br><span class="line"></span><br><span class="line"><span class="attr">3.proxy_next_upstream</span></span><br><span class="line"></span><br><span class="line"><span class="attr">指定在何种情况下一个失败的请求应该被发送到下一台后端服务器</span></span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"><span class="attr">需要理解一点的是,只有在没有向客户端发送任何数据以前,将请求转给下一台后端服务器才是可行的。也就是说,如果在传输响应到客户端时出现错误或者超时,这类错误是不可能恢复的。</span> <span class="string"></span></span><br></pre></td></tr></table></figure><h2 id="zookeeper"><a href="#zookeeper" class="headerlink" title="zookeeper"></a>zookeeper</h2><h3 id="1-zookeeper-概述"><a href="#1-zookeeper-概述" class="headerlink" title="1. zookeeper 概述"></a>1. zookeeper 概述</h3><figure class="highlight properties"><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="attr">zookeeper是一种观察者模式的设计模式。负责管理存储数据,然后接受观察者的注册,一旦数据的状态发生变化,zookeeper就将负责通知已经在zookeeper上注册的那些观察者做出相应的反应</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p>观察者模式</p><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">观察者模式是一种对象行为模式。它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新。在观察者模式中,主体是通知的发布者,它发出通知时并不需要知道谁是它的观察者,可以有任意数目的观察者订阅并接收通知。观察者模式不仅被广泛应用于软件界面元素之间的交互,在业务对象之间的交互、权限管理等方面也有广泛的应用。</span></span><br></pre></td></tr></table></figure><h3 id="2-zookeeper的特点"><a href="#2-zookeeper的特点" class="headerlink" title="2. zookeeper的特点"></a>2. zookeeper的特点</h3><figure class="highlight properties"><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="attr">1.</span> <span class="string">zookeeper是一个领导者和多个跟随着组成的集群。</span></span><br><span class="line"><span class="attr">2.</span> <span class="string">集群中只w要有半数以上的节点存活,zookeeper集群就能正常服务</span></span><br><span class="line"><span class="attr">3.</span> <span class="string">全局数据一直:每个service保存一份相同的数据副本,client无论连接到哪个service,数据都是一致的</span></span><br><span class="line"><span class="attr">4.</span> <span class="string">更新顺序执行</span></span><br><span class="line"><span class="attr">5.</span> <span class="string">数据更新原子性,要么成功要么失败</span></span><br><span class="line"><span class="attr">6.</span> <span class="string">实时性,能读到最新数据</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="3-zookeeper-的应用场景"><a href="#3-zookeeper-的应用场景" class="headerlink" title="3. zookeeper 的应用场景"></a>3. zookeeper 的应用场景</h3><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> Nginx </tag>
</tags>
</entry>
<entry>
<title>wallpaper视频一键转移</title>
<link href="/2024/04/21/wallpaper%E8%A7%86%E9%A2%91%E4%B8%80%E9%94%AE%E8%BD%AC%E7%A7%BB/"/>
<url>/2024/04/21/wallpaper%E8%A7%86%E9%A2%91%E4%B8%80%E9%94%AE%E8%BD%AC%E7%A7%BB/</url>
<content type="html"><![CDATA[<h3 id="功能"><a href="#功能" class="headerlink" title="功能"></a>功能</h3><p>将wallpaper目录下面的视频转移到自己所需的目录下面</p><hr><h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><p>三个输入:</p><h5 id="第一个输入的是wallpaper存放壁纸的地址"><a href="#第一个输入的是wallpaper存放壁纸的地址" class="headerlink" title="第一个输入的是wallpaper存放壁纸的地址"></a>第一个输入的是wallpaper存放壁纸的地址</h5><p><img src="https://s3.bmp.ovh/imgs/2024/04/21/31a2eade7b26ed2f.png"></p><p>其中地址就为</p><p>E:\steam\Steam\steamapps\workshop\content\431960</p><p>如果不知道也可以右键壁纸查看 </p><h5 id="第二个输入的是下载的时间,"><a href="#第二个输入的是下载的时间," class="headerlink" title="第二个输入的是下载的时间,"></a>第二个输入的是下载的时间,</h5><p>意思就是从哪个时间开始的壁纸,就比如2022-12-4-19-0,就会找12月4号下午七点以后下载的壁纸</p><h5 id="第三个输入的是存放地址"><a href="#第三个输入的是存放地址" class="headerlink" title="第三个输入的是存放地址"></a>第三个输入的是存放地址</h5><p>这个就填要存放在哪里的地址。可以是电脑的,也可以把手机连上直接下载</p><hr><h3 id="所需依赖:"><a href="#所需依赖:" class="headerlink" title="所需依赖:"></a>所需依赖:</h3><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.alibaba<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>fastjson<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.2.47<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><h3 id="更新了方法"><a href="#更新了方法" class="headerlink" title="更新了方法"></a>更新了方法</h3><ul><li><p>使用了线程池,线程池的数量等于cpu核处理速度最快</p></li><li><p>使用了Files.copy方法,使用该方法在复制小文件的过程中速度比BufferedInputStream更快</p></li><li><p>使用了synchronizedList来统计文件的个数,因为此集合是线程安全的。</p></li></ul><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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.company;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSON;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.*;</span><br><span class="line"><span class="keyword">import</span> java.nio.file.Files;</span><br><span class="line"><span class="keyword">import</span> java.nio.file.StandardCopyOption;</span><br><span class="line"><span class="keyword">import</span> java.text.ParseException;</span><br><span class="line"><span class="keyword">import</span> java.text.SimpleDateFormat;</span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.*;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WallPaper</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">ExecutorService</span> <span class="variable">executor</span> <span class="operator">=</span> Executors.newFixedThreadPool(<span class="number">6</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 class="keyword">throws</span> ParseException, InterruptedException {</span><br><span class="line"> <span class="type">SimpleDateFormat</span> <span class="variable">sdf</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleDateFormat</span>(<span class="string">"yyyy-MM-dd-HH-mm"</span>);</span><br><span class="line"> List<String> list = Collections.synchronizedList(<span class="keyword">new</span> <span class="title class_">ArrayList</span><String>());</span><br><span class="line"></span><br><span class="line"> <span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"> System.out.println(<span class="string">"请输入wallpaper下载的地址"</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> scanner.next();</span><br><span class="line"> <span class="type">File</span> <span class="variable">sfile</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(str);</span><br><span class="line"> System.out.println(<span class="string">"请输入时间(格式为:年-月-日-小时-分钟)"</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">time</span> <span class="operator">=</span> scanner.next();</span><br><span class="line"> <span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> sdf.parse(time);</span><br><span class="line"> System.out.println(<span class="string">"请输入需要存放的地址"</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">str2</span> <span class="operator">=</span> scanner.next();</span><br><span class="line"> <span class="type">File</span> <span class="variable">tfile</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(str2);</span><br><span class="line"> <span class="keyword">if</span> (!tfile.exists() && !tfile.isDirectory()) {</span><br><span class="line"> tfile = <span class="keyword">new</span> <span class="title class_">File</span>(tfile.getParentFile(), <span class="string">"wallpaper下载的视频"</span>);</span><br><span class="line"> System.out.println(tfile.getAbsolutePath());</span><br><span class="line"> tfile.mkdirs();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (!sfile.exists() && !sfile.isDirectory()) {</span><br><span class="line"> System.out.println(<span class="string">"地址不对哦"</span>);</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (sfile.isDirectory()) {</span><br><span class="line"> File[] fs = sfile.listFiles();</span><br><span class="line"> <span class="type">File</span> <span class="variable">finalTfile</span> <span class="operator">=</span> tfile;</span><br><span class="line"> <span class="type">int</span> <span class="variable">tmp</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">assert</span> fs != <span class="literal">null</span>;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * *先统计文件的个数</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (File x : fs) {</span><br><span class="line"> <span class="type">Date</span> <span class="variable">date1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Date</span>(x.lastModified());</span><br><span class="line"> <span class="keyword">if</span> (date1.compareTo(date) > <span class="number">0</span>) {</span><br><span class="line"> <span class="type">boolean</span> <span class="variable">flag</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">needFilename</span> <span class="operator">=</span> x.getAbsolutePath() + <span class="string">"\\project.json"</span>;</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">new</span> <span class="title class_">File</span>(needFilename).exists()) {</span><br><span class="line"> flag = isNeedFile(needFilename);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (flag) {</span><br><span class="line"> tmp++;</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 class="type">CountDownLatch</span> <span class="variable">cdl</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">CountDownLatch</span>(tmp);</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> *多线程进行复制</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="type">Date</span> <span class="variable">startDate</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Date</span>();</span><br><span class="line"> <span class="keyword">for</span> (File x : fs) {</span><br><span class="line"> executor.submit(</span><br><span class="line"> () -> {</span><br><span class="line"> <span class="type">Date</span> <span class="variable">date1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Date</span>(x.lastModified());</span><br><span class="line"> <span class="keyword">if</span> (date1.compareTo(date) > <span class="number">0</span>) {</span><br><span class="line"> <span class="type">boolean</span> <span class="variable">flag</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line"> <span class="type">String</span> <span class="variable">needFilename</span> <span class="operator">=</span> x.getAbsolutePath() + <span class="string">"\\project.json"</span>;</span><br><span class="line"> <span class="keyword">if</span> (<span class="keyword">new</span> <span class="title class_">File</span>(needFilename).exists()) {</span><br><span class="line"> flag = isNeedFile(needFilename);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (flag) {</span><br><span class="line"> <span class="type">String</span> <span class="variable">filename</span> <span class="operator">=</span> x.getAbsolutePath() + <span class="string">"\\"</span> + Filename(needFilename);</span><br><span class="line"> <span class="type">File</span> <span class="variable">tf</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(finalTfile.getAbsoluteFile() + <span class="string">"\\"</span> + Filename(needFilename));</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> copyfile(<span class="keyword">new</span> <span class="title class_">File</span>(filename), tf);</span><br><span class="line"> <span class="keyword">synchronized</span> (list){</span><br><span class="line"> list.add(<span class="string">"成功"</span>);</span><br><span class="line"> }</span><br><span class="line"> System.out.println(<span class="string">"将 "</span> + Filename(needFilename) + <span class="string">" 复制到 "</span> + finalTfile.getAbsolutePath() + <span class="string">" 中"</span>);</span><br><span class="line"> } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> System.out.println(Filename(needFilename) + <span class="string">"复制失败"</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> cdl.countDown();</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"> cdl.await();</span><br><span class="line"> executor.shutdown();</span><br><span class="line"> System.out.println(<span class="string">"复制完成,共"</span> + list.size() + <span class="string">"个文件"</span>);</span><br><span class="line"> <span class="type">Date</span> <span class="variable">endDate</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Date</span>();</span><br><span class="line"> System.out.println(endDate.getTime()-startDate.getTime());</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> System.out.println(<span class="string">"地址不对哦"</span>);</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 class="comment">//复制文件</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">synchronized</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">copyfile</span><span class="params">(File fs, File ft)</span> <span class="keyword">throws</span> IOException {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (ft.exists()) {</span><br><span class="line"> System.out.println(ft.getName() + <span class="string">"重复...."</span> + <span class="string">"正在删除"</span>);</span><br><span class="line"> ft.delete();</span><br><span class="line"> }</span><br><span class="line"> Files.copy(fs.toPath(),ft.toPath(),StandardCopyOption.REPLACE_EXISTING);</span><br><span class="line"><span class="comment">// FileInputStream fi = new FileInputStream(fs);</span></span><br><span class="line"><span class="comment">// FileOutputStream fo = new FileOutputStream(ft);</span></span><br><span class="line"><span class="comment">// BufferedInputStream bfi = null;</span></span><br><span class="line"><span class="comment">// BufferedOutputStream bfo = null;</span></span><br><span class="line"><span class="comment">// bfi = new BufferedInputStream(fi);</span></span><br><span class="line"><span class="comment">// bfo = new BufferedOutputStream(fo);</span></span><br><span class="line"><span class="comment">// int count = -1;</span></span><br><span class="line"><span class="comment">// while ((count = bfi.read()) != -1) {</span></span><br><span class="line"><span class="comment">// bfo.write(count);</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"><span class="comment">// bfo.flush();</span></span><br><span class="line"><span class="comment">// bfo.close();</span></span><br><span class="line"><span class="comment">// bfi.close();</span></span><br><span class="line"> }</span><br><span class="line"></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="type">boolean</span> <span class="title function_">isNeedFile</span><span class="params">(String filename)</span> {</span><br><span class="line"></span><br><span class="line"> <span class="type">String</span> <span class="variable">s</span> <span class="operator">=</span> readJsonFile(filename);</span><br><span class="line"> <span class="type">JSONObject</span> <span class="variable">jobj</span> <span class="operator">=</span> JSON.parseObject(s);</span><br><span class="line"> <span class="keyword">if</span> (jobj.get(<span class="string">"contentrating"</span>) != <span class="literal">null</span> && !jobj.get(<span class="string">"contentrating"</span>).equals(<span class="string">""</span>))</span><br><span class="line"> <span class="keyword">return</span> jobj.get(<span class="string">"contentrating"</span>).toString().equals(<span class="string">"Mature"</span>) && (jobj.get(<span class="string">"type"</span>).toString().equals(<span class="string">"Video"</span>) || jobj.get(<span class="string">"type"</span>).toString().equals(<span class="string">"video"</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><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">Filename</span><span class="params">(String filename)</span> {</span><br><span class="line"></span><br><span class="line"> <span class="type">String</span> <span class="variable">s</span> <span class="operator">=</span> readJsonFile(filename);</span><br><span class="line"> <span class="type">JSONObject</span> <span class="variable">jobj</span> <span class="operator">=</span> JSON.parseObject(s);</span><br><span class="line"> <span class="keyword">return</span> jobj.get(<span class="string">"file"</span>).toString();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//读取json文件</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">readJsonFile</span><span class="params">(String fileName)</span> {</span><br><span class="line"> <span class="type">String</span> <span class="variable">jsonStr</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="type">File</span> <span class="variable">jsonFile</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(fileName);</span><br><span class="line"> <span class="type">FileReader</span> <span class="variable">fileReader</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileReader</span>(jsonFile);</span><br><span class="line"> <span class="type">Reader</span> <span class="variable">reader</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">InputStreamReader</span>(<span class="keyword">new</span> <span class="title class_">FileInputStream</span>(jsonFile), <span class="string">"utf-8"</span>);</span><br><span class="line"> <span class="type">int</span> <span class="variable">ch</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"> <span class="type">StringBuffer</span> <span class="variable">sb</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">StringBuffer</span>();</span><br><span class="line"> <span class="keyword">while</span> ((ch = reader.read()) != -<span class="number">1</span>) {</span><br><span class="line"> sb.append((<span class="type">char</span>) ch);</span><br><span class="line"> }</span><br><span class="line"> fileReader.close();</span><br><span class="line"> reader.close();</span><br><span class="line"> jsonStr = sb.toString();</span><br><span class="line"> <span class="keyword">return</span> jsonStr;</span><br><span class="line"> } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</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"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>利用反射实现orm</title>
<link href="/2024/04/21/%E5%88%A9%E7%94%A8%E5%8F%8D%E5%B0%84%E5%AE%9E%E7%8E%B0orm/"/>
<url>/2024/04/21/%E5%88%A9%E7%94%A8%E5%8F%8D%E5%B0%84%E5%AE%9E%E7%8E%B0orm/</url>
<content type="html"><![CDATA[<p>需求:从数据库表中查询数据,并且以json的格式输出</p><p>由于类中的属性太多了,不想一个一个写了,所以使用反射直接set进去,这样比较方便,也比较实用,并且加深了对反射的理解。</p><p>并且使用了jackson 将List转换成了 json格式的字符串</p><p>代码如下 </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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">test</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_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> ClassNotFoundException, SQLException {</span><br><span class="line"> Class.forName(<span class="string">"com.mysql.jdbc.Driver"</span>);</span><br><span class="line"> <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> DriverManager.getConnection(<span class="string">"jdbc:mysql://localhost:3306/book_shop?useSSL=false"</span>,<span class="string">"root"</span>,<span class="string">"111111"</span>);</span><br><span class="line"></span><br><span class="line"> System.out.println(<span class="string">"连接数据库成功"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 先查询图书的种类</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="type">Statement</span> <span class="variable">statement</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line"> statement= connection.createStatement();</span><br><span class="line"> <span class="type">ResultSet</span> <span class="variable">resultSet</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line"> resultSet = statement.executeQuery(<span class="string">"SELECT * FROM TB_CATEGORY"</span>);</span><br><span class="line"> List<category> c = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">while</span> (resultSet.next()){</span><br><span class="line"> <span class="type">category</span> <span class="variable">category</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">category</span>();</span><br><span class="line"> category.setCategoryId(resultSet.getInt(<span class="number">1</span>));</span><br><span class="line"> category.setCategoryName(resultSet.getString(<span class="number">2</span>));</span><br><span class="line"> c.add(category);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 利用反射,读取book里面的属性</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"> <span class="type">Class</span> <span class="variable">clazz</span> <span class="operator">=</span> Class.forName(Book.class.getName());</span><br><span class="line"> Field[] fields = clazz.getDeclaredFields();</span><br><span class="line"> List<String> fs = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">for</span> (Field f: fields) {</span><br><span class="line"> fs.add(String.valueOf(f));</span><br><span class="line"><span class="comment">// System.out.println(f);</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 使用流,将 属性名前面的去掉,留下简化的属性名</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> fs = fs.stream().map(x->x.replaceAll(x,x.split(<span class="string">"\\."</span>)[x.split(<span class="string">"\\."</span>).length-<span class="number">1</span>])).collect(Collectors.toList());</span><br><span class="line"><span class="comment">// System.out.println(fs);</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 查询图书</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">"SELECT * FROM TB_BOOK"</span>;</span><br><span class="line"> <span class="type">Statement</span> <span class="variable">st</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line"> st = connection.createStatement();</span><br><span class="line"> <span class="type">ResultSet</span> <span class="variable">rs</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line"> rs = st.executeQuery(sql);</span><br><span class="line"> <span class="type">ResultSetMetaData</span> <span class="variable">rd</span> <span class="operator">=</span> rs.getMetaData();</span><br><span class="line"> <span class="type">int</span> <span class="variable">count</span> <span class="operator">=</span> rd.getColumnCount();</span><br><span class="line"> List<Book> books = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">while</span> (rs.next()){</span><br><span class="line"> <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line"> <span class="type">Book</span> <span class="variable">book</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Book</span>();</span><br><span class="line"> <span class="keyword">while</span> (i<count){</span><br><span class="line"> <span class="comment">//循环将数据库中的值set 到book类中</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">stringValue</span> <span class="operator">=</span> rs.getString(i);</span><br><span class="line"> <span class="type">String</span> <span class="variable">ColumnName</span> <span class="operator">=</span> rd.getColumnName(i);</span><br><span class="line"> setValues(ColumnName,stringValue,book,fs);</span><br><span class="line"> <span class="comment">//book中category代表数的种类,但是是用数字表示的,因此要转换成为name并且赋值</span></span><br><span class="line"> <span class="keyword">if</span>(ColumnName.equals(<span class="string">"category_id"</span>)){</span><br><span class="line"> <span class="keyword">for</span>(category category: c){</span><br><span class="line"> <span class="keyword">if</span>(category.getCategoryId()==Integer.valueOf(stringValue)){</span><br><span class="line"> book.setCategory_name(category.getCategoryName());</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> books.add(book);</span><br><span class="line"><span class="comment">// System.out.println();</span></span><br><span class="line"> }</span><br><span class="line"><span class="comment">// for(Book b:books){</span></span><br><span class="line"><span class="comment">// System.out.println(b);</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 利用jackson实现序列化</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="comment">//创建映射对象</span></span><br><span class="line"> <span class="type">ObjectMapper</span> <span class="variable">mapper</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ObjectMapper</span>();</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="type">String</span> <span class="variable">json</span> <span class="operator">=</span> mapper.writeValueAsString(books);</span><br><span class="line"> System.out.println(json);</span><br><span class="line"> } <span class="keyword">catch</span> (JsonProcessingException e) {</span><br><span class="line"> e.printStackTrace();</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"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 利用反射,调用 set方法</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> ColumnName</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> stringValue</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> book</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> fs</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@throws</span> ClassNotFoundException</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">static</span> <span class="keyword">void</span> <span class="title function_">setValues</span><span class="params">(String ColumnName,String stringValue, Book book,List<String> fs)</span> <span class="keyword">throws</span> ClassNotFoundException {</span><br><span class="line"></span><br><span class="line"> <span class="type">Class</span> <span class="variable">clazz</span> <span class="operator">=</span> book.getClass();</span><br><span class="line"> Field[] fields = clazz.getDeclaredFields();</span><br><span class="line"> <span class="type">Field</span> <span class="variable">f</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line"> <span class="comment">//我们这里要获得与之对应的属性,因为要调用set,必须得传参数进去,因此我们需要得到属性的类型</span></span><br><span class="line"> <span class="keyword">for</span>(Field field:fields ){</span><br><span class="line"> <span class="keyword">if</span>(ColumnName.equals(field.toString().split(<span class="string">"\\."</span>)[field.toString().split(<span class="string">"\\."</span>).length-<span class="number">1</span>])){</span><br><span class="line"> f = field;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//准备拼接set方法,将属性名称前面改为大写</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">fileName</span> <span class="operator">=</span> initStr(ColumnName);</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"></span><br><span class="line"> <span class="comment">//拼接方法</span></span><br><span class="line"> <span class="type">Method</span> <span class="variable">setBookValue</span> <span class="operator">=</span> clazz.getDeclaredMethod(<span class="string">"set"</span>+fileName,f.getType());</span><br><span class="line"><span class="comment">// System.out.println(f.getType());</span></span><br><span class="line"> <span class="comment">//book属性中有integer类型,因此需要判断并且转换类型</span></span><br><span class="line"> <span class="keyword">if</span>(f.getType().toString().equals(<span class="string">"class java.lang.Integer"</span>)){</span><br><span class="line"> setBookValue.invoke(book,Integer.valueOf(stringValue));</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//同理,有int类型</span></span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(f.getType().toString().equals(<span class="string">"int"</span>)){</span><br><span class="line"> setBookValue.invoke(book,Integer.valueOf(stringValue));</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> setBookValue.invoke(book,stringValue);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> } <span class="keyword">catch</span> (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {</span><br><span class="line"> e.printStackTrace();</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 class="comment">/**</span></span><br><span class="line"><span class="comment"> * 将首个字母大小写</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> old</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">initStr</span><span class="params">(String old)</span>{</span><br><span class="line"> <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> old.substring(<span class="number">0</span>,<span class="number">1</span>).toUpperCase() + old.substring(<span class="number">1</span>) ;</span><br><span class="line"> <span class="keyword">return</span> str ;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">} </span><br></pre></td></tr></table></figure><p>Book类</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Book</span> {</span><br><span class="line"></span><br><span class="line"> Integer book_id;</span><br><span class="line"> Integer category_id;<span class="comment">//类别</span></span><br><span class="line"> String category_name;<span class="comment">//类别名称</span></span><br><span class="line"> String book_name;</span><br><span class="line"> String author;</span><br><span class="line"> String publisher;</span><br><span class="line"></span><br><span class="line"> <span class="type">int</span> price;</span><br><span class="line"> <span class="type">int</span> sale_price;</span><br><span class="line"> <span class="type">int</span> amount;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> Integer <span class="title function_">getBook_id</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> book_id;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setBook_id</span><span class="params">(Integer book_id)</span> {</span><br><span class="line"> <span class="built_in">this</span>.book_id = book_id;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> Integer <span class="title function_">getCategory_id</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> category_id;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setCategory_id</span><span class="params">(Integer category_id)</span> {</span><br><span class="line"> <span class="built_in">this</span>.category_id = category_id;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getCategory_name</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> category_name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setCategory_name</span><span class="params">(String category_name)</span> {</span><br><span class="line"> <span class="built_in">this</span>.category_name = category_name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getBook_name</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> book_name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setBook_name</span><span class="params">(String book_name)</span> {</span><br><span class="line"> <span class="built_in">this</span>.book_name = book_name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">getSale_price</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> sale_price;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setSale_price</span><span class="params">(<span class="type">int</span> sale_price)</span> {</span><br><span class="line"> <span class="built_in">this</span>.sale_price = sale_price;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getAuthor</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> author;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setAuthor</span><span class="params">(String author)</span> {</span><br><span class="line"> <span class="built_in">this</span>.author = author;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getPublisher</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> publisher;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPublisher</span><span class="params">(String publisher)</span> {</span><br><span class="line"> <span class="built_in">this</span>.publisher = publisher;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">getPrice</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> price;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPrice</span><span class="params">(<span class="type">int</span> price)</span> {</span><br><span class="line"> <span class="built_in">this</span>.price = price;</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 class="keyword">public</span> <span class="type">int</span> <span class="title function_">getAmount</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> amount;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setAmount</span><span class="params">(<span class="type">int</span> amount)</span> {</span><br><span class="line"> <span class="built_in">this</span>.amount = amount;</span><br><span class="line"> }</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> String <span class="title function_">toString</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"Book{"</span> +</span><br><span class="line"> <span class="string">"book_id="</span> + book_id +</span><br><span class="line"> <span class="string">", category_id="</span> + category_id +</span><br><span class="line"> <span class="string">", category_name='"</span> + category_name + <span class="string">'\''</span> +</span><br><span class="line"> <span class="string">", book_name='"</span> + book_name + <span class="string">'\''</span> +</span><br><span class="line"> <span class="string">", author='"</span> + author + <span class="string">'\''</span> +</span><br><span class="line"> <span class="string">", publisher='"</span> + publisher + <span class="string">'\''</span> +</span><br><span class="line"> <span class="string">", price="</span> + price +</span><br><span class="line"> <span class="string">", sale_price="</span> + sale_price +</span><br><span class="line"> <span class="string">", amount="</span> + amount +</span><br><span class="line"> <span class="string">'}'</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>categorie 类</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><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="keyword">public</span> <span class="keyword">class</span> <span class="title class_">category</span> {</span><br><span class="line"> Integer categoryId;<span class="comment">//类别</span></span><br><span class="line"> String categoryName;<span class="comment">//类别名称</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> Integer <span class="title function_">getCategoryId</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> categoryId;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setCategoryId</span><span class="params">(Integer categoryId)</span> {</span><br><span class="line"> <span class="built_in">this</span>.categoryId = categoryId;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getCategoryName</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> categoryName;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setCategoryName</span><span class="params">(String categoryName)</span> {</span><br><span class="line"> <span class="built_in">this</span>.categoryName = categoryName;</span><br><span class="line"> }</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> String <span class="title function_">toString</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"category{"</span> +</span><br><span class="line"> <span class="string">"categoryId="</span> + categoryId +</span><br><span class="line"> <span class="string">", categoryName='"</span> + categoryName + <span class="string">'\''</span> +</span><br><span class="line"> <span class="string">'}'</span>;</span><br><span class="line"> }</span><br><span class="line">} </span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>常见Linux命令</title>
<link href="/2024/04/21/%E5%B8%B8%E8%A7%81Linux%E5%91%BD%E4%BB%A4/"/>
<url>/2024/04/21/%E5%B8%B8%E8%A7%81Linux%E5%91%BD%E4%BB%A4/</url>
<content type="html"><![CDATA[<p>/usr/local/redis/bin/redis-cli -a 123456 –cluster create 10.101.37.179:6381 10.101.37.179:6380 10.101.37.200:6381 10.101.37.200:6380 10.101.37.111:6381 10.101.37.111:6380 –cluster-replicas 1</p><p>rm -rf appendonly.aof<br>rm -rf dump.rdb<br>rm -rf nodes.conf</p><p>/usr/local/redis/bin/redis-server /data/redis/6379/redis.conf</p><p>/usr/local/redis/bin/redis-cli -a 123456 -p 6380 shutdown</p><p>/usr/local/redis/bin/redis-cli -a 123456</p><p>/usr/local/redis/bin/redis-cli -a 123456 –cluster check 10.101.37.179:6381</p><p>firewall-cmd –zone=public –list-ports<br>firewall-cmd –zone=public –add-port=9913/tcp –permanent<br>firewall-cmd –reload<br>firewall-cmd –state<br>npm install –legacy-peer-deps<br>firewall-cmd –query-port=80/tcp<br>netstat -tlpn 查询侦听端口<br>nc -l 8080<br>ss -tnl</p><p>cat /etc/redhat-release 查看Linux操作系统信息</p><p>df -h 查看磁盘空间</p><p>mysqladmin -u root password 123456</p><p>netstat -aon|findstr “8080”<br>tasklist|findstr “2668”</p><p>修改mysql 数据库密码</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ALTER USER <span class="string">'root'</span>@<span class="string">'localhost'</span> IDENTIFIED WITH mysql_native_password BY <span class="string">'root'</span>;</span><br></pre></td></tr></table></figure><p>如果安装发生错误,443<br>安装ca-certificates<br>yum install ca-certificates -y<br>或者是w<br>yum install ssl-cert -y</p><h3 id="1-查看当前编码"><a href="#1-查看当前编码" class="headerlink" title="1. 查看当前编码"></a>1. 查看当前编码</h3><p>echo $LANG</p><h3 id="2。设置编码为zh-CN-UTF-8"><a href="#2。设置编码为zh-CN-UTF-8" class="headerlink" title="2。设置编码为zh_CN.UTF-8"></a>2。设置编码为zh_CN.UTF-8</h3><p>export LANG=export LANG=zh_CN.UTF-8<br>3.再次查看当前编码<br> echo $LANG</p><p>ubuntu防火墙<br>sudo ufw status<br>sudo ufw enable //开启防火墙<br>sudo ufw allow 22 //开放22端口<br>sudo ufw delete allow 21 //关闭21端口</p><p>netstat -lntup | awk ‘NR>2{gsub(/.*:/,” “,$4);print $4}’ | grep “ 31059$”<br>精确找出端口31059</p><p>PORT=88<br>netstat -lntup | awk -v port=”$PORT” ‘NR>2 && $4 ~ “:”port”$” {gsub(/.*:/,””,$4); print $4}’</p><p>#-o或–options选项后面接可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的<br>#-l或–long选项后面接可接受的长选项,用逗号分开,冒号的意义同短选项。<br>#-n选项后接选项解析错误时提示的脚本名字<br>ARGS=<code>getopt -o s: --long p: -n "$BASH_NAME" -- "$@"</code></p><p>mysqldump</p>]]></content>
<categories>
<category> 小笔记 </category>
</categories>
<tags>
<tag> Linux </tag>
</tags>
</entry>
<entry>
<title>doris删除工具</title>
<link href="/2024/04/21/doris%E5%88%A0%E9%99%A4%E5%B7%A5%E5%85%B7/"/>
<url>/2024/04/21/doris%E5%88%A0%E9%99%A4%E5%B7%A5%E5%85%B7/</url>
<content type="html"><![CDATA[<h2 id="概要"><a href="#概要" class="headerlink" title="概要"></a>概要</h2><blockquote><p>对于Doris的 Unique 模型,在删除数据的时候只能根据key删除,如果使用其他条件就会报错</p></blockquote><h2 id="整体架构流程"><a href="#整体架构流程" class="headerlink" title="整体架构流程"></a>整体架构流程</h2><p>先获得表的key,然后在通过输入的条件获得key的所有值,最后通过key的值拼接删除语句,调用线程删除。</p><h2 id="技术名词解释"><a href="#技术名词解释" class="headerlink" title="技术名词解释"></a>技术名词解释</h2><ul><li>jsqlparser :SQL解析工具,能将字符串解析出SQL的表,值,条件等</li><li>HikariCP :数据库连接池</li><li>单例模式:单例模式调用数据库连接</li></ul><h2 id="技术细节"><a href="#技术细节" class="headerlink" title="技术细节"></a>技术细节</h2><ul><li>多线程:使用线程池开启线程,也可以使用分页线程</li><li>时间显示:时间显示使用无符号的时间格式</li></ul><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>具体实现代码如下:</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> org.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"><span class="keyword">import</span> java.time.LocalDate;</span><br><span class="line"><span class="keyword">import</span> java.time.LocalDateTime;</span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.CountDownLatch;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.TimeUnit;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.atomic.AtomicInteger;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.example.SqlParserExample.getTableName;</span><br><span class="line"></span><br><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 class="keyword">throws</span> Exception {</span><br><span class="line"> initLogRecord.initLog();</span><br><span class="line"> System.out.println(<span class="string">"================================================================"</span>);</span><br><span class="line"> <span class="type">Connection</span> <span class="variable">conn</span> <span class="operator">=</span> HikariConfigs.HikariConn();</span><br><span class="line"> <span class="comment">// Statement stmt = conn.createStatement();</span></span><br><span class="line"> <span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"> System.out.println(<span class="string">"===========================请输入删除的语句========================="</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> scanner.nextLine();</span><br><span class="line"> <span class="type">String</span> <span class="variable">where</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">if</span> (sql.indexOf(<span class="string">"where"</span>) > <span class="number">0</span>) {</span><br><span class="line"> where = sql.substring(sql.indexOf(<span class="string">"where"</span>));</span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">if</span> (sql.indexOf(<span class="string">"WHERE"</span>) > <span class="number">0</span>) {</span><br><span class="line"> where = sql.substring(sql.indexOf(<span class="string">"WHERE"</span>));</span><br><span class="line"> }</span><br><span class="line"> System.out.println(<span class="string">"=======================获取WHERE条件============================="</span>);</span><br><span class="line"> System.out.println(where);</span><br><span class="line"> <span class="type">String</span> <span class="variable">table</span> <span class="operator">=</span> getTableName(sql);</span><br><span class="line"> <span class="type">String</span> <span class="variable">getKey</span> <span class="operator">=</span> <span class="string">"select * from information_schema.columns where TABLE_NAME = ? "</span>;</span><br><span class="line"> <span class="type">PreparedStatement</span> <span class="variable">ptmt_getKey</span> <span class="operator">=</span> conn.prepareStatement(getKey);</span><br><span class="line"> ptmt_getKey.setString(<span class="number">1</span>, table);</span><br><span class="line"> <span class="type">ResultSet</span> <span class="variable">rs</span> <span class="operator">=</span> ptmt_getKey.executeQuery();</span><br><span class="line"> List<String> key = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> Map<String, String> key_type = <span class="keyword">new</span> <span class="title class_">HashMap</span><>();</span><br><span class="line"> System.out.println(<span class="string">"=======================获取KEY=================================="</span>);</span><br><span class="line"> <span class="keyword">while</span> (rs.next()) {</span><br><span class="line"> <span class="keyword">if</span> (rs.getString(<span class="string">"column_key"</span>).equals(<span class="string">"UNI"</span>)) {</span><br><span class="line"> key.add(rs.getString(<span class="string">"column_name"</span>));</span><br><span class="line"> key_type.put(rs.getString(<span class="string">"column_name"</span>), rs.getString(<span class="string">"DATA_TYPE"</span>));</span><br><span class="line"> System.out.println(rs.getString(<span class="string">"column_name"</span>) + <span class="string">" "</span> + rs.getString(<span class="string">"column_key"</span>));</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> System.out.println(<span class="string">"=======================拼接key=================================="</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">column</span> <span class="operator">=</span> <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span> (String s : key) {</span><br><span class="line"> <span class="keyword">if</span> (!Objects.equals(column, <span class="string">""</span>)) {</span><br><span class="line"> column = column + <span class="string">","</span> + s;</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> column = s;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> System.out.println(column);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 拼接SELECT 语句</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">newSQL</span> <span class="operator">=</span> <span class="string">"SELECT "</span> + column + <span class="string">" FROM "</span> + table + <span class="string">" "</span> + where;</span><br><span class="line"> <span class="type">PreparedStatement</span> <span class="variable">pstm_getkeyvalue</span> <span class="operator">=</span> conn.prepareStatement(newSQL);</span><br><span class="line"> rs = pstm_getkeyvalue.executeQuery();</span><br><span class="line"> List<Map<String, String>> values = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">while</span> (rs.next()) {</span><br><span class="line"> Map<String, String> map = <span class="keyword">new</span> <span class="title class_">HashMap</span><>();</span><br><span class="line"> <span class="keyword">for</span> (String x : key) {</span><br><span class="line"> map.put(x, rs.getString(x));</span><br><span class="line"> }</span><br><span class="line"> values.add(map);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// for (int i =0 ;i< values.size();i++){</span></span><br><span class="line"> <span class="comment">// System.out.println(values.get(i));;</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// 循环拼接删除的where 条件</span></span><br><span class="line"> StringBuilder delete_where;</span><br><span class="line"> String delete_sql;</span><br><span class="line"> List<String> delete_sqls = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> <span class="keyword">for</span> (Map<String, String> x : values) {</span><br><span class="line"> delete_where = <span class="keyword">new</span> <span class="title class_">StringBuilder</span>();</span><br><span class="line"> <span class="keyword">for</span> (String y : x.keySet()) {</span><br><span class="line"> <span class="keyword">if</span> (delete_where.length() > <span class="number">0</span>) {</span><br><span class="line"> <span class="comment">// 时间格式的拼接</span></span><br><span class="line"> <span class="keyword">if</span> (key_type.get(y).equals(<span class="string">"datetime"</span>)) {</span><br><span class="line"> <span class="type">LocalDateTime</span> <span class="variable">date</span> <span class="operator">=</span> LocalDateUtils.parseLocalDateTime(x.get(y),</span><br><span class="line"> LocalDateUtils.DATETIME_PATTERN);</span><br><span class="line"> <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> LocalDateUtils.format(date, LocalDateUtils.UNSIGNED_DATETIME_PATTERN);</span><br><span class="line"> delete_where.append(<span class="string">" AND "</span>).append(y).append(<span class="string">"="</span>).append(<span class="string">"'"</span>).append(str).append(<span class="string">"'"</span>);</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> delete_where.append(<span class="string">" AND "</span>).append(y).append(<span class="string">"="</span>).append(<span class="string">"'"</span>).append(x.get(y)).append(<span class="string">"'"</span>);</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> <span class="keyword">if</span> (key_type.get(y).equals(<span class="string">"datetime"</span>)) {</span><br><span class="line"> <span class="type">LocalDate</span> <span class="variable">date</span> <span class="operator">=</span> LocalDateUtils.parseLocalDate(x.get(y), LocalDateUtils.DATETIME_PATTERN);</span><br><span class="line"> <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> LocalDateUtils.format(date, LocalDateUtils.UNSIGNED_DATETIME_PATTERN);</span><br><span class="line"> delete_where = <span class="keyword">new</span> <span class="title class_">StringBuilder</span>(y + <span class="string">"="</span> + <span class="string">"'"</span> + str + <span class="string">"'"</span>);</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> delete_where = <span class="keyword">new</span> <span class="title class_">StringBuilder</span>(y + <span class="string">"="</span> + <span class="string">"'"</span> + x.get(y) + <span class="string">"'"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> delete_sql = <span class="string">""</span>;</span><br><span class="line"> delete_sql = <span class="string">"DELETE FROM "</span> + table + <span class="string">" WHERE "</span> + delete_where;</span><br><span class="line"> delete_sqls.add(delete_sql);</span><br><span class="line"> <span class="comment">// System.out.println("删除语句:"+ delete_sql);</span></span><br><span class="line"> <span class="comment">// if (dels.executeUpdate(delete_sql)>0){</span></span><br><span class="line"> <span class="comment">// i++;</span></span><br><span class="line"> <span class="comment">// System.out.println("=======================删除成功=======================");</span></span><br><span class="line"> <span class="comment">// }else{</span></span><br><span class="line"> <span class="comment">// System.out.println("!!!!!!!!!!!!!!!!!删除失败!!!!!!!!!!!!!!!!!");</span></span><br><span class="line"> <span class="comment">// j++;</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> }</span><br><span class="line"> conn.close();</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 使用线程执行sql</span></span><br><span class="line"> System.out.println(<span class="string">"===================== 需要删除数据的总数为: "</span> + delete_sqls.size() + <span class="string">" ================="</span>);</span><br><span class="line"> System.out.println(<span class="string">"====================== 请确认是否删除? yes or no====================="</span>);</span><br><span class="line"> <span class="type">String</span> <span class="variable">is_delete</span> <span class="operator">=</span> scanner.nextLine();</span><br><span class="line"> <span class="keyword">if</span> (!is_delete.equals(<span class="string">"yes"</span>)) {</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// ExecutorService executor = Executors.newFixedThreadPool(10); // 创建一个固定大小的线程池</span></span><br><span class="line"> <span class="comment">// AtomicInteger successCount = new AtomicInteger(0); // 原子计数器,用于记录成功执行的SQL数量</span></span><br><span class="line"> <span class="comment">// AtomicInteger failureCount = new AtomicInteger(0); // 统计失败次数</span></span><br><span class="line"> <span class="comment">// long start = System.currentTimeMillis();</span></span><br><span class="line"> <span class="comment">// executor.submit(() -> {</span></span><br><span class="line"> <span class="comment">// try (Connection connection = HikariConfigs.HikariConn();) {</span></span><br><span class="line"> <span class="comment">// for (int i = 0; i < delete_sqls.size(); i++) {</span></span><br><span class="line"> <span class="comment">// Statement statement = connection.createStatement();</span></span><br><span class="line"> <span class="comment">// String deletesql = delete_sqls.get(i);</span></span><br><span class="line"> <span class="comment">// System.out.println("!!!正在删除数据:" + deletesql);</span></span><br><span class="line"> <span class="comment">// // int updateCount = statement.executeUpdate(deletesql);</span></span><br><span class="line"> <span class="comment">// // if (updateCount > -1) {</span></span><br><span class="line"> <span class="comment">// // successCount.incrementAndGet(); // 如果删除成功,增加本地计数器</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// // } else {</span></span><br><span class="line"> <span class="comment">// // failureCount.incrementAndGet();// 如果删除失败</span></span><br><span class="line"> <span class="comment">// // }</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// statement.addBatch(deletesql);</span></span><br><span class="line"> <span class="comment">// successCount.incrementAndGet(); // 如果删除成功,增加本地计数器</span></span><br><span class="line"> <span class="comment">// if (i % 500 == 0) {</span></span><br><span class="line"> <span class="comment">// statement.executeBatch();</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// } catch (SQLException e) {</span></span><br><span class="line"> <span class="comment">// e.printStackTrace();</span></span><br><span class="line"> <span class="comment">// } catch (InterruptedException ex) {</span></span><br><span class="line"> <span class="comment">// ex.printStackTrace();</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// });</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// executor.shutdown(); // 关闭线程池</span></span><br><span class="line"> <span class="comment">// executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); // 等待所有任务完成</span></span><br><span class="line"> <span class="comment">// long end = System.currentTimeMillis();</span></span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"> <span class="type">AtomicInteger</span> <span class="variable">successCount</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">AtomicInteger</span>(<span class="number">0</span>); <span class="comment">// 原子计数器,用于记录成功执行的SQL数量</span></span><br><span class="line"> <span class="type">AtomicInteger</span> <span class="variable">failureCount</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">AtomicInteger</span>(<span class="number">0</span>); <span class="comment">// 统计失败次数</span></span><br><span class="line"></span><br><span class="line"> <span class="type">int</span> <span class="variable">size</span> <span class="operator">=</span> delete_sqls.size();</span><br><span class="line"> <span class="type">int</span> <span class="variable">theadCount</span> <span class="operator">=</span> <span class="number">10</span>;</span><br><span class="line"> <span class="type">int</span> <span class="variable">splitCount</span> <span class="operator">=</span> size / theadCount + (size % theadCount != <span class="number">0</span> ? <span class="number">1</span> : <span class="number">0</span>); <span class="comment">//计算分拆数量,向上取整</span></span><br><span class="line"> <span class="keyword">final</span> <span class="type">CountDownLatch</span> <span class="variable">cdl</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">CountDownLatch</span>(theadCount);<span class="comment">// 定义线程数量</span></span><br><span class="line"> <span class="type">long</span> <span class="variable">starttime</span> <span class="operator">=</span> System.currentTimeMillis();</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">k</span> <span class="operator">=</span> <span class="number">1</span>; k <= theadCount; k++) {</span><br><span class="line"> <span class="keyword">final</span> <span class="type">int</span> <span class="variable">beign</span> <span class="operator">=</span> (k - <span class="number">1</span>) * splitCount;</span><br><span class="line"> <span class="keyword">final</span> <span class="type">int</span> <span class="variable">end</span> <span class="operator">=</span> (k * splitCount) > size ? size : k * splitCount;</span><br><span class="line"> <span class="keyword">if</span>(beign >= end) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">new</span> <span class="title class_">Thread</span>(<span class="keyword">new</span> <span class="title class_">Runnable</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_">run</span><span class="params">()</span> {</span><br><span class="line"> <span class="type">Connection</span> <span class="variable">con</span> <span class="operator">=</span> JDBCTools.getConnection();</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="type">Statement</span> <span class="variable">st</span> <span class="operator">=</span> con.createStatement();</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i < delete_sqls.size(); i++) {</span><br><span class="line"> <span class="type">String</span> <span class="variable">deletesql</span> <span class="operator">=</span> delete_sqls.get(i);</span><br><span class="line"> System.out.println(<span class="string">"!!!正在删除数据:"</span> + deletesql);</span><br><span class="line"> <span class="type">int</span> <span class="variable">count</span> <span class="operator">=</span> st.executeUpdate(deletesql);</span><br><span class="line"> <span class="keyword">if</span> (count > -<span class="number">1</span>) {</span><br><span class="line"> successCount.incrementAndGet();</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> failureCount.incrementAndGet();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> cdl.countDown(); <span class="comment">// 执行完一个线程,递减1</span></span><br><span class="line"> } <span class="keyword">catch</span> (Exception e) {</span><br><span class="line"> } <span class="keyword">finally</span> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> con.close();</span><br><span class="line"> } <span class="keyword">catch</span> (SQLException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }).start();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> cdl.await(); <span class="comment">//前面线程没执行完,其他线程等待,不往下执行</span></span><br><span class="line"> <span class="type">long</span> spendtime=System.currentTimeMillis()-starttime;</span><br><span class="line"> System.out.println( theadCount+<span class="string">"个线程花费时间:"</span>+spendtime);</span><br><span class="line"> } <span class="keyword">catch</span> (InterruptedException e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> }</span><br><span class="line"> <span class="type">long</span> <span class="variable">endtime</span> <span class="operator">=</span> System.currentTimeMillis();</span><br><span class="line"> System.out.println(<span class="string">"已完成删除"</span>);</span><br><span class="line"> System.out.println(<span class="string">"成功删除数据 "</span> + successCount + <span class="string">" 条"</span>);</span><br><span class="line"> System.out.println(<span class="string">"删除失败 "</span> + failureCount + <span class="string">" 条"</span>);</span><br><span class="line"> System.out.println(<span class="string">"消耗的时间为(毫秒):"</span> + (endtime - starttime));</span><br><span class="line"> System.out.println(<span class="string">"消耗的时间为(秒):"</span> + TimeUnit.MILLISECONDS.toSeconds(endtime - starttime));</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>完整的项目git地址:<a href="https://gitee.com/reisen7/doristool">Doris工具</a></p>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Doris </tag>
</tags>
</entry>
<entry>
<title>国内镜像下载node-sass</title>
<link href="/2024/04/21/%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E4%B8%8B%E8%BD%BDnode-sass/"/>
<url>/2024/04/21/%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E4%B8%8B%E8%BD%BDnode-sass/</url>
<content type="html"><![CDATA[<p>npm 下载 gpy(给爷爬)失败,大概率是下载node-sass失败<br>👇👇👇</p><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">npm</span> <span class="string">ERR! path xxx\src\main\webapp\admin\node_modules\node-sass</span></span><br></pre></td></tr></table></figure><p><strong>解决办法</strong></p><p>在项目根目录添加 <em><code>.npmrc</code></em><br>例如:</p><p><img src="/img/posts/b329c4d44eeb5c45c7d1d53e8c3d3d85.png"><br>在里面写如下内容:</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></pre></td><td class="code"><pre><span class="line">registry=https://registry.npmmirror.com</span><br><span class="line">sass_binary_site=https://npmmirror.com/mirrors/node-sass/</span><br><span class="line">phantomjs_cdnurl=https://npmmirror.com/mirrors/phantomjs/</span><br><span class="line">electron_mirror=https://npmmirror.com/mirrors/electron/</span><br><span class="line">sqlite3_binary_host_mirror=http://npmmirror.com/mirrors/</span><br><span class="line">profiler_binary_host_mirror=http://npmmirror.com/mirrors/node-inspector/</span><br><span class="line">chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver</span><br><span class="line">sentrycli_cdnurl=https://npmmirror.com/mirrors/sentry-cli/</span><br></pre></td></tr></table></figure><h2 id="另外需要注意node的版本"><a href="#另外需要注意node的版本" class="headerlink" title="另外需要注意node的版本"></a>另外需要注意node的版本</h2><p>博主使用 14.17.0 能正常下载,使用16就报错了,建议使用nvm管理</p><h3 id="后来经过反复的部署项目,发现node-sass需要和node的版本号相互匹配"><a href="#后来经过反复的部署项目,发现node-sass需要和node的版本号相互匹配" class="headerlink" title="后来经过反复的部署项目,发现node-sass需要和node的版本号相互匹配"></a>后来经过反复的部署项目,发现node-sass需要和node的版本号相互匹配</h3><p><img src="/img/posts/78012a241d234e3fb3263e6f5b0a0dac.png"></p>]]></content>
<categories>
<category> 解决方案 </category>
</categories>
<tags>
<tag> Node </tag>
</tags>
</entry>
<entry>
<title>Vue2:创建一个聊天弹窗</title>
<link href="/2024/04/17/Vue2%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E5%BC%B9%E7%AA%97/"/>
<url>/2024/04/17/Vue2%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E8%81%8A%E5%A4%A9%E5%BC%B9%E7%AA%97/</url>
<content type="html"><![CDATA[<h2 id="创建一个聊天窗口"><a href="#创建一个聊天窗口" class="headerlink" title="创建一个聊天窗口"></a>创建一个聊天窗口</h2><blockquote><p>先创建一个model.vue 该文件作为弹窗的内容</p></blockquote><h3 id="前端代码如下:"><a href="#前端代码如下:" class="headerlink" title="前端代码如下:"></a>前端代码如下:</h3><hr><p>页面部分:</p><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><br><span class="line"><span class="tag"><<span class="name">template</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"model-bg"</span> <span class="attr">v-show</span>=<span class="string">"show"</span> @<span class="attr">mousemove</span>=<span class="string">"modelMove"</span> @<span class="attr">mouseup</span>=<span class="string">"cancelMove"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"model-container"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"model-header"</span> @<span class="attr">mousedown</span>=<span class="string">"setStartingPoint"</span>></span></span><br><span class="line"> {{ title }}</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">div</span> <span class="attr">class</span>=<span class="string">"model-main"</span> <span class="attr">ref</span>=<span class="string">"box"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">v-for</span>=<span class="string">"(item,i) in list"</span> <span class="attr">:key</span>=<span class="string">"i"</span> <span class="attr">:class</span>=<span class="string">"item.id== 2 ? 'atalk' : 'btalk'"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span>></span>{{ item.content }}<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><br><span class="line"> <span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span>></span><span class="tag"></<span class="name">div</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">"wordone"</span> <span class="attr">class</span>=<span class="string">"inputword"</span> @<span class="attr">keyup.enter</span>=<span class="string">"sendmsg1"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">el-button</span> <span class="attr">type</span>=<span class="string">"primary"</span> <span class="attr">round</span> @<span class="attr">click</span>=<span class="string">"sendmsg1"</span> <span class="attr">class</span>=<span class="string">"btnsend"</span>></span>发送<span class="tag"></<span class="name">el-button</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"model-footer"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">el-button</span> <span class="attr">round</span> @<span class="attr">click</span>=<span class="string">"cancel"</span>></span>关闭<span class="tag"></<span class="name">el-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">Loading</span>></span><span class="tag"></<span class="name">Loading</span>></span></span><br><span class="line"></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">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">template</span>></span></span><br><span class="line"></span><br></pre></td></tr></table></figure><ul><li>分为两块:</li><li>上面的 model-main 为聊天信息的内容,其中根据list的id来判断聊天消息在左侧和在右侧</li><li>下面的 text 为聊天的按钮</li></ul><hr><p>js部分</p><figure class="highlight js"><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></pre></td><td class="code"><pre><span class="line"><script></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">Loading</span> <span class="keyword">from</span> <span class="string">"@/views/loading.vue"</span>;<span class="comment">//引用loading组件</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> {</span><br><span class="line"> <span class="attr">props</span>: {</span><br><span class="line"> <span class="attr">show</span>: {</span><br><span class="line"> <span class="attr">type</span>: <span class="title class_">Boolean</span>,</span><br><span class="line"> <span class="attr">default</span>: <span class="literal">false</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">title</span>: {</span><br><span class="line"> <span class="attr">type</span>: <span class="title class_">String</span>,</span><br><span class="line"> <span class="attr">default</span>: <span class="string">'智能助手'</span></span><br><span class="line"> },</span><br><span class="line"> },</span><br><span class="line"> <span class="title function_">data</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="attr">x</span>: <span class="number">0</span>,</span><br><span class="line"> <span class="attr">y</span>: <span class="number">0</span>,</span><br><span class="line"> <span class="attr">node</span>: <span class="literal">null</span>,</span><br><span class="line"> <span class="attr">isCanMove</span>: <span class="literal">false</span>,</span><br><span class="line"></span><br><span class="line"> <span class="attr">list</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">id</span>: <span class="number">1</span>,</span><br><span class="line"> <span class="attr">name</span>: <span class="string">'111'</span>,</span><br><span class="line"> <span class="attr">content</span>: <span class="string">'你好'</span>,</span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">id</span>: <span class="number">2</span>,</span><br><span class="line"> <span class="attr">name</span>: <span class="string">'222'</span>,</span><br><span class="line"> <span class="attr">content</span>: <span class="string">'你好👋,我是你的智能小助手'</span>,</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> <span class="attr">wordone</span>: <span class="string">''</span>,</span><br><span class="line"> <span class="attr">wordtow</span>: <span class="string">''</span>,</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">components</span>: {</span><br><span class="line"> <span class="title class_">Loading</span>,</span><br><span class="line"> },</span><br><span class="line"> <span class="title function_">mounted</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">node</span> = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">'.model-container'</span>)</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">methods</span>: {</span><br><span class="line"> <span class="title function_">sendmsg1</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">list</span>.<span class="title function_">push</span>({ <span class="attr">id</span>: <span class="number">1</span>, <span class="attr">name</span>: <span class="string">'sigtuna'</span>, <span class="attr">content</span>: <span class="variable language_">this</span>.<span class="property">wordone</span> });</span><br><span class="line"> <span class="keyword">var</span> $this = <span class="variable language_">this</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="title function_">getBotContent</span>($this);</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">wordone</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">wordone</span> = <span class="string">''</span>;</span><br><span class="line"> <span class="comment">// console.log(this.list)</span></span><br><span class="line"> <span class="keyword">var</span> div = <span class="variable language_">this</span>.<span class="property">$refs</span>.<span class="property">box</span>;</span><br><span class="line"> <span class="built_in">setTimeout</span>(<span class="function">() =></span> {</span><br><span class="line"> div.<span class="property">scrollTop</span> = div.<span class="property">scrollHeight</span>;</span><br><span class="line"> }, <span class="number">0</span>)</span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> <span class="title function_">getBotContent</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">bus</span>.$emit(<span class="string">"loading"</span>, <span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line"> <span class="variable language_">this</span>.$http({</span><br><span class="line"> <span class="attr">url</span>:<span class="string">"/AiController/query?content="</span>+<span class="variable language_">this</span>.<span class="property">wordone</span>,</span><br><span class="line"> <span class="attr">method</span>:<span class="string">"post"</span></span><br><span class="line"> })</span><br><span class="line"> .<span class="title function_">then</span>(<span class="function"><span class="params">res</span> =></span> {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(res);</span><br><span class="line"> <span class="keyword">if</span>(res.<span class="property">data</span>.<span class="property">code</span> == <span class="number">200</span>){</span><br><span class="line"> <span class="keyword">var</span> data = res.<span class="property">data</span>.<span class="property">msg</span>;</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(data);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">list</span>.<span class="title function_">push</span>({ <span class="attr">id</span>: <span class="number">2</span>, <span class="attr">name</span>: <span class="string">'kanade'</span>, <span class="attr">content</span>: data });</span><br><span class="line"> <span class="keyword">var</span> div = <span class="variable language_">this</span>.<span class="property">$refs</span>.<span class="property">box</span>;</span><br><span class="line"> <span class="built_in">setTimeout</span>(<span class="function">() =></span> {</span><br><span class="line"> div.<span class="property">scrollTop</span> = div.<span class="property">scrollHeight</span>;</span><br><span class="line"> }, <span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">bus</span>.$emit(<span class="string">"loading"</span>, <span class="literal">false</span>);</span><br><span class="line"></span><br><span class="line"> }).<span class="title function_">catch</span>(<span class="function"><span class="params">err</span> =></span> {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">loading</span> = <span class="literal">false</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">$message</span>.<span class="title function_">error</span>(err.<span class="property">message</span>);</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 class="title function_">cancel</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.$emit(<span class="string">'cancel'</span>)</span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> <span class="title function_">submit</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.$emit(<span class="string">'submit'</span>)</span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> <span class="title function_">setStartingPoint</span>(<span class="params">e</span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">x</span> = e.<span class="property">clientX</span> - <span class="variable language_">this</span>.<span class="property">node</span>.<span class="property">offsetLeft</span></span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">y</span> = e.<span class="property">clientY</span> - <span class="variable language_">this</span>.<span class="property">node</span>.<span class="property">offsetTop</span></span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">isCanMove</span> = <span class="literal">true</span></span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> <span class="title function_">modelMove</span>(<span class="params">e</span>) {</span><br><span class="line"> <span class="keyword">if</span> (<span class="variable language_">this</span>.<span class="property">isCanMove</span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">node</span>.<span class="property">style</span>.<span class="property">left</span> = e.<span class="property">clientX</span> - <span class="variable language_">this</span>.<span class="property">x</span> + <span class="string">'px'</span></span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">node</span>.<span class="property">style</span>.<span class="property">top</span> = e.<span class="property">clientY</span> - <span class="variable language_">this</span>.<span class="property">y</span> + <span class="string">'px'</span></span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"></span><br><span class="line"> <span class="title function_">cancelMove</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">isCanMove</span> = <span class="literal">false</span></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"></script></span><br><span class="line"></span><br></pre></td></tr></table></figure><p><em>点击发送,向后端发送请求,然后更新消息list</em></p><hr><p>css部分</p><figure class="highlight css"><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></pre></td><td class="code"><pre><span class="line"><style scoped></span><br><span class="line"><span class="selector-class">.model-bg</span> {</span><br><span class="line"> <span class="attribute">position</span>: fixed;</span><br><span class="line"> <span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, .<span class="number">5</span>);</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">10</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.model-container</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">#fff</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">position</span>: fixed;</span><br><span class="line"> <span class="attribute">top</span>: <span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">left</span>: <span class="number">50%</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">500px</span>;</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">translate</span>(-<span class="number">50%</span>, -<span class="number">50%</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.model-header</span> {</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">56px</span>;</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">#409EFF</span>;</span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#fff</span>;</span><br><span class="line"> <span class="attribute">display</span>: flex;</span><br><span class="line"> <span class="attribute">align-items</span>: center;</span><br><span class="line"> <span class="attribute">justify-content</span>: center;</span><br><span class="line"> <span class="attribute">cursor</span>: move;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.model-footer</span> {</span><br><span class="line"> <span class="attribute">display</span>: flex;</span><br><span class="line"> <span class="attribute">align-items</span>: center;</span><br><span class="line"> <span class="attribute">justify-content</span>: center;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">57px</span>;</span><br><span class="line"> <span class="attribute">border-top</span>: <span class="number">1px</span> solid <span class="number">#ddd</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.model-footer</span> <span class="selector-tag">button</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.model-main</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">300px</span>;</span><br><span class="line"> <span class="attribute">overflow</span> : auto;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.main</span> {</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">85%</span>;</span><br><span class="line"> <span class="attribute">overflow</span>: scroll;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">div</span>::-webkit-scrollbar {</span><br><span class="line"> <span class="attribute">display</span>: none;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.atalk</span> {</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">10px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.atalk</span> <span class="selector-tag">span</span> {</span><br><span class="line"> <span class="attribute">display</span>: inline-block;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">3px</span> <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">1px</span> solid aliceblue;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">5px</span> <span class="number">10px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.btalk</span> {</span><br><span class="line"> <span class="attribute">text-align</span>: right;</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">10px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.btalk</span> <span class="selector-tag">span</span> {</span><br><span class="line"> <span class="attribute">display</span>: inline-block;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">3px</span> <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">1px</span> solid aliceblue;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">15px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.sendbox</span> {</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">50px</span>;</span><br><span class="line"> <span class="attribute">border-bottom-left-radius</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">border-bottom-right-radius</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">margin-top</span>: <span class="number">5px</span>;</span><br><span class="line"> <span class="attribute">margin-left</span>: <span class="number">2%</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.inputword</span> {</span><br><span class="line"> <span class="attribute">outline</span>: none;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">80%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">25px</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">text-indent</span>: <span class="number">12px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.btnsend</span> {</span><br><span class="line"> <span class="attribute">align-items</span>: center;</span><br><span class="line"> <span class="attribute">justify-content</span>: center;</span><br><span class="line">}</style></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>通过想后端发送请求,可以实现在线聊天功能,也可以通过接入AI来实现客服对话功能</p></blockquote><hr><h3 id="后代码如下:"><a href="#后代码如下:" class="headerlink" title="后代码如下:"></a>后代码如下:</h3><p>service层</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><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></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ApiService</span> {</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Value("${ai-key}")</span></span><br><span class="line"> <span class="keyword">private</span> String apiKey;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">query</span><span class="params">(String queryMessage)</span> {</span><br><span class="line"> Constants.apiKey = apiKey;</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="type">Generation</span> <span class="variable">gen</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Generation</span>();</span><br><span class="line"> <span class="type">MessageManager</span> <span class="variable">msgManager</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MessageManager</span>(<span class="number">10</span>);</span><br><span class="line"> <span class="type">Message</span> <span class="variable">systemMsg</span> <span class="operator">=</span> Message.builder().role(Role.SYSTEM.getValue()).content(<span class="string">"你是Hibiki开发的智能助手,你只回答与动漫的问题,不要回答其他问题!"</span>).build();</span><br><span class="line"> <span class="type">Message</span> <span class="variable">userMsg</span> <span class="operator">=</span> Message.builder().role(Role.USER.getValue()).content(queryMessage).build();</span><br><span class="line"> msgManager.add(systemMsg);</span><br><span class="line"> msgManager.add(userMsg);</span><br><span class="line"> <span class="type">QwenParam</span> <span class="variable">param</span> <span class="operator">=</span> QwenParam.builder().model(Generation.Models.QWEN_TURBO).messages(msgManager.get()).resultFormat(QwenParam.ResultFormat.MESSAGE).build();</span><br><span class="line"> <span class="type">GenerationResult</span> <span class="variable">result</span> <span class="operator">=</span> gen.call(param);</span><br><span class="line"> <span class="type">GenerationOutput</span> <span class="variable">output</span> <span class="operator">=</span> result.getOutput();</span><br><span class="line"> <span class="type">Message</span> <span class="variable">message</span> <span class="operator">=</span> output.getChoices().get(<span class="number">0</span>).getMessage();</span><br><span class="line"> <span class="keyword">return</span> message.getContent();</span><br><span class="line"> } <span class="keyword">catch</span> (Exception e) {</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"智能助手现在不在线,请稍后再试~"</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>通过阿里的通义千问大模型,可以实现在线的对话机器人功能<br>也能自定义模型的回答类型,非常实用</p></blockquote><h3 id="所需的依赖"><a href="#所需的依赖" class="headerlink" title="所需的依赖"></a>所需的依赖</h3><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><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><br><span class="line"><span class="comment"><!--GSON --></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>com.google.code.gson<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>gson<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>2.9.1<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><span class="line"></span><br><span class="line"><span class="comment"><!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java --></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>com.alibaba<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>dashscope-sdk-java<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">exclusions</span>></span></span><br><span class="line"><span class="tag"><<span class="name">exclusion</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.slf4j<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>slf4j-simple<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">exclusion</span>></span></span><br><span class="line"><span class="tag"></<span class="name">exclusions</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>2.9.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><span class="line"></span><br><span class="line"><span class="comment"><!--ok http client--></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>com.squareup.okhttp3<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>okhttp<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>4.10.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><span class="line"></span><br></pre></td></tr></table></figure><p><strong>其中阿里的sdk会有依赖冲突,exclusion看情况添加</strong></p><h3 id="在所需页面里引入弹窗"><a href="#在所需页面里引入弹窗" class="headerlink" title="在所需页面里引入弹窗"></a>在所需页面里引入弹窗</h3><pre><code class="html"><template> <div class="navbar"> <div :style='{ "cursor": "pointer", "margin": "0 5px", "lineHeight": "44px", "color": "#fff" }' class="logout" @click="diaglog">智能助手</div> <Model :show="show" @cancel="cancel" @submit="submit"></Model> </div></template><script>import Model from '@/views/model.vue'export default { data() { return { show: false, }; }, created() { }, components: { Model }, mounted() { }, methods: { cancel() { // 取消弹窗回调 this.show = false }, submit() { // 确认弹窗回调 this.show = false }, diaglog() { this.show = true; }, onLogout() { let storage = this.$storage let router = this.$router storage.clear() router.replace({ name: "login" }); }, onIndexTap() { window.location.href = `${this.$base.indexUrl}` }, }};</script><style lang="scss" scoped>.navbar {}</style></code></pre>]]></content>
<categories>
<category> 代码 </category>
</categories>
<tags>
<tag> Vue </tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<link href="/2024/04/15/hello-world/"/>
<url>/2024/04/15/hello-world/</url>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p><h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p><h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p><h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p><h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>]]></content>
</entry>
<entry>
<title>vscode配置</title>
<link href="/2023/09/26/vscode%E9%85%8D%E7%BD%AE/"/>
<url>/2023/09/26/vscode%E9%85%8D%E7%BD%AE/</url>
<content type="html"><![CDATA[<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><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></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> "workbench.iconTheme": "material-icon-theme",</span><br><span class="line"> "editor.guides.bracketPairs": true,</span><br><span class="line"> "workbench.colorCustomizations": {</span><br><span class="line"></span><br><span class="line"> },</span><br><span class="line"> "editor.codeActionsOnSave": {</span><br><span class="line"> </span><br><span class="line"> },</span><br><span class="line"> "files.autoSave": "afterDelay",</span><br><span class="line"> // 代理配置</span><br><span class="line"> // "http.proxy": "",</span><br><span class="line"> // "http.proxyStrictSSL": false,</span><br><span class="line"> // "http.proxySupport": "on",</span><br><span class="line"></span><br><span class="line"> // springboot 配置</span><br><span class="line"> "java.jdt.ls.java.home":"d:\\etc\\jdk-17.0.8.7-hotspot",</span><br><span class="line"> "java.configuration.maven.userSettings": "D:\\usr\\apache-maven-3.9.4\\conf\\settings.xml",</span><br><span class="line"> "java.configuration.maven.globalSettings": "D:\\usr\\apache-maven-3.9.4\\conf\\settings.xml",</span><br><span class="line"> "maven.executable.path": "D:\\usr\\apache-maven-3.9.4\\bin\\mvn.cmd",</span><br><span class="line"></span><br><span class="line"> "maven.excludedFolders": [</span><br><span class="line"></span><br><span class="line"> "**/.*",</span><br><span class="line"> "**/node_modules",</span><br><span class="line"> "**/target",</span><br><span class="line"> "**/bin",</span><br><span class="line"> "**/archetype-resources"</span><br><span class="line"> ],</span><br><span class="line"> "extensions.autoUpdate": false,</span><br><span class="line"> "redhat.telemetry.enabled": true,</span><br><span class="line"></span><br><span class="line"> // java</span><br><span class="line"> "java.configuration.runtimes": [</span><br><span class="line"></span><br><span class="line"> {</span><br><span class="line"> "name": "JavaSE-1.8",</span><br><span class="line"> "path": "D:\\etc\\jdk-1.8",</span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> "name": "JavaSE-11",</span><br><span class="line"> "path": "D:\\etc\\jdk-11.0.20.8-hotspot",</span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> "name": "JavaSE-17",</span><br><span class="line"> "path": "D:\\etc\\jdk-17.0.8.7-hotspot",</span><br><span class="line"> "default": true</span><br><span class="line"> },</span><br><span class="line"> ],</span><br><span class="line"> "boot-java.rewrite.reconcile": true,</span><br><span class="line"> "security.workspace.trust.untrustedFiles": "open",</span><br><span class="line"> "remote.SSH.remotePlatform": {</span><br><span class="line"> "60.204.200.91": "linux"</span><br><span class="line"> },</span><br><span class="line"> "workbench.colorTheme": "Default Dark+",</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> VsCode </tag>
</tags>
</entry>
<entry>
<title>普罗米修斯</title>
<link href="/2023/08/01/%E6%99%AE%E7%BD%97%E7%B1%B3%E4%BF%AE%E6%96%AF/"/>
<url>/2023/08/01/%E6%99%AE%E7%BD%97%E7%B1%B3%E4%BF%AE%E6%96%AF/</url>
<content type="html"><![CDATA[]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> Prometheus </tag>
</tags>
</entry>
<entry>
<title>Java 入门基础(一)</title>
<link href="/2023/02/24/Java_%E5%85%A5%E9%97%A8/"/>
<url>/2023/02/24/Java_%E5%85%A5%E9%97%A8/</url>
<content type="html"><![CDATA[<h1 id="javaSE基础"><a href="#javaSE基础" class="headerlink" title="javaSE基础"></a>javaSE基础</h1><h2 id="javaSe-整体大纲"><a href="#javaSe-整体大纲" class="headerlink" title="javaSe 整体大纲"></a>javaSe 整体大纲</h2><ol><li>java基础 (循环,数组)</li><li>OOP</li><li>API</li></ol><h2 id="基础"><a href="#基础" class="headerlink" title="基础"></a>基础</h2><ul><li>编程的本质=数据结构+算法</li><li>什么是编程:就是让计算机按自己的意图去工作</li></ul><h2 id="编程语言的发展史(了解)"><a href="#编程语言的发展史(了解)" class="headerlink" title="编程语言的发展史(了解)"></a>编程语言的发展史(了解)</h2><ol><li>机器语言:0101</li><li>汇编语言: 助记符</li><li>高级语言:java,c,c++,python,basic</li></ol><h2 id="为什么是java"><a href="#为什么是java" class="headerlink" title="为什么是java"></a>为什么是java</h2><p>流行的语言:</p><ul><li>java,python,c,C++,javascript,go…..</li><li>语言没有好坏之分,只有适不适用?</li></ul><p>厨房中的刀,哪把刀更好:砍刀,切菜刀,西瓜刀,水果刀?</p><ul><li>每个语言都有适用的场景</li><li>数据分析:python,</li><li>3D游戏:C++ </li><li>前端页面:javascript</li><li>应用程序的后台:java</li></ul><h2 id="回顾"><a href="#回顾" class="headerlink" title="回顾"></a>回顾</h2><p>1.学习方法:编码-》巩固-》检索 3F:focus->feedback->fix<br>2.课程 se:1.基础 2.oop,3API<br>3.编程的基础: 数据结构+算法=程序<br>4.编程语言的发展史</p><ol><li>机器语言</li><li>汇编语言</li><li>高级语言</li></ol><p>5.java</p><ul><li>企业后台</li><li>安卓</li><li>大数据</li><li>桌面</li></ul><p>6.java语言的发展史</p><h2 id="java语言的发展"><a href="#java语言的发展" class="headerlink" title="java语言的发展"></a>java语言的发展</h2><p>高斯林(高司令):嵌入式程序</p><p>99年,三个版本:javase,javame,javaee</p><ul><li>LTS</li><li>JDK8</li><li>JDK11</li><li>JDK17</li></ul><h2 id="java-语言的特点"><a href="#java-语言的特点" class="headerlink" title="java 语言的特点"></a>java 语言的特点</h2><ul><li>面向对象</li><li>简单</li><li>跨平台</li></ul><h2 id="java语言的三个版本"><a href="#java语言的三个版本" class="headerlink" title="java语言的三个版本"></a>java语言的三个版本</h2><ul><li>A:javaSE:标准版本:基础,桌面级应用</li><li>B:javaEE:企业版:服务器端的大网络,分布式</li><li>C:javaME:微型版本:嵌入式设备,小设备</li></ul><p><img src="https://s3.bmp.ovh/imgs/2023/02/24/1a4a6b994af3b594.png"></p><h2 id="环境安装"><a href="#环境安装" class="headerlink" title="环境安装"></a>环境安装</h2><h3 id="JDK"><a href="#JDK" class="headerlink" title="JDK"></a>JDK</h3><blockquote><p>java development kid:java开发包</p><p>作用:开发,运行java程序</p><p><strong>JRE</strong>:java runtime environmentjava 运行环境</p><p>作用:运行java程序</p><p>JDK包含了JRE</p><p><strong>JVM</strong>:java virtual machine:java虚拟机</p><p>作用:用来运行java程序 不包含类库和命令</p><p>JDK中包含了JRE,JRE中包含了JVM</p></blockquote><h2 id="安装JDK"><a href="#安装JDK" class="headerlink" title="安装JDK"></a>安装JDK</h2><p>建议:安装 11,8,</p><p>安装注意事项</p><ol><li>傻瓜式安装,按步骤来就行</li><li>安装路径不要有空格,不要使用中文路径 </li><li>安装后会有两个目录<ul><li>bin:包含了java命令:javac(编译),java(运行),javadoc(生成文档)</li><li>lib:包含了java类库</li></ul></li></ol><p>配置:</p><blockquote><p>配置环境变量?</p></blockquote><h2 id="DOS命令"><a href="#DOS命令" class="headerlink" title="DOS命令"></a>DOS命令</h2><p>DOS:disk operation system:命令行 </p><blockquote><p>命令:</p></blockquote><ul><li><p>cd:改变目录</p></li><li><p>dir:查看当前目录下的内容</p></li><li><p>盘符:切换到其它盘,例如 D:</p></li><li><p>d:切换到D盘</p></li><li><p>cd ..:切换到上层目录</p></li><li><p>cd bin:进入取bin子目录</p></li><li><p>dir:显示当前目录中的内容 </p><blockquote><p>问题?<br>java.exe,javac.exe在 d:/java/jdk-11.0.8/bin下,如果想使用java,javac命令,必须先进入到d:/java/jdk-11.0.8/bin下才可以使用,如果希望在任何一个目录下都使用此命令,则需要配置环境变量才可以 </p><p>环境变量中有一个叫path的<br>path的作用是,当运行一个命令时,先从当前路径找,如找不到,再去path中找 </p><p>如果在path中设置一个值 d:/java/jdk-11.0.8/bin<br>当我们在 e:盘下,运行 java</p></blockquote></li><li><p>1.先在 e:/下找java</p></li><li><p>2.如找不到,再到path下找</p></li></ul><blockquote><p>环境变量<br>path:路径<br>classpath:类路径 .d:/java/jdk-11.0.8/lib</p></blockquote><p>window: 图形界面</p><p>android:图形</p><p>linux:有图形 </p><h2 id="第一个java程序"><a href="#第一个java程序" class="headerlink" title="第一个java程序"></a>第一个java程序</h2><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="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</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_">main</span><span class="params">(String[] args)</span>{</span><br><span class="line">System.out.println(<span class="string">"这是我的第一个java程序,我好高兴呀,今天晚上给自己加一个鸡腿吧"</span>);</span><br><span class="line">}</span><br><span class="line">}</span><br></pre></td></tr></table></figure><ol><li>HelloWorld:是类名,类名必须要与文件名相同 (HelloWorld.java</li><li>System.out.println(“”):代表输出 “”中可以写任何字符串 </li><li>所有的标点符号都是英文半角 </li><li>java是区分大小写的</li></ol><p></p><h2 id="HelloWorld详解"><a href="#HelloWorld详解" class="headerlink" title="HelloWorld详解"></a>HelloWorld详解</h2><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Hello</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_">main</span><span class="params">(String[] args)</span>{</span><br><span class="line"> </span><br><span class="line"> System.out.println();</span><br><span class="line"> } </span><br><span class="line">}</span><br><span class="line"><span class="comment">//Hello是类名</span></span><br><span class="line"><span class="comment">//public static void main(String[] args):是主函数,程序的入口,如果想直接运行此类,必须有此方法 </span></span><br><span class="line"><span class="comment">//System.out.println();输出内容后换行</span></span><br><span class="line"><span class="comment">//System.out.print();输出内容后不换行</span></span><br><span class="line"><span class="comment">//无论是print还是println都只能输出一个内容,内容可以是字符串,数字,布尔等等 </span></span><br><span class="line"></span><br><span class="line"><span class="comment">//9+9 </span></span><br><span class="line"><span class="comment">//"hello"+"hello"+9</span></span><br></pre></td></tr></table></figure><h2 id="java命令"><a href="#java命令" class="headerlink" title="java命令"></a>java命令</h2><blockquote><p>javac:编译<br>java:运行<br>javadoc:生成文档</p></blockquote><blockquote><p>javac语法</p><p>javac 文件名.java<br>javac HelloWorld.java<br>作用:将.java的源代码编译成.class文件,如果代码有错误,将无法完成编译 </p></blockquote><blockquote><p>java 语法</p><p>java 类名<br>java HelloWorld<br>注意:千万不要写.class<br>作用:运行java类,要求此类必须有主函数 </p></blockquote><blockquote><p>javadoc:生成文档<br>javadoc 类名.java</p></blockquote><h2 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h2><blockquote><p>作用:为了让程序员更容易理解代码的含义,可以使用注释加以说明 注释不会影响代码的运行</p><p>注释有三种 </p><p>//:单行<br>/* <em>/:块注释<br>/</em>* */:文档注释</p></blockquote><h1 id="java编程基础"><a href="#java编程基础" class="headerlink" title="java编程基础"></a>java编程基础</h1><h2 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h2><ul><li><p>什么是关键字:在java语言有,有特殊含义的一些单词就是关键字 </p></li><li><p>关键字的特点:全部都有小写</p></li></ul><h2 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h2><ul><li>什么标识符:用来标识某种东西的符号就是标识符</li></ul><blockquote><p>比如:类,方法名,变量名,参数名,</p></blockquote><p>定义标识符的规则</p><ul><li><p>标识符中可包含字母,数字,_,$,中文也可以(不建议)</p></li><li><p>不能以数字开头</p></li><li><p>不能是关键字</p></li><li><p>长度无限制,最好做到“见名知义”</p><p> </p></li></ul><p></p><h2 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h2><p>变量:就是内存中的一个区域,为了便于使用,需要给变量起个名字</p><p>变量用法:</p><ol><li><p>变量一定要先定义,再使用</p></li><li><p>定义变量的格式是 </p><blockquote><p>数据类型 变量名=初始值</p></blockquote></li><li><p>变量的值是可以改变的</p></li><li><p>在一个作用域中,变量名是不能重复的</p></li></ol><h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><p>java的数据类型分为两大类,分别是</p><ul><li>基本数据类型</li><li>引用数据类型<ul><li>类,接口,数组</li></ul></li></ul><h3 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h3><ul><li><p>整数</p><ul><li>byte :1</li><li>short:1</li><li>int :2</li><li>long:2</li></ul></li><li><p>浮点数</p><ul><li>float:45.6f</li><li>double:444.4</li></ul></li><li><p>字符</p><ul><li>char ‘a’</li></ul></li><li><p>布尔</p><ul><li>boolean :true,false</li></ul></li></ul><h4 id="整数:"><a href="#整数:" class="headerlink" title="整数:"></a>整数:</h4><ul><li><p>byte:1个字节</p><ul><li><p>位(bit)</p><p>01:bit,每个一个bit只能存储两个值 </p><p>一个字节等于8位二进制</p><blockquote><p>10101011</p></blockquote><p>byte = -128~127;</p></li></ul><p></p></li><li><p>short:2个字节</p></li><li><p>int:4个字节</p></li><li><p>long:8个字节</p></li></ul><h4 id="关于容量的换算关系"><a href="#关于容量的换算关系" class="headerlink" title="关于容量的换算关系"></a>关于容量的换算关系</h4><p>字节 B byte</p><p>1KB->1024B</p><p>1MB->1024KB</p><p>1GB->1024MB</p><p>1TB->1024GB</p><p>1PB->1024TB</p><h4 id="进制的转换"><a href="#进制的转换" class="headerlink" title="进制的转换"></a>进制的转换</h4><blockquote><p>1.10进制-》二进制<br> 除2取余法 </p><p>2.二进制-》十进制<br> 乘权相加法<br> 110101<br> 1+4+16+32=53<br>3.二进制-》十六进制<br> 1011 1010<br> B A<br> 100011111<br>4.十六进制-》二进制<br> 6E-》</p></blockquote><h3 id="字面值(literal)"><a href="#字面值(literal)" class="headerlink" title="字面值(literal)"></a>字面值(literal)</h3><p>字面值也叫直接量 </p><blockquote><p>1.整数的字面值的类型默认为是int<br>2.十六进制 0x开头<br>3.八进制以0开头,例如 int a=011<br>4.如果想表示一个long值,可以使用 L结尾,例如 long a=12312312399L</p></blockquote><h3 id="浮点型"><a href="#浮点型" class="headerlink" title="浮点型"></a>浮点型</h3><table><thead><tr><th></th><th>字节</th><th>范围</th></tr></thead><tbody><tr><td>float</td><td>4</td><td>-3.403E38 ~ 3.403E38</td></tr><tr><td>double</td><td>8</td><td>-1.798E308 ~ 1.798E308</td></tr></tbody></table><blockquote><p>总结<br>1.浮点数只能表示出一个近似数,而不能表示出一个准确的数<br>2.浮点数的字值的类型是double,如果想表示一个float,应该使用 F结尾 </p></blockquote><h3 id="字符型"><a href="#字符型" class="headerlink" title="字符型"></a>字符型</h3><p>用 一对‘’引起的单个字符就是字符,字符可以以数字,英文字母,标点符号,还可以表示任何语言的单字符 例如,中文,法文,俄文,日文 </p><blockquote><p>每个字符存储时,都会转换成与之对应的数字<br>字符与数字之间的对应关系就是一种字符集 UTF-8 GBK,GB2312<br>char有三种表示方式<br>1.‘’<br>2.‘\转义字符’ ,例如 ‘\n’:换行<br>3.unicode码 ‘\uXXXX’</p></blockquote><h3 id="boolean"><a href="#boolean" class="headerlink" title="boolean"></a>boolean</h3><blockquote><p>boolean叫布尔<br>只有两个值,分别是true,false<br>通常来说,可以使用boolean来存储一个状态 </p><p>是否打开音乐<br>boolean isMusic=false</p></blockquote><h3 id="String类型"><a href="#String类型" class="headerlink" title="String类型"></a>String类型</h3><blockquote><p>String代表字符串,即用双引号引起的多个字符序列<br>String不是基本数据类型,而是一种引用类型 </p><p>String name=”刘备”</p></blockquote><h2 id="java代码三级跳"><a href="#java代码三级跳" class="headerlink" title="java代码三级跳"></a>java代码三级跳</h2><blockquote><p>1.表达式<br> 类似于语文中的汉字,词组,例如 a+b,c*d<br>2.语句<br> 类似于语文中的句子。以 号结束 一个语句中会包含多个表达式,</p><p> int a=5;<br>int b=a+b;<br>c=sum+a;<br>3.代码段<br>相当于语文的作文,一个代码段中包含多个语句 </p></blockquote><h2 id="数据类型的转换"><a href="#数据类型的转换" class="headerlink" title="数据类型的转换"></a>数据类型的转换</h2><blockquote><p>两种转换<br>1.自动转换:低精度向高精度可以自动转换,安全<br>2.强制转换:高精度向低精度转换时可以采用强制转换,强转可能会造成精度丢失 </p></blockquote><blockquote><p>数值类的的精度<br>byte->short->int->long->float->double<br> char</p></blockquote><h4 id="自动类型转换发生在两种情况"><a href="#自动类型转换发生在两种情况" class="headerlink" title="自动类型转换发生在两种情况"></a>自动类型转换发生在两种情况</h4><ul><li>赋值</li><li>运算</li></ul><h4 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h4><ul><li>高精度向低精度转换时,可使用强转</li><li>强转的语法是 (数据类型) 例如 long b=6677; int a=(int)b;</li></ul><h2 id="Scanner"><a href="#Scanner" class="headerlink" title="Scanner"></a>Scanner</h2><blockquote><p>//有交互的程序<br>交互的方式主要用两种<br>1.命令行<br>2.图形<br>Scanner叫扫描器,他可以接收用户输入的数据 例如数字,字符串,布尔值等 </p></blockquote><blockquote><p>使用Scanner的步骤<br>1.导包 import java.util.*<br>2.创建Scanner对象<br> Scanner s=new Scanner(System.in)<br>3.接收数据<br> int a=s.nextInt()</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><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*; <span class="comment">//1.导包</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Circle</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><br><span class="line"><span class="comment">//2.创建一个扫描器 </span></span><br><span class="line">Scanner scanner=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"></span><br><span class="line">System.out.println(<span class="string">"请输入半径"</span>);</span><br><span class="line"><span class="comment">//3.接收一个半径</span></span><br><span class="line"><span class="type">double</span> r=scanner.nextDouble();</span><br><span class="line"></span><br><span class="line"><span class="type">double</span> area=r*r*<span class="number">3.14</span>;</span><br><span class="line"></span><br><span class="line">System.out.println(<span class="string">"圆的面积是:"</span>+area);</span><br><span class="line">}</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><p> 运算符可以有两种分在方式</p><ol><li>功能<ul><li>算术运算符</li><li>赋值运算符</li><li>比较运算符</li><li>位运算符</li><li>逻辑运算符</li><li>条件(三元)运算符</li></ul></li><li>操作数的个数<ul><li>一元操作符: ++b, </li><li>二元操作符: a+b</li><li>三元操作符 a>b?a:b</li></ul></li></ol><h3 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</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></pre></td><td class="code"><pre><span class="line">++,--</span><br><span class="line">可以放在操作数之前,也可以放在操作数之后 </span><br><span class="line"></span><br><span class="line">a++操作符有作用 </span><br><span class="line"><span class="number">1.</span>对a做一个加操作 </span><br><span class="line"><span class="number">2.</span>a++也是一个表达式,即将表达式的结果赋给一个变量 </span><br><span class="line">b=a++;</span><br><span class="line">b=++a;</span><br><span class="line"></span><br><span class="line">a++;</span><br><span class="line">++a;</span><br></pre></td></tr></table></figure><h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</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></pre></td><td class="code"><pre><span class="line">=</span><br><span class="line">例如: a=<span class="number">9</span>+<span class="number">8</span>;</span><br><span class="line">特点:</span><br><span class="line"><span class="number">1.</span>操作符的结合性是从右到左 </span><br><span class="line"><span class="number">2.</span>操作符左侧一定是一个变量 </span><br></pre></td></tr></table></figure><h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符"></a>比较运算符</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></pre></td><td class="code"><pre><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"><span class="keyword">instanceof</span></span><br><span class="line"></span><br><span class="line">所有比较运算符的计算结果的类型都是<span class="type">boolean</span>; <span class="literal">true</span>,<span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line">注意,</span><br><span class="line">=是赋值</span><br><span class="line">==是比较 </span><br></pre></td></tr></table></figure><h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</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><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></pre></td></tr></table></figure> <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="number">1</span> & 表达式<span class="number">2</span> </span><br><span class="line">表达式<span class="number">1</span> && 表达式<span class="number">2</span> </span><br></pre></td></tr></table></figure><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><br><span class="line"> 即,两个表达式的结果同时为<span class="literal">true</span>时,与后的结果才<span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line">或: | ||</span><br><span class="line">作用:两个操作数的结果,只要有一个为<span class="literal">true</span>,那么或的结果就为<span class="literal">true</span>;</span><br><span class="line">非:</span><br><span class="line">取反 </span><br><span class="line">!<span class="literal">true</span>;=<span class="literal">false</span>;</span><br><span class="line">!<span class="literal">false</span>:=<span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line">异或:</span><br><span class="line">作用:两个操作数不同时为<span class="literal">true</span>,否则为<span class="literal">false</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure><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></pre></td><td class="code"><pre><span class="line">&,&&的区别?</span><br><span class="line">&,&&都是逻辑与,计算的结果是相同的 但运算的过程是有区别的?</span><br><span class="line">例如</span><br><span class="line">a&&b;</span><br><span class="line">假如,a的结果是<span class="literal">false</span>;那么是否需要计算b,才知道整个表达式的结果 </span><br><span class="line"></span><br><span class="line">区别:</span><br><span class="line">&:无论第一个操作数结果是什么,都会计算所有表达式 </span><br><span class="line">&&:如果第一个操作数的结果是<span class="literal">false</span>,那么将不会计算第二个表达式 </span><br></pre></td></tr></table></figure><h3 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</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></pre></td><td class="code"><pre><span class="line">操作对象:整数(<span class="type">byte</span>,<span class="type">short</span>,<span class="type">int</span>,<span class="type">long</span>) </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"></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"><span class="number">895</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="条件运算符"><a href="#条件运算符" class="headerlink" title="条件运算符"></a>条件运算符</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></pre></td><td class="code"><pre><span class="line">语法</span><br><span class="line">布尔表达式?表达式<span class="number">1</span>:表达式<span class="number">2</span> </span><br><span class="line"><span class="type">int</span> c=a>b?a:b;</span><br></pre></td></tr></table></figure><h1 id="Java进阶"><a href="#Java进阶" class="headerlink" title="Java进阶"></a>Java进阶</h1><h2 id="流程控制"><a href="#流程控制" class="headerlink" title="流程控制"></a>流程控制</h2><blockquote><p>三种<br>顺序结构<br>分支(选择)结构:branch<br>循环结构:loop</p></blockquote><blockquote><p>顺序:<br> 程序从上到下,依次执行 </p></blockquote><h2 id="分支语句"><a href="#分支语句" class="headerlink" title="分支语句"></a>分支语句</h2><p>分支语句分为if,switch</p><h2 id="if语句"><a href="#if语句" class="headerlink" title="if语句"></a>if语句</h2><h3 id="单分支"><a href="#单分支" class="headerlink" title="单分支"></a>单分支</h3><p>语法</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式){</span><br><span class="line"> 语句块 </span><br><span class="line">}</span><br><span class="line">。。</span><br></pre></td></tr></table></figure><blockquote><p>适用场景:<br> 为程序增加一个可能执行的代码,此代码有可能执行,有可能不执行 </p></blockquote><h3 id="双分支"><a href="#双分支" class="headerlink" title="双分支"></a>双分支</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式){</span><br><span class="line"> 语句块<span class="number">1</span> </span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"> 语句块<span class="number">2</span> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="多分支"><a href="#多分支" class="headerlink" title="多分支"></a>多分支</h3><p>语法</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><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式){</span><br><span class="line"> </span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(布尔表达式<span class="number">2</span>){</span><br><span class="line"> </span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(布尔表达式<span class="number">3.</span>。。。){</span><br><span class="line"> </span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><blockquote><p>关于if的小结<br>1.完整的if语句中,包含 if-else if-else<br>2.if语法中,if是必须存在的, else if可有0到n个,可以有0到1个else<br>3.如果存在else,else一定放在最后<br>4.多分支语句中,最多只能执行一个分支,执行此分支后,分支语句结束 </p></blockquote><h3 id="if的嵌套"><a href="#if的嵌套" class="headerlink" title="if的嵌套"></a>if的嵌套</h3><blockquote><p>在一个分支语句块中包含另一个分支语句<br>适用场景:适合解决较为复杂的逻辑问题 </p></blockquote><blockquote><p>例如:<br> 登录<br> 1.成功 用户名,密码,验证码<br> 2.失败<br> 1.验证码?<br> 2.用户名,或密码错误,但少于3次<br> 3.用户名,或密码错误,但大于等于3次 锁定(1个小时) </p></blockquote><p>语法</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(条件){</span><br><span class="line">System.out.println();</span><br><span class="line">i++;</span><br><span class="line"><span class="keyword">if</span>(){</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(条件){</span><br><span class="line"><span class="keyword">if</span>(){</span><br><span class="line"></span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="if语句的简化"><a href="#if语句的简化" class="headerlink" title="if语句的简化"></a>if语句的简化</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果if语句块中只包含一行代码,那么{}可以省略,(但不建议省略)</span></span><br><span class="line"><span class="keyword">if</span>(<span class="literal">true</span>)</span><br><span class="line">System.out.println(<span class="string">"ok"</span>);</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">System.out.println(<span class="string">"else"</span>);</span><br></pre></td></tr></table></figure><h3 id="switch-语句"><a href="#switch-语句" class="headerlink" title="switch 语句"></a>switch 语句</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line"><span class="keyword">switch</span>(表达式){</span><br><span class="line"><span class="keyword">case</span> 值<span class="number">1</span>:</span><br><span class="line">语句;</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> 值<span class="number">2</span>:</span><br><span class="line">语句;</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">语句<span class="number">3</span> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><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">//输入一个成绩 5,4,3,2,1,0 </span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>关于break;<br>在switch语句中,如果case 没有break,那么将会穿透 </p></blockquote><blockquote><p>解决问题<br>输入月份,判断此月有多少天?<br>2:28,29<br>1,3,5,7,8,10,12:31<br>4,6,9,11:30</p><p>case:<br> 2,<br> 4,<br> 6,<br> 9,11</p><p>default:</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Switch2</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><br><span class="line">Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"></span><br><span class="line">System.out.println(<span class="string">"输入月份"</span>);</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> month=s.nextInt();</span><br><span class="line"></span><br><span class="line"><span class="keyword">switch</span>(month){</span><br><span class="line"><span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">System.out.println(<span class="string">"28或29天"</span>);</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line"><span class="keyword">case</span> <span class="number">6</span>:</span><br><span class="line"><span class="keyword">case</span> <span class="number">9</span>:</span><br><span class="line"><span class="keyword">case</span> <span class="number">11</span>:</span><br><span class="line">System.out.println(<span class="string">"30天"</span>);</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">System.out.println(<span class="string">"31天"</span>);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br></pre></td></tr></table></figure><blockquote><p>使用switch的注意事项<br>1.switch只能使用等值比较,而且对数据类型有要求(byte,short,int,char,String)<br>2.注意 case穿透 (break)<br>3.switch的结果清晰,但没有if应用的广泛 </p></blockquote><h2 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h2><blockquote><p>语法很简单,练习是关键</p></blockquote><h3 id="循环语句的三个部分"><a href="#循环语句的三个部分" class="headerlink" title="循环语句的三个部分"></a>循环语句的三个部分</h3><blockquote><p>1.初始化部分(1次)<br>2.条件部分(多次)<br>3.循环体部分 (多次)</p></blockquote><h3 id="java中,循环语句的分类"><a href="#java中,循环语句的分类" class="headerlink" title="java中,循环语句的分类"></a>java中,循环语句的分类</h3><blockquote><p>1.while<br>2.do-while<br>3.for</p></blockquote><h3 id="while语句"><a href="#while语句" class="headerlink" title="while语句"></a>while语句</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><br><span class="line"><span class="keyword">while</span>(表达式){</span><br><span class="line">循环体语句;</span><br><span class="line">}</span><br><span class="line">...</span><br></pre></td></tr></table></figure><blockquote><p>1+2+3+4…..+100;</p><p>int sum=0;//定义一个变量 用来存储累加的和</p><p>int i=1;<br>sum+=i;(1.2,3,4,5,5.6,7)</p></blockquote><blockquote><p>盈盈为了考验令狐冲夺冠的决心,要他说一百遍“我能行!”;<br>1+…100;</p></blockquote><h3 id="死循环"><a href="#死循环" class="headerlink" title="死循环"></a>死循环</h3><blockquote><p>死循环:无法结束的循环被称为死循环 </p></blockquote><h3 id="变量的作用域"><a href="#变量的作用域" class="headerlink" title="变量的作用域"></a>变量的作用域</h3><p>内层可以使用外层的变量,外层不能使用内层的变量</p><h3 id="do-while"><a href="#do-while" class="headerlink" title="do-while"></a>do-while</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//do-while循环</span></span><br><span class="line">[初使化变量]</span><br><span class="line"><span class="keyword">do</span>{</span><br><span class="line">循环体 </span><br><span class="line">}<span class="keyword">while</span>(布尔表达式);</span><br><span class="line"></span><br><span class="line">特点:至少进入一次循环体 </span><br></pre></td></tr></table></figure><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="comment">//猜数游戏</span></span><br><span class="line">Random r=<span class="keyword">new</span> <span class="title class_">Random</span>();</span><br><span class="line"><span class="type">int</span> n=r.nextInt(<span class="number">10</span>);<span class="comment">//产生一个随机数,(整数)</span></span><br><span class="line"><span class="type">int</span> i=<span class="number">0</span>;<span class="comment">//代表用户猜的那个数值</span></span><br><span class="line"><span class="keyword">do</span>{</span><br><span class="line"><span class="comment">//猜数 </span></span><br><span class="line">}<span class="keyword">while</span>(n!=i)</span><br><span class="line"></span><br><span class="line"><span class="comment">//计算一下,用户用了几次机会 </span></span><br><span class="line"></span><br></pre></td></tr></table></figure><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><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">GuessNumber</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><br><span class="line">Random r=<span class="keyword">new</span> <span class="title class_">Random</span>();<span class="comment">//创建一个随机数生成器 </span></span><br><span class="line">Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);<span class="comment">//创建一个扫描器,用来接收用户猜的数字</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> n=r.nextInt(<span class="number">100</span>)+<span class="number">1</span>;<span class="comment">//获得一个随机数 </span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> i=<span class="number">0</span>;<span class="comment">//i代表用户每次猜的那个数,如果i==n,说明猜对了 </span></span><br><span class="line"></span><br><span class="line"><span class="keyword">do</span>{</span><br><span class="line"><span class="comment">//每次猜数</span></span><br><span class="line">System.out.println(<span class="string">"说出一个数字"</span>);</span><br><span class="line">i=s.nextInt();</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(i>n){</span><br><span class="line">System.out.println(<span class="string">"高了"</span>);</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(i<n){</span><br><span class="line">System.out.println(<span class="string">"低了"</span>);</span><br><span class="line">}</span><br><span class="line">}<span class="keyword">while</span>(i!=n);</span><br><span class="line"></span><br><span class="line">System.out.println(<span class="string">"你猜对了,这个数就是:"</span>+n);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="for循环"><a href="#for循环" class="headerlink" title="for循环"></a>for循环</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(初始化变量;条件表达式;循环体的最后一个表达式 ){</span><br><span class="line">循环体 </span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">//特点:非常适用于已知循环次数的程序 </span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> sum=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<<span class="number">100</span>;i++){</span><br><span class="line">sum+=i;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">//1.int i=0;</span></span><br><span class="line"><span class="comment">//2( i<100; sum+=i; i++)</span></span><br></pre></td></tr></table></figure><h3 id="break-与-continue"><a href="#break-与-continue" class="headerlink" title="break 与 continue"></a>break 与 continue</h3><blockquote><p>break与continue都是关键字,可以在循环体中使用 (for,while,do-while)</p><p>break:结束当前循环(退出循环)<br>continue:结束当次循环,进入下一次循环判断 </p></blockquote><h3 id="嵌套循环"><a href="#嵌套循环" class="headerlink" title="嵌套循环"></a>嵌套循环</h3><blockquote><p>语法结构:<br> 在一个循环体中,包含另外一个循环语句,这种结构就是嵌套循环 </p></blockquote><h3 id="循环中的算法"><a href="#循环中的算法" class="headerlink" title="循环中的算法"></a>循环中的算法</h3><blockquote><p>暴力(穷举):数字,字母,特殊字符 </p><p>顺推:已知条件推结果</p><p>逆推:已知结果推条件 </p></blockquote><h2 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h2><h3 id="数组的定义"><a href="#数组的定义" class="headerlink" title="数组的定义"></a>数组的定义</h3><blockquote><p>1.数组是一种引用数据类型,它可以存储多个相同类型的数据 </p><p>2.数组的长度一旦定义,不能改变</p><p>3.数组中的元素可以通过下标来访问,下标的取值范围是0~长度-1</p></blockquote><h3 id="数组-1"><a href="#数组-1" class="headerlink" title="数组"></a>数组</h3><p>数组元素的初始化 </p><blockquote><p>动态:创建数组后,为元素分别赋值</p><p>静态:创建数组的同时,为元素赋值 </p></blockquote><p>for each</p><blockquote><p>增强的for循环 </p><p>作用:遍历集合中的数据 </p><p>语法:</p><p>for(数据类型 变量:数组名){</p><p>}</p><p>将数组中的元素转成字符串 </p><p>Arrays.toString(数组)</p></blockquote><h3 id="内存模型"><a href="#内存模型" class="headerlink" title="内存模型"></a>内存模型</h3><p>java虚拟机将内容主要分为两个区域,分别是栈和堆</p><blockquote><p>基本数据类型,存在栈中 </p><p>int i=9;</p><p>基本数据类型变量存储的是数据本身 </p></blockquote><blockquote><p>引用类型是存储在堆中的 </p><p>引用类型有数组,类,接口 </p><p>int[] a=new int[5];</p></blockquote><h2 id="排序及二维数组"><a href="#排序及二维数组" class="headerlink" title="排序及二维数组"></a>排序及二维数组</h2><h3 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h3><blockquote><p>什么是算法:</p><p>其实就是解决问题?</p><p>如何衡量算法优劣?</p><p>时间</p><p>空间</p><p>时间复杂度:大O表示法 </p><p>O(1):固定次数,常数</p><p>O(logn):二分</p><p>O(n):一层循环</p><p>O(n方):二层循环</p><p>O(n的立方):三层循环</p><p>O(2的n次幂):</p><p>O(n!):</p></blockquote><h3 id="排序"><a href="#排序" class="headerlink" title="排序"></a>排序</h3><blockquote><p>排序是最常的算法 </p><p>直接选择排序?</p><p>冒泡排序?</p><p>未排序,已排序 </p><p>相邻比较并交换。整个的过程就像冒水泡一样 </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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="comment">//冒泡排序</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">BubbleSort</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><br><span class="line"> <span class="type">int</span>[] nums={<span class="number">12</span>,<span class="number">45</span>,<span class="number">78</span>,<span class="number">5</span>,<span class="number">75</span>,<span class="number">33</span>,<span class="number">23</span>,<span class="number">47</span>};</span><br><span class="line"> <span class="type">int</span> temp=<span class="number">0</span>;</span><br><span class="line"><span class="comment">//循环n-1次 </span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<nums.length-<span class="number">1</span>;i++){</span><br><span class="line"><span class="comment">//通过冒泡,每次从未排序堆中选一个最大的,放在已排序堆中</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j<nums.length-<span class="number">1</span>-i;j++){</span><br><span class="line"><span class="comment">//交换</span></span><br><span class="line"> <span class="keyword">if</span>(nums[j]>nums[j+<span class="number">1</span>]){</span><br><span class="line"> temp=nums[j];</span><br><span class="line"> nums[j]=nums[j+<span class="number">1</span>];</span><br><span class="line"> nums[j+<span class="number">1</span>]=temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> System.out.println(Arrays.toString(nums));</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><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><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="comment">//直接选择排序</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Sort3</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><br><span class="line"> <span class="type">int</span>[] nums={<span class="number">30</span>,<span class="number">78</span>,<span class="number">90</span>,<span class="number">10</span>,<span class="number">4</span>,<span class="number">67</span>};</span><br><span class="line"><span class="comment">//将最大的元素与第一个元素进行交换 </span></span><br><span class="line"><span class="comment">//1.定义一个变量,用来存储最大元素的下标</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<nums.length-<span class="number">1</span>;i++){</span><br><span class="line"> <span class="type">int</span> max=i;</span><br><span class="line"><span class="comment">//1.向未排序堆中找出最大的元素的下标 </span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j=i+<span class="number">1</span>;j<nums.length;j++){</span><br><span class="line"> <span class="keyword">if</span>(nums[max]<nums[j]){</span><br><span class="line"> max=j;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"><span class="comment">//2.交换 </span></span><br><span class="line"> <span class="keyword">if</span>(max!=i){</span><br><span class="line"> <span class="type">int</span> temp=nums[max];</span><br><span class="line"> nums[max]=nums[i];</span><br><span class="line"> nums[i]=temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> System.out.println(Arrays.toString(nums));</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="二分法"><a href="#二分法" class="headerlink" title="二分法"></a>二分法</h3><blockquote><p>二分法,也称为折半查找法 前提是,数据一定是已排序的。</p><p>时间复杂度为O(logn)</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">BinarySearch</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><br><span class="line"> <span class="type">int</span>[] nums={<span class="number">1</span>,<span class="number">3</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">9</span>,<span class="number">11</span>,<span class="number">23</span>,<span class="number">34</span>,<span class="number">56</span>,<span class="number">67</span>,<span class="number">88</span>,<span class="number">99</span>,<span class="number">100</span>};</span><br><span class="line"> Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"> System.out.println(<span class="string">"请输入一个数"</span>);</span><br><span class="line"> <span class="type">int</span> n=s.nextInt();</span><br><span class="line"> <span class="type">int</span> i=<span class="number">0</span>;</span><br><span class="line"> <span class="type">int</span> j=nums.length-<span class="number">1</span>;</span><br><span class="line"> <span class="type">int</span> m=<span class="number">0</span>;</span><br><span class="line"><span class="comment">//1.编写代码,完成查询,如果找到了,输出位置,否则,输出“查无此数” </span></span><br><span class="line"><span class="comment">//2.分别使用O(n) O(logn)来解决?</span></span><br><span class="line"> <span class="keyword">while</span>(i<=j){</span><br><span class="line"><span class="comment">//1.计算出中间位置 </span></span><br><span class="line"> m=(i+j)>><span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(n==nums[m]){</span><br><span class="line"> System.out.println(<span class="string">"找到了,位置是:"</span>+m);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(nums[m]>n){</span><br><span class="line"> j=m-<span class="number">1</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> i=m+<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(i>j){</span><br><span class="line"> System.out.println(<span class="string">"查无此数"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"> </span><br></pre></td></tr></table></figure><h3 id="二位数组"><a href="#二位数组" class="headerlink" title="二位数组"></a>二位数组</h3><p>二维数组</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><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></pre></td><td class="code"><pre><span class="line">java中其实没有二维数组,所谓的二维数组其实就是一个数组,只不过数组中的元素还是一个数组 </span><br><span class="line"></span><br><span class="line"><span class="type">int</span>[] nums={<span class="number">3</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>};</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</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"><span class="type">int</span> nums={{<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">7</span>},{<span class="number">6</span>,<span class="number">6</span>,<span class="number">6</span>},{<span class="number">8</span>,<span class="number">9</span>,<span class="number">4</span>,<span class="number">3</span>}};</span><br><span class="line"></span><br><span class="line">动态初使化 </span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</span><br><span class="line"></span><br><span class="line">nums[<span class="number">0</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]{<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>};</span><br><span class="line"></span><br><span class="line">nums[<span class="number">1</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]{<span class="number">333</span>,<span class="number">56</span>};</span><br><span class="line"></span><br><span class="line">nums[<span class="number">2</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]{<span class="number">4</span>,<span class="number">4</span>,<span class="number">6</span>,<span class="number">8</span>};</span><br><span class="line"></span><br><span class="line">String names={{<span class="string">"刘备"</span>,<span class="string">"张飞"</span>,<span class="string">"关羽"</span>},{<span class="string">"曹操"</span>},{<span class="string">"孙权"</span>,<span class="string">"周瑜"</span>}};</span><br><span class="line"></span><br></pre></td></tr></table></figure><h1 id="面向对象OOP"><a href="#面向对象OOP" class="headerlink" title="面向对象OOP"></a>面向对象OOP</h1><h2 id="面向过程与面向对象"><a href="#面向过程与面向对象" class="headerlink" title="面向过程与面向对象"></a>面向过程与面向对象</h2><blockquote><p>面向对象,强调由谁来做<br>面向过程,强调怎么做</p><p>面向过程:把解决问题的步骤列出来,再逐步实现</p><p>面向对象:将问题域中的对象找出来,再确定它们之间的关系 </p></blockquote><p>面向对象有什么优点</p><blockquote><p>1.更容易理解<br>2.解决复杂的问题,更有优势</p></blockquote><h2 id="面向对象的基础知识"><a href="#面向对象的基础知识" class="headerlink" title="面向对象的基础知识"></a>面向对象的基础知识</h2><blockquote></blockquote><h3 id="什么是对象"><a href="#什么是对象" class="headerlink" title="什么是对象"></a>什么是对象</h3><blockquote><p>所有具体的事物都是对象(object)</p></blockquote><h3 id="类"><a href="#类" class="headerlink" title="类"></a>类</h3><blockquote><p>类是一组具有相同属性和行为的一组对象的抽象表示<br>类和对象的关系:<br> 类是对象的抽象表示<br> 对象是类的一个具体实例<br>类是抽象的,对象是具体的</p></blockquote><p>class :</p><h3 id="定义类的语法"><a href="#定义类的语法" class="headerlink" title="定义类的语法"></a>定义类的语法</h3><blockquote><p>回顾</p><p>1.面向过程,面向对象的区别?</p><p>2.面向对象的两个重要的概念</p><p>对象,类 </p><p>3.如何定义一个类 </p><p>class 类名{</p><p>属性 </p><p>方法 </p><p>}</p></blockquote><p>类中都应该有什么</p><blockquote><p>1.定义一个学生类型</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">student</span>{</span><br><span class="line"> <span class="type">int</span> stuno; <span class="comment">//定义类的属性</span></span><br><span class="line"> String name;</span><br><span class="line"> String sex;</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="方法"><a href="#方法" class="headerlink" title="方法"></a>方法</h3><blockquote><p>大家用过方法吗?</p><p>用过哪呢?</p><p>Random r=new Random();</p><p>int i=r.nextInt(10);</p><p>方法中都包括什么?</p><p>方法名:</p><p>参数:多个,每个参数都需要有类型 </p><p>返回值类型:</p><p>定义一个方法,判断是否为闰年 </p></blockquote><p>定义方法的语法?</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><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">返回值类型 方法名(参数列表 ){</span><br><span class="line">方法体 </span><br><span class="line">}</span><br><span class="line"><span class="type">int</span> <span class="title function_">sum</span><span class="params">(<span class="type">int</span> a)</span>{</span><br><span class="line"> <span class="type">int</span> s=(<span class="number">1</span>+a)*a/<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">return</span> s;</span><br><span class="line">}</span><br><span class="line"><span class="type">int</span> s=num(<span class="number">100</span>);</span><br><span class="line">s=num(<span class="number">50</span>);</span><br></pre></td></tr></table></figure><blockquote><p>形参和实参的区别?</p><p>形参:定义方法时使用的参数,也叫形式参数 </p><p>实参:调用方法,传递的参数,也叫实际参数 </p><p>传参的过程就是赋值 即把实参赋给形参 </p></blockquote><p>return 用法</p><blockquote><p> 1.return语句 可以放在方法体中,代表返回的意思 </p><p>2.如果一个方法中有return 语句,return 一定作为最后一条语句来存在 </p><p>3.return 后的表达式的类型一定要与方法的返回值类型一致 </p><p>4.如果方法返回值类型为void ,那么可以省略return ,或者直接写return</p></blockquote><h3 id="内存结构"><a href="#内存结构" class="headerlink" title="内存结构"></a>内存结构</h3><p>略</p><h3 id="方法的传参"><a href="#方法的传参" class="headerlink" title="方法的传参"></a>方法的传参</h3><blockquote><p>pass by value:按值传递 </p><p>pass by ref:按引用传递 (引用类型)</p></blockquote><h3 id="重载(overload)"><a href="#重载(overload)" class="headerlink" title="重载(overload)"></a>重载(overload)</h3><blockquote><p>方法重载(overload):同一类中,方法名相同,参数列表不同的一组方法就叫重载方法 </p><p>输出 </p><p> System.out.printlnEmpty();</p><p> System.out.printlnString(“hello”);</p><p> System.out.printlnInt(8);</p><p>参数列表的不同主要体现在三方面</p><p>1.数量不同</p><p>2.类型不同</p><p>3.顺序不同 </p><p>四件套</p><p>1.理解题意,考虑边界问题</p><p>2.找出所有解</p><p>3.编写代码</p><p>4.测试</p><p>leetcode</p></blockquote><h2 id="构造方法及继承"><a href="#构造方法及继承" class="headerlink" title="构造方法及继承"></a>构造方法及继承</h2><h3 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a>构造方法</h3><blockquote><p>构造方法是一种特殊的方法<br>构造方法会给属性赋初值<br>构造方法会自动调用</p><p>构造方法与类同名</p></blockquote><h3 id="默认的构造方法"><a href="#默认的构造方法" class="headerlink" title="默认的构造方法"></a>默认的构造方法</h3><blockquote><p>1.每个类都至少有一个构造方法,如果不显式的定义,java编译器会自动为类创建一个无参的构造方法 即默</p><p>认的构造方法</p><p>2.默认的构造方法没有参数,没有方法体 </p><p>3.如果开发者显式的定义了构造方法,那么java编译器将不会再生成默认构造方法 </p></blockquote><h3 id="构造方法不返回值"><a href="#构造方法不返回值" class="headerlink" title="构造方法不返回值"></a>构造方法不返回值</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></pre></td><td class="code"><pre><span class="line">Student(<span class="type">int</span> no,String name,<span class="type">int</span> age){</span><br><span class="line"> </span><br><span class="line">}</span><br><span class="line"><span class="comment">//构造方法前面不能加void (添加后会变成一个普通方法)</span></span><br><span class="line">(<span class="keyword">void</span>)Student(){</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>默认的构造方法</p><h3 id="就近原则"><a href="#就近原则" class="headerlink" title="就近原则"></a>就近原则</h3><blockquote><p>就近原则:当访问不同作用域同名变量时 寻找最近的同名变量</p></blockquote><h3 id="this关键字"><a href="#this关键字" class="headerlink" title="this关键字"></a>this关键字</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></pre></td><td class="code"><pre><span class="line"><span class="built_in">this</span>代表当前对象的属性引用 </span><br><span class="line"><span class="built_in">this</span> 用法:</span><br><span class="line"> <span class="built_in">this</span>.属性</span><br><span class="line"> <span class="built_in">this</span>.普通方法</span><br><span class="line"> <span class="built_in">this</span>().构造方法</span><br><span class="line"> 只有在其他的构造方法中才能使用<span class="built_in">this</span>()来调用;</span><br><span class="line"> <span class="built_in">this</span>()必须位于构造方法第一条语句;</span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>Person p=new Person 一共做了几件事</p><p>1,开辟的新的空间</p><p>2,调用构造方法</p><p>3,返回引用赋值给p</p></blockquote><h3 id="匿名块"><a href="#匿名块" class="headerlink" title="匿名块"></a>匿名块</h3><blockquote><p>作用:将每个构造方法中相同的代码可以写在匿名块中 匿名块中的代码一定是在构造方法之前调用。</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></pre></td><td class="code"><pre><span class="line">语法:</span><br><span class="line">{</span><br><span class="line"><span class="comment">//代码 </span></span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="关于构造方法的小结"><a href="#关于构造方法的小结" class="headerlink" title="关于构造方法的小结"></a>关于构造方法的小结</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></pre></td><td class="code"><pre><span class="line">Person p=<span class="keyword">new</span> <span class="title class_">Person</span>(); <span class="comment">//一共做了三件事</span></span><br><span class="line"><span class="number">1.</span>在堆中开辟内存空间</span><br><span class="line"><span class="number">2.</span>调用构造方法,为属性初使化 </span><br><span class="line"><span class="number">3.</span>将引用返回给p;</span><br></pre></td></tr></table></figure><h2 id="包管理"><a href="#包管理" class="headerlink" title="包管理"></a>包管理</h2><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><br><span class="line">d:/照片/男朋友/男朋友<span class="number">1</span> </span><br><span class="line">/</span><br><span class="line">语法格式</span><br><span class="line"><span class="keyword">package</span> com.huayu.oop;</span><br><span class="line">导包 </span><br><span class="line"><span class="keyword">import</span> com.huayu.oop.*;</span><br><span class="line"><span class="keyword">import</span> com.huayu.oop.Person;</span><br></pre></td></tr></table></figure><h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h2><blockquote><p>继承是面向对象编程的最重要的特性之王一,它可以简化类的设计,利用的原有的类来创建新的类</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Person</span>{};</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span> <span class="keyword">extends</span> <span class="title class_">Person</span>{</span><br><span class="line">}</span><br></pre></td></tr></table></figure><blockquote><p>关于继承的总结</p><p>1.java中,只支持继承</p><p>2.子类继承父类的属性和方法,并且可以增加新的属性和方法</p><p>3.使用extends关键字来继承</p><p>4.是否可以使用继承 ,可以通过Instanceof 来判断</p></blockquote><h3 id="方法重写"><a href="#方法重写" class="headerlink" title="方法重写"></a>方法重写</h3><blockquote><p>方法重写(override,overwrite):在继承关系下,子类覆盖父类的方法覆盖时,要求方法名,参数,返回值都相同</p></blockquote><h3 id="关于继承的小结"><a href="#关于继承的小结" class="headerlink" title="关于继承的小结"></a>关于继承的小结</h3><blockquote><p>1.父类有的,子类一定有</p><p>2.父类没有的,子类可以扩展</p><p>3.父类有的,子类可以更改 </p></blockquote><h3 id="super关键字"><a href="#super关键字" class="headerlink" title="super关键字"></a>super关键字</h3><blockquote><p>super代表父类对象的引用<br>通过super关键字,再子类中可以</p></blockquote><h2 id="多态和封装"><a href="#多态和封装" class="headerlink" title="多态和封装"></a>多态和封装</h2><blockquote><p>面向对象的高级特性 </p><p>封装</p><p>继承 :复用</p><p>多态</p></blockquote><h3 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h3><blockquote><p>多态:同一类事物,可以拥有不同的形态</p><p>动物:吃,喝,行走</p><p>狗:</p><p>猫:</p><p>蛇:</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//子类的对象可以替代父类的对象进行使用</span></span><br><span class="line">Student s=<span class="keyword">new</span> <span class="title class_">Student</span>();</span><br><span class="line">Person p=s;</span><br><span class="line">父类 s=<span class="keyword">new</span> 子类</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="编译时类型"><a href="#编译时类型" class="headerlink" title="编译时类型"></a>编译时类型</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//当我们使用多态时,定义变量时使用的类型称为编译时类型 我们在使用方法和属性时,只能使用编译时类型</span></span><br><span class="line"><span class="comment">//提供的属性和方法 </span></span><br><span class="line">Person p=<span class="keyword">new</span> <span class="title class_">Student</span>();<span class="comment">//此时,编译时类型是Person </span></span><br><span class="line">Animal a=<span class="keyword">new</span> <span class="title class_">Dog</span>(); <span class="comment">//编译时类型是Animal</span></span><br><span class="line">a=net <span class="title function_">Cat</span><span class="params">()</span>;</span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Fish</span>();</span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Bird</span>();</span><br></pre></td></tr></table></figure><h3 id="运行时类型"><a href="#运行时类型" class="headerlink" title="运行时类型"></a>运行时类型</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">Animal a=<span class="keyword">new</span> <span class="title class_">Dog</span>(); <span class="comment">//编译时类型是Animal,运行时类型是Dog</span></span><br><span class="line">a=net <span class="title function_">Cat</span><span class="params">()</span>; <span class="comment">//编译时类型是Animal,运行时类型是Cat</span></span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Fish</span>(); <span class="comment">//编译时类型是Animal,运行时类型是Fish</span></span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Bird</span>(); <span class="comment">//编译时类型是Animal,运行时类型是Bird</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h3><blockquote><p>downcast:向下转型</p><p>upcast:向上转型</p><p>向上转换:直接转换无风险<br>向下转换:有风险</p><p>例如将,Animal转成Dog就是向下转型,向下转型有风险,建议转型前,使用instanceof来判断 否则可能</p><p>会产生ClassCastException(类型转换异常) 异常 </p></blockquote><h3 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h3><blockquote><p>java中,处处皆封装 主要表现在三方面?</p><p>1.类就是一个封装体,类中封装的属性,方法 </p><p>2.方法也是一种封装 (方法中封装的是代码)</p><p>Random r=new Random();</p><p>r.nextInt(10);</p><p>3.通过访问修饰符可以改变访问权限</p></blockquote><h3 id="访问修饰符"><a href="#访问修饰符" class="headerlink" title="访问修饰符"></a>访问修饰符</h3><table><thead><tr><th align="center"></th><th align="center">类内部</th><th align="center">同包</th><th align="center">不同包的子类</th><th align="center">不同包的非子类</th></tr></thead><tbody><tr><td align="center">private</td><td align="center">是</td><td align="center">否</td><td align="center">否</td><td align="center">否</td></tr><tr><td align="center">default</td><td align="center">是</td><td align="center">是</td><td align="center">否</td><td align="center">否</td></tr><tr><td align="center">protected</td><td align="center">是</td><td align="center">是</td><td align="center">是</td><td align="center">否</td></tr><tr><td align="center">public</td><td align="center">是</td><td align="center">是</td><td align="center">是</td><td align="center">是</td></tr></tbody></table><h3 id="修饰符"><a href="#修饰符" class="headerlink" title="修饰符"></a>修饰符</h3><h4 id="final"><a href="#final" class="headerlink" title="final"></a>final</h4><blockquote><p>final修饰属性,类,方法<br>它可以修饰,属性,变量,参数,只能赋值一次 不能被修改<br>修饰类:不能被继承<br>修饰方法:不能被重写</p></blockquote><h4 id="static"><a href="#static" class="headerlink" title="static"></a>static</h4><blockquote><p>static修饰属性,说明当前属性是的类属性,只存在一份整个类共享<br>并且可以直接通过类访问。<br>属性:类属性 类名,属性名<br>方法:类方法 </p><p>示例 </p><p>定义一个学生类,为学生自动生成学号,即创建的第一个学生,学号是1,第二个学生,学号是2 </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><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_">Student</span> {</span><br><span class="line"> <span class="type">int</span> stuno;</span><br><span class="line"> String name;</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="title function_">Student</span><span class="params">(String name, <span class="type">int</span> age)</span> {</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">showInfo</span><span class="params">()</span> {</span><br><span class="line"> System.out.println(<span class="string">"学号:"</span> + stuno + <span class="string">",姓名:"</span> + name + <span class="string">",age:"</span> + age);</span><br><span class="line"> }</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">Student</span> <span class="variable">s</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">"王千金"</span>, <span class="number">18</span>);</span><br><span class="line"> <span class="type">Student</span> <span class="variable">s1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">"王万两"</span>, <span class="number">18</span>);</span><br><span class="line"> <span class="type">Student</span> <span class="variable">s2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">"王大锤"</span>, <span class="number">19</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><blockquote><p>方法:</p><p>1.被static修饰的方法被称为类方法,调用类方法时无须创建对象,可以通过 类名.方法名()来调用 </p><p>2.在static方法中,只能实现静态成员,不能使用非静态成员 </p><p>3.在static方法中,也不能使用this,super关键字 </p><p>static 返回值类型 方法名(){</p><p>//方法体 </p><p>}</p></blockquote><h4 id="静态块"><a href="#静态块" class="headerlink" title="静态块"></a>静态块</h4><blockquote><p>static块</p><p>语法:</p><p>static{</p><p>//代码 </p><p>}</p><p>什么时执行:当类加载,初使化时,会自动调用静态块中的代码,因为每个类只加载一次,因此static{}只</p><p>被调用一次 </p></blockquote><blockquote><p>加载顺序<br>静态成员和static块<br>👇<br>普通成员和非static块<br>👇<br>构造方法</p></blockquote><blockquote><p>加载顺寻<br>父类静态成员和static块<br>👇<br>子类静态成员和static块<br>👇<br>父类普通成员和非static块<br>👇<br>父类构造方法<br>👇<br>子类普通成员和非static块<br>👇<br>子类构造方法</p></blockquote><h4 id="单例模式"><a href="#单例模式" class="headerlink" title="单例模式"></a>单例模式</h4><blockquote><p>设计模式:Design partten</p><p>解决某些设计问题所采用的套路,有点类似于三十六计 </p><p>目前设计模式一共有23种 </p><p>一共分为三类 </p><p>1.创建型</p><p>2.结构型</p><p>3.行为型</p></blockquote><p><strong>单例模式:</strong>Singleton</p><blockquote><p>解决的问题:某个类,只允许产生唯一的实例 </p><p>解决的方法</p><p>1.将构造方法定义成私有 </p><p>2.定义一个同类型的静态的属性 </p><p>3.定义一个public的静态方法,用来返回唯一的实例 </p></blockquote><p><strong>单例模式 的两种类型</strong></p><blockquote><p>1.饿汉式 </p><p>2.懒汉式 (lazy)</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><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> Singleton s=<span class="keyword">new</span> <span class="title class_">Singleton</span>();</span><br><span class="line"><span class="comment">/*String name;</span></span><br><span class="line"><span class="comment">String time;*/</span></span><br><span class="line"><span class="keyword">private</span> <span class="title function_">Singleton</span><span class="params">()</span>{</span><br><span class="line"><span class="comment">/*System.out.println("创建单例模式: ");</span></span><br><span class="line"><span class="comment">System.out.println("进程分别有");</span></span><br><span class="line"><span class="comment">System.out.println("1");</span></span><br><span class="line"><span class="comment">System.out.println("2");</span></span><br><span class="line"><span class="comment">System.out.println("3");</span></span><br><span class="line"><span class="comment">System.out.println("4");*/</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> Singleton <span class="title function_">getinstance</span><span class="params">()</span> {</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> s;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/*public void close() {</span></span><br><span class="line"><span class="comment">System.out.println("关闭程序");</span></span><br><span class="line"><span class="comment">}*/</span></span><br></pre></td></tr></table></figure><h1 id="抽象类与接口"><a href="#抽象类与接口" class="headerlink" title="抽象类与接口"></a><strong>抽象类与接口</strong></h1><h2 id="abstract"><a href="#abstract" class="headerlink" title="abstract"></a>abstract</h2><blockquote><p>abstract是一个修饰符</p><p>可以修饰方法和类<br>类:抽象类,不能被实例化<br>方法:抽象方法,让子类重写 如果子类不重写,子类方法也是抽象方法<br>抽象方法没有具体的实现 </p><p>抽象方法只有定义,没有方法的实现<br>如果一个类有抽象方法,那这个类一定是抽象类<br>如果子类不重写方法,那这个子类还是抽象类</p></blockquote><h2 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h2><blockquote><p>1.java中不支持继承,但通过接口,可以实现多继承的效果 </p><p>2.接口是一个特殊的抽象类 接口中只能有抽象方法和public static final属性 </p><p>3.接口使用 interface来定义 </p></blockquote><h3 id="接口与类"><a href="#接口与类" class="headerlink" title="接口与类"></a>接口与类</h3><blockquote><p>接口通常代表一种能力,抽象类通常代表一个概念 </p><p>接口:able:</p><p>会飞的</p><p>发光的</p><p>吃肉的</p><p>抽象类:</p><p>动物</p><p>交通工具 </p><p>图形 </p><p>找你妹 </p><p>发光 </p><p>会飞的 </p><p>带尖的 </p><p>交通工具 </p><p>飞机 </p><p>会飞的 a=new Plan();</p><p>=new 天使();</p><p>=new 蝙蝠();</p><p>=new 萤火虫();</p></blockquote><h3 id="接口与抽象类的区别"><a href="#接口与抽象类的区别" class="headerlink" title="接口与抽象类的区别"></a><strong>接口与抽象类的区别</strong></h3><blockquote><p>1.接口是一个特殊的抽象类,只有public static final 属性及抽象方法 </p><p>2.一个类只能有一个父类,但一个类可以同时实现多个接口 </p><p>3.类和类之间是单继承 ,但接口和接口之间可以多继承</p><p>interface C extends A,B</p><p>4.抽象类通常表示一个概念,而接口则表示一种能力 </p></blockquote><h3 id="类和类之间的关系"><a href="#类和类之间的关系" class="headerlink" title="类和类之间的关系"></a><strong>类和类之间的关系</strong></h3><blockquote><p>主要有三种 </p><p>1.继承</p><p>2.关联</p><p>3.依赖 </p><p>关联又可以细分为</p><p>1.聚合</p><p>2.组合</p></blockquote><h4 id="继承-1"><a href="#继承-1" class="headerlink" title="继承"></a>继承</h4><blockquote><p>子类拥有父类的属性和方法 </p><p>判断两个类是否是继承关系 is 即 子类 is 父类 </p><p>代码: class 子类 extends 父类{}</p></blockquote><h4 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h4><blockquote><p>一个类可以实现多个接口 </p><p>代码: class 类 implements 接口 </p></blockquote><h4 id="依赖"><a href="#依赖" class="headerlink" title="依赖"></a>依赖</h4><blockquote><p>两个类之间关系是临时发生的,即做某一件事时才产生联系,这种关系就是依赖 </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></pre></td><td class="code"><pre><span class="line">判断方法 : use;</span><br><span class="line">代码:</span><br><span class="line">两种形式</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Person</span>{</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">eat</span><span class="params">()</span>{</span><br><span class="line"> Spoon s=<span class="keyword">new</span> <span class="title class_">Spoon</span>();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">attack</span><span class="params">(Weapon w)</span>{</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="关联"><a href="#关联" class="headerlink" title="关联"></a>关联</h4><blockquote><p>关联:一种强依赖,比依赖的关系更强,是一种稳定的关系 </p><p>判断: has</p><p>代码:作为别外一个类的属性来存在 </p></blockquote><h4 id="聚合"><a href="#聚合" class="headerlink" title="聚合"></a>聚合</h4><blockquote><p>聚合是关联的一种特例,体现整体和局部的关系 整体和局部之间没有共同的生命周期 </p></blockquote><h4 id="组合"><a href="#组合" class="headerlink" title="组合"></a>组合</h4><blockquote><p>聚合是关联的一种特例,体现整体和局部的关系 整体和局部之间有共同的生命周期 </p></blockquote><h4 id="设计思想"><a href="#设计思想" class="headerlink" title="设计思想"></a>设计思想</h4><blockquote><p>高内聚,低耦合 </p></blockquote><h3 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h3><p>可以将类的定义放在其它的类中,这种类叫内部类 </p><p>内部类一共有四种,分别是</p><ol><li><p>静态内部类</p></li><li><p>成员内部类</p></li><li><p>匿名内部类</p></li><li><p>方法内部类</p></li></ol><h4 id="静态内部类"><a href="#静态内部类" class="headerlink" title="静态内部类"></a>静态内部类</h4><p>静态内部类可以使用外部类的静态成员</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><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="keyword">public</span> <span class="keyword">class</span> <span class="title class_">A</span> {</span><br><span class="line"> <span class="keyword">static</span> <span class="type">int</span> a=<span class="number">9</span>;</span><br><span class="line"> String name=<span class="string">"人"</span>;</span><br><span class="line"> <span class="comment">//静态内部类</span></span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">B</span>{</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">getB</span><span class="params">()</span> {System.out.println(a);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">//test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestA</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_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"><span class="comment">//创建一个内部类的对象 </span></span><br><span class="line"> A.B b=<span class="keyword">new</span> <span class="title class_">A</span>.B();</span><br><span class="line"> b.getB();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="成员内部类"><a href="#成员内部类" class="headerlink" title="成员内部类"></a>成员内部类</h4><p>在一个类的内部定义另外一个类,内部类可以使用外部类的非静态成员</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><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Outer</span> {</span><br><span class="line"> String name=<span class="string">"outer"</span>;</span><br><span class="line"> <span class="keyword">class</span> <span class="title class_">Inner</span>{</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">getInner</span><span class="params">()</span> {</span><br><span class="line"> System.out.println(name);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">//test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestA</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_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"><span class="comment">//创建一个外部类的对象 </span></span><br><span class="line"> Outer o=<span class="keyword">new</span> <span class="title class_">Outer</span>();</span><br><span class="line"><span class="comment">//创建o的内部类对象</span></span><br><span class="line"> Outer.Inner i=o.<span class="keyword">new</span> <span class="title class_">Inner</span>();</span><br><span class="line"> i.getInner();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="方法内部类"><a href="#方法内部类" class="headerlink" title="方法内部类"></a>方法内部类</h4><h4 id="匿名内部类"><a href="#匿名内部类" class="headerlink" title="匿名内部类"></a>匿名内部类</h4><p>有时,我们定义了一个内部类,使用这个内部类时,只实例一个对象 此时,就可以将定义类和实例化</p><p>对象,两个操作合到一起,这个就是匿名内部类</p><p>使用匿名类的条件是,此类必须实现一个接口或继承一个抽象类</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></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>定义一个类</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">A</span>(){</span><br><span class="line">}</span><br><span class="line"><span class="number">2.</span>只实体化一次</span><br><span class="line">A a=<span class="keyword">new</span> <span class="title class_">A</span>();</span><br></pre></td></tr></table></figure><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">Usb u=<span class="keyword">new</span> <span class="title class_">Usb</span>() {</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getData</span><span class="params">()</span> {</span><br><span class="line"> <span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line"> <span class="keyword">return</span> <span class="string">"这就是匿名内部类,看着有点不舒服。"</span>;</span><br><span class="line"> }</span><br><span class="line">};</span><br><span class="line">c.connect(u);</span><br></pre></td></tr></table></figure><h1 id="常用类"><a href="#常用类" class="headerlink" title="常用类"></a>常用类</h1><h2 id="lang包"><a href="#lang包" class="headerlink" title="lang包"></a>lang包</h2><blockquote><p>lang是java中使用最广泛的包,全称是java.lang 此包不需要手动导入,即可使用此包中的所有类 </p><p>此包中常用的类有 </p><p>System</p><p>Object</p><p>包装类</p><p>Math</p><p>字符串 </p><p>Thread等</p></blockquote><h2 id="System类"><a href="#System类" class="headerlink" title="System类"></a>System类</h2><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></pre></td><td class="code"><pre><span class="line"><span class="comment">//System 类包含一些有用的类字段和方法。它不能被实例化。 final修饰的类不能被继承</span></span><br><span class="line"><span class="comment">//常用方法:</span></span><br><span class="line">System.out.println();</span><br><span class="line">System.err.println();</span><br><span class="line">System.in;</span><br><span class="line">System.exit(<span class="number">0</span>);</span><br><span class="line">System.arraycopy()</span><br><span class="line">System.gc()</span><br><span class="line">System.currentTimeMillis()</span><br></pre></td></tr></table></figure><h2 id="包装类"><a href="#包装类" class="headerlink" title="包装类"></a>包装类</h2><blockquote><p>java,为每个基本数据类型都定义了与之对对就的类,这些类就叫包装类 </p><p>Boolean</p><p>Byte,Short,Integer,Long</p><p>Float,Double</p><p>Character</p><p>包装类与基本数据类型是可以相互转换的 </p><p>基本数据类型-》包装类 :装包</p><p>包装-》基本数据类型: 拆包 </p></blockquote><h2 id="Math"><a href="#Math" class="headerlink" title="Math"></a>Math</h2><blockquote><p>Math类:包含了所有用于几何和三角的浮点运算方法。Math类是final的,其中所有方法都是static的。</p></blockquote><h2 id="object类"><a href="#object类" class="headerlink" title="object类"></a>object类</h2><blockquote><p>Object类是所有类的类的父类 此类中下定义所有类都拥有的方法 </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></pre></td><td class="code"><pre><span class="line">equals():比较</span><br><span class="line">toString():转成字符串</span><br><span class="line">hashcode():哈希码</span><br><span class="line">getClass():获得当前对象的类 </span><br><span class="line">clone():克隆 </span><br><span class="line">finalize():垃圾回收前执行的方法 </span><br><span class="line">notify()</span><br><span class="line">notifyAll();</span><br><span class="line">wait();</span><br></pre></td></tr></table></figure><h3 id="hashcode方法"><a href="#hashcode方法" class="headerlink" title="hashcode方法"></a>hashcode方法</h3><blockquote><p>hashcode是一个int值 </p><p>即可将任何长度的对象转换成固定长度的数字 </p><p>hashcode的协定 </p><p>1.如一个对象不改变,那么多次调用hashcode()方法,返回的结果应该相同 </p><p>2.如果两个对象相等(equals()),那么两个对象的hashcode()一定相等</p><p>3.如果两对象不相等,那么hashcode也有可能相等,设计时,尽量不相等 </p></blockquote><h3 id="equals方法"><a href="#equals方法" class="headerlink" title="equals方法"></a>equals方法</h3><blockquote><p>boolean equals(Object obj);</p><p>四个特性 </p><p>1.自反性:a.equals(a); true</p><p>2.对称性:a.equals(b)==b.equals(a);</p><p>3.传递性:a.equals(b)=true,b.equals(c)=true,那么 a.equals(c)=true</p><p>4.一致性:a.equasl(b)的值,多次调用时,应该相同 (前提是,a和b都不改变)</p><p>另外 a.equals(null),永远为false</p></blockquote><h3 id="toString方法"><a href="#toString方法" class="headerlink" title="toString方法"></a><em>toString</em>方法</h3><blockquote><p>将对象转成String </p><p>注意:</p><p>1.如果不重写,那么将会调用父类的方法,内容是 类名@hashcode()的十六进制 </p><p>2.当调用System.out.println(s)方法,会自动调用s.toString()方法 </p></blockquote><h3 id="getClass-方法"><a href="#getClass-方法" class="headerlink" title="**getClass()**方法"></a>**getClass()**方法</h3><blockquote><p>获得对象的类 Class 即,所用同类型的对象返回的是同一个类 </p></blockquote><h3 id="String-类"><a href="#String-类" class="headerlink" title="String 类"></a>String 类</h3><blockquote><p>字符串 Java是常用的类<br>字符串的特点<br>1.字符串是常量,不能改变<br>2.为了提升使用率,java对字符串进行了优化处理,即字符串池(String Pool)</p></blockquote><p>常用的方法</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><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="type">int</span> <span class="title function_">length</span><span class="params">()</span>:返回字符串的长度</span><br><span class="line"><span class="type">int</span> <span class="title function_">indexOf</span><span class="params">(<span class="type">int</span>)</span>:返回某个字符位于串中的位置(下标)</span><br><span class="line"><span class="type">int</span> <span class="title function_">lastIndexOf</span><span class="params">(String)</span>:查找最后一个指定子串的位置 </span><br><span class="line"><span class="type">boolean</span> <span class="title function_">isEmpty</span><span class="params">()</span>:判断某个字符串是否为空</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">startsWith</span><span class="params">(String)</span>:是否以某个字符串开头</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">endsWith</span><span class="params">(String)</span>:是否以某个字符串结尾</span><br><span class="line">String <span class="title function_">toUpperCase</span><span class="params">()</span>:转成大写</span><br><span class="line">String <span class="title function_">toLowerCase</span><span class="params">()</span>:转成小写 </span><br><span class="line">String <span class="title function_">trim</span><span class="params">()</span>:返回一个去掉前后空格的新串 </span><br><span class="line">String[] split(String);拆分字符串</span><br><span class="line"><span class="type">char</span> <span class="title function_">charAt</span><span class="params">(<span class="type">int</span>)</span>:根据索引找字符 </span><br><span class="line">String <span class="title function_">replaceAll</span><span class="params">(String a,String b)</span>:将字符串中的a都替换成b,并返回一个新的字符串</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">contains</span><span class="params">(String)</span>:是否包含另外一个子串</span><br></pre></td></tr></table></figure><h3 id="字符串类"><a href="#字符串类" class="headerlink" title="字符串类"></a>字符串类</h3><h4 id="字符串比较方法"><a href="#字符串比较方法" class="headerlink" title="字符串比较方法"></a>字符串比较方法</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></pre></td><td class="code"><pre><span class="line"><span class="type">boolean</span> <span class="title function_">equals</span><span class="params">(String)</span> 比较</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">equalsIgnoreCase</span><span class="params">(String)</span> 比较(忽略大小写(英文))</span><br><span class="line"><span class="type">int</span> <span class="title function_">compareto</span><span class="params">(String)</span> 与另一个字符串比较大小</span><br><span class="line"><span class="type">int</span> <span class="title function_">comparetoignoreCase</span><span class="params">()</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h4 id="字符串池"><a href="#字符串池" class="headerlink" title="字符串池"></a>字符串池</h4><blockquote><p>因为String是java最常用的类,同时此类是常量(一旦定义,不能改变),因此,为了提高效率(节省内存),java中使用字符串池 </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></pre></td><td class="code"><pre><span class="line">String s=<span class="string">"hello"</span>; </span><br><span class="line">String s1=<span class="string">"hello"</span>;</span><br><span class="line">String s2=<span class="string">"hello"</span>; </span><br><span class="line">String s3=<span class="string">"hello"</span>;</span><br></pre></td></tr></table></figure><h4 id="字符串转换"><a href="#字符串转换" class="headerlink" title="字符串转换"></a>字符串转换</h4><blockquote><p>不同的类型之间是否能转换?</p><p>1 基本类型 (可转)c<br>2 不同类之间 需要有继承关系才能转<br>3 如果两个类型之间没有继承关系,有时也可以通过一些方法转换<br>integer parseInt()</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></pre></td><td class="code"><pre><span class="line">String s=<span class="string">"123"</span>;</span><br><span class="line"><span class="comment">//将String,s转成int类型</span></span><br><span class="line"><span class="type">int</span> i=Integer.parseInt(s);</span><br><span class="line">System.out.println(i);</span><br><span class="line"><span class="comment">//将int 类型的i转换成字符串</span></span><br><span class="line">String s2=String.valueOf(i);</span><br></pre></td></tr></table></figure><h4 id="StringBuffer"><a href="#StringBuffer" class="headerlink" title="StringBuffer"></a><strong>StringBuffer</strong></h4><blockquote><p>1.StringBuffer是字符串缓冲区,与String不同,内容是可以修改的 </p><p>2.StringBuffer支持链式编程</p><p>3.与StringBuilder不同,它是线程安全的 </p><p>4.StringBuffer与String是可以转换的</p></blockquote><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">StringBuffer->String; sb.toString();</span><br><span class="line">String->StringBuffer: StringBuffer sb=<span class="keyword">new</span> <span class="title class_">StringBuffer</span>(String);</span><br></pre></td></tr></table></figure><p>常用方法</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></pre></td><td class="code"><pre><span class="line">StringBuffer <span class="title function_">append</span><span class="params">()</span>:追加</span><br><span class="line">StringBuffer <span class="title function_">insert</span><span class="params">()</span>:插入</span><br><span class="line">StringBuffer <span class="title function_">delete</span><span class="params">(start,end)</span>:删除指定的子串</span><br><span class="line">StringBuffer <span class="title function_">repalace</span><span class="params">(start,end,str)</span>:将指定位置的字符串替换成str</span><br><span class="line">StringBuffer <span class="title function_">reverse</span><span class="params">()</span>:翻转字符串</span><br></pre></td></tr></table></figure><h4 id="StringBuilder"><a href="#StringBuilder" class="headerlink" title="StringBuilder"></a><strong>StringBuilder</strong></h4><blockquote><p>与StringBuffer基本相同,只是线程不安全 </p></blockquote><h1 id="异常"><a href="#异常" class="headerlink" title="异常"></a>异常</h1><h2 id="异常概念"><a href="#异常概念" class="headerlink" title="异常概念"></a><strong>异常概念</strong></h2><blockquote><p>错误主要发生有两种<br>1 编译时发生错误<br>2 运行时错误 叫做异常 </p><p>java的异常分为两类<br>1 error jvm内部错误、资源耗尽<br>2 exception 其他编程错误或偶然的外在因素</p></blockquote><h2 id="异常的体系结构"><a href="#异常的体系结构" class="headerlink" title="异常的体系结构"></a><strong>异常的体系结构</strong></h2><blockquote><p>Throwable<br>Error:错误<br>Exception:异常<br>RuntimeException:运行时异常<br>NullPointerException:空指针异常<br>ClassCastException:类型转换异常<br>ArrayIndexOutOfBoundsException:数组下标越界<br>ArithmeticException:数字异常<br>受检查异常 </p></blockquote><h2 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h2><blockquote><p>java中处理异常的机制是:抓抛模型 </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></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span>-<span class="keyword">catch</span>-<span class="keyword">finally</span></span><br><span class="line"> <span class="keyword">try</span>{</span><br><span class="line"><span class="comment">//代码1;</span></span><br><span class="line"><span class="comment">//代码2 出现exceptin2;</span></span><br><span class="line"><span class="comment">//代码3:出现exception3;</span></span><br><span class="line"> }<span class="keyword">catch</span>(Exception1 e){</span><br><span class="line"><span class="comment">//处理代码1</span></span><br><span class="line"> }<span class="keyword">catch</span>(Exception2 e2){</span><br><span class="line"><span class="comment">//处理代码2</span></span><br><span class="line"> }<span class="keyword">finally</span>{</span><br><span class="line"><span class="comment">//finally</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h2 id="异常分类"><a href="#异常分类" class="headerlink" title="异常分类"></a>异常分类</h2><blockquote><p>1 运行时异常 runtimeException类和其子类<br>2 受检查异常 非runtimException</p><p>区别:<br>运行时异常编译时可以不处理<br>受检查异常必须得处理</p></blockquote><h2 id="throws"><a href="#throws" class="headerlink" title="throws"></a>throws</h2><blockquote><p>当我们定义一个方法时,如果正确调用,可以返回一个结果,如果错误的调用,则应该抛出一个异常,这时,</p><p>可以使用throws来抛出某种异常的类型 </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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="type">double</span> <span class="title function_">getCircleArea</span><span class="params">(<span class="type">double</span> r)</span> thrwos Exception{</span><br><span class="line">}</span><br><span class="line"><span class="comment">//MyArray; 10,11</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">int</span> <span class="title function_">get</span><span class="params">(<span class="type">int</span> index)</span> <span class="keyword">throws</span> ArrayIndexOutOfBoundsException{</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="throw关键字"><a href="#throw关键字" class="headerlink" title="throw关键字"></a>throw关键字</h2><blockquote><p>throw代表:手动抛出一个异常对象 格式是 </p><p>throw new Excpetion();</p><p>throw主要用在方法中 throw有点类似return </p></blockquote><h2 id="throw和throws的区别"><a href="#throw和throws的区别" class="headerlink" title="throw和throws的区别"></a>throw和throws的区别</h2><blockquote><p>throws与throw的区别</p><p>1.throws放在方法后,说明此方法可能抛出某种类型的异常 </p><p>2.throws后,放的是异常类型 </p><p>2.throw 放在方法体中,throw后面放置的是异常对象,说明要手动抛出一个异常 </p></blockquote><h1 id="工具类"><a href="#工具类" class="headerlink" title="工具类"></a>工具类</h1><blockquote><p>java.util包,被称为工具包,也是java最常用的一个包</p><p>此包中主要有集合框架,日期,编码解码,国际化等</p></blockquote><h2 id="random类"><a href="#random类" class="headerlink" title="random类"></a>random类</h2><blockquote><p>Random类是随机数生成器,提供了很多用于生成各种类型的随机数的方法</p></blockquote><h2 id="Date-类"><a href="#Date-类" class="headerlink" title="Date 类"></a>Date 类</h2><blockquote><p>Date类主用来存储时间,精确到毫秒,内部是通过一个long值来进行存储的</p></blockquote><h2 id="Calendar"><a href="#Calendar" class="headerlink" title="Calendar"></a><strong>Calendar</strong></h2><blockquote><p>日历类:主要用来处理时间,例如,获取时间的某个部分,改变时间的某个部分 对时间进行加减操作等 </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></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>实例化 </span><br><span class="line">Calendar c=Calendar.getInstance();</span><br><span class="line"><span class="number">2.</span>Date与Calendar的转换</span><br><span class="line">Calendar->Date c.getTime();</span><br><span class="line">date->Calendar c.setTime(date);</span><br><span class="line"><span class="number">3.</span>操作时间</span><br><span class="line">获得某个部分 </span><br><span class="line"><span class="type">int</span> <span class="title function_">get</span><span class="params">(<span class="type">int</span> )</span></span><br><span class="line">Calendar.YEAR=<span class="number">1</span>;</span><br></pre></td></tr></table></figure><h2 id="SimpleDateFormat"><a href="#SimpleDateFormat" class="headerlink" title="SimpleDateFormat"></a><strong>SimpleDateFormat</strong></h2><blockquote><p>SimpleDateFormat类是日期格式化的类,可以用来将指定格式的之符串转成Date,也可以将Date转换成指</p><p>定格式的字符串 </p><p>用法</p><p>1.先实例化一个对象</p><p> SimpleDateFormat sdf=new SimpleDateFormat(“yyyy-MM-dd”);</p><p>2.使用 parse方法将字符串转成日期</p><p> Date d=sdf.parse(str);</p><p>3.使用format方法将日期转成字符串</p><p> String str=sdf.format(data);</p></blockquote><h1 id="集合框架"><a href="#集合框架" class="headerlink" title="集合框架"></a>集合框架</h1><h2 id="集合框架-1"><a href="#集合框架-1" class="headerlink" title="集合框架"></a>集合框架</h2><blockquote><p>集合:集合也被称为容器,也是一个对象,此对象中可以管理其它的对象(element)元素 例如数组就是一</p><p>个集合 </p><p>集合框架:java中给我提供了很多集合类,接口和算法类,作为一个整体,被称为集合框架</p></blockquote><p><img src="https://s3.bmp.ovh/imgs/2023/02/25/4736ba1bd8ccacc3.png"></p><p>集合框架有两个顶层接口,所有的集合类都是这两个接口的实现</p><h2 id="Collection接口"><a href="#Collection接口" class="headerlink" title="Collection接口"></a><strong>Collection</strong>接口</h2><blockquote><p>1.是集合框架的顶层接口之一,没有直接的实现类 </p><p>2.Collection有三个子接口,分别是List,Set,Queue;</p><p>3.三个子接口的特点如下 </p><p>List:有序(有索引),可重复 </p><p>Set:无序,不可重复 </p><p>Queue:先进先出</p></blockquote><p>Collection接口应该有什么方法?</p><blockquote><p>CURD</p><p>boolean add(E):增加一个元素</p><p>boolean addAll(Collection):增加多个元素</p><p>void clear():清空</p><p>boolean isEmpty():是否为空</p><p>int size():返回元素的个数</p><p>boolean remove(E):删除一个元素</p><p>boolean removeAll(Collection):删除多个元素</p><p>boolean retainAll(Collection):保留多个元素</p><p>boolean contains(E):是否包含某个元素</p><p>boolean containsAll(Collection):是否包含某些元素</p><p>Object[] toArray():将集合中的元素转成数组返回</p></blockquote><p>所有集合类中存储的不是对象本身,而是一个引用而已</p><h2 id="泛型"><a href="#泛型" class="headerlink" title="泛型"></a>泛型</h2><blockquote><p>泛型指的是数据类型的参数化 </p><p>泛型可以解决两个问题</p><p>1.类型安全检查</p><p>2.消除强制类型转换</p><p>java中,集合框架中的集合类都支持泛型</p></blockquote><p>如何使用</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">List<Person> list=<span class="keyword">new</span> <span class="title class_">ArrayList</span><Person>();</span><br></pre></td></tr></table></figure><h2 id="算法类"><a href="#算法类" class="headerlink" title="算法类"></a>算法类</h2><blockquote><p>集合框架中除了提供接口和实现类之外,还提供用于处理集合的算法类,算法类主要有</p><p>Collections:用于处理集合的算法类 </p><p>Arrays:用于处理数组的算法类 </p></blockquote><p>Collections常用的方法</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="keyword">static</span> <span class="keyword">void</span> <span class="title function_">sort</span><span class="params">(List)</span>:对List中的元素按自然顺序进行排序 </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">reverse</span><span class="params">(List)</span>:翻转集合中元素</span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">shuffle</span><span class="params">(List)</span>:洗牌 (打乱顺序)</span><br><span class="line"><span class="keyword">static</span> E <span class="title function_">max</span><span class="params">(Collection)</span>:获取最大的元素</span><br><span class="line"><span class="keyword">static</span> E <span class="title function_">min</span><span class="params">(Collection)</span>:获取最小的元素 </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">addAll</span><span class="params">(Collection coll,T...t)</span>:向coll中增加多个元素 </span><br><span class="line"><span class="keyword">static</span> <span class="type">int</span> <span class="title function_">binarySearch</span><span class="params">(List)</span>:二分查找 </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">copy</span><span class="params">(List desc,List src)</span>:复制</span><br></pre></td></tr></table></figure><p>Arrays常用的方法</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> List <span class="title function_">asList</span><span class="params">(T...t)</span>:创建一个List,将添加多个元素</span><br><span class="line"><span class="keyword">static</span> T <span class="title function_">binarySearch</span><span class="params">()</span>:二分查找</span><br><span class="line"><span class="keyword">static</span> T[] copyRange(<span class="type">int</span>[],start,end);</span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">sort</span><span class="params">()</span>;</span><br><span class="line"><span class="keyword">static</span> String <span class="title function_">toString</span><span class="params">()</span>;</span><br></pre></td></tr></table></figure><h2 id="Comparable"><a href="#Comparable" class="headerlink" title="Comparable"></a><strong>Comparable</strong></h2><blockquote><p>Comparable是自然排序的接口,实现此接口的类,就拥有了比较大小的能力</p><p>此接口中的方法只有一个</p><p>public int comparareTo(T t){</p><p>}</p><p>返回值说明 </p><p>正数:当前对象与比t大</p><p>0:当前对象与t相等</p><p>负数:当前对象比t小</p></blockquote><h2 id="Comparator"><a href="#Comparator" class="headerlink" title="Comparator"></a><strong>Comparator</strong></h2><blockquote><p>自定义的比较器 </p><p>Comparator接口中包含一个方法</p></blockquote><blockquote><p>Comparator与Comparable的区别</p><p>1.Comparable为可排序的,也被称为自然排序或内部比较器,实现该接口的类的对象自动拥有可排序功能。</p><p>2.Comparator为比较器,也被称为外部比较器,实现该接口可以定义一个针对某个类的排序方式。</p><p>3.Comparator与Comparable同时存在的情况下,前者优先级高</p></blockquote><h2 id="ArrayList源码分析"><a href="#ArrayList源码分析" class="headerlink" title="ArrayList源码分析"></a><strong>ArrayList</strong>源码分析</h2><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><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="keyword">transient</span> Object[]elementData; <span class="comment">//定义一个Object数组,用来存储数组的元素,此数组可以扩</span></span><br><span class="line">容 </span><br><span class="line"><span class="comment">//2.构造方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">ArrayList</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">this</span>.elementData=DEFAULTCAPACITY_EMPTY_ELEMENTDATA;</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="title function_">ArrayList</span><span class="params">(<span class="type">int</span> initialCapacity)</span>{</span><br><span class="line"> <span class="keyword">if</span>(initialCapacity><span class="number">0</span>){</span><br><span class="line"> <span class="built_in">this</span>.elementData=<span class="keyword">new</span> <span class="title class_">Object</span>[initialCapacity];</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(initialCapacity==<span class="number">0</span>){</span><br><span class="line"> <span class="built_in">this</span>.elementData=EMPTY_ELEMENTDATA;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">IllegalArgumentException</span>(<span class="string">"Illegal Capacity: "</span>+</span><br><span class="line"> initialCapacity);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">//3.add方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">add</span><span class="params">(E e)</span>{modCount++;</span><br><span class="line"> add(e,elementData,size);</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 class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">add</span><span class="params">(E e,Object[]elementData,<span class="type">int</span> s)</span>{</span><br><span class="line"> <span class="keyword">if</span>(s==elementData.length)</span><br><span class="line"> elementData=grow();</span><br><span class="line"> elementData[s]=e;</span><br><span class="line"> size=s+<span class="number">1</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="数组总结"><a href="#数组总结" class="headerlink" title="数组总结"></a>数组总结</h3><blockquote><p>数组的特点:元素之间的地址是连续的 </p><p>get(index):时间复杂度是O(1)</p><p>set(index,E):O(1)</p><p>add(index,E):时间复杂度是O(n)</p><p>remove(index):O(n)</p></blockquote><h2 id="链表"><a href="#链表" class="headerlink" title="链表"></a>链表</h2><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></pre></td><td class="code"><pre><span class="line"><span class="comment">//内部结节</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Node</span><E> {</span><br><span class="line"> E item;</span><br><span class="line"> Node<E> next;</span><br><span class="line"> Node<E> prev;</span><br><span class="line"> Node(Node<E> prev, E element, Node<E> next) {</span><br><span class="line"> <span class="built_in">this</span>.item = element;</span><br><span class="line"> <span class="built_in">this</span>.next = next;</span><br><span class="line"> <span class="built_in">this</span>.prev = prev;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="Stack"><a href="#Stack" class="headerlink" title="Stack"></a><strong>Stack</strong></h2><blockquote><p>Stack是栈 特点是先进后出 </p><p> LIFO:last in first out</p><p>方法:</p><p> push:压栈 </p><p> pop:弹出</p><p> peek:获得栈顶的元素</p><p>栈的用途:</p><p>悔棋</p><p>撤销</p><p>方法的调用</p></blockquote><h2 id="Queue"><a href="#Queue" class="headerlink" title="Queue"></a><strong>Queue</strong></h2><blockquote><p>Queue是一个队列,它的特点是先进先出(FIFO)</p></blockquote><h2 id="双端队列"><a href="#双端队列" class="headerlink" title="双端队列"></a>双端队列</h2><blockquote><p>Deque =dubole ended queue</p><p>两端都可以插入和删除元素 </p><p>方法如下 </p><p> addFirst</p><p> addLast</p><p> removeFist</p><p> removeLast</p><p> offerFirst</p><p> offerLast</p><p> pollFirst</p><p> pollLast</p></blockquote><h1 id="集合框架2"><a href="#集合框架2" class="headerlink" title="集合框架2"></a>集合框架2</h1><h2 id="Set"><a href="#Set" class="headerlink" title="Set"></a>Set</h2><blockquote><p>Set:是Collection的子接口,无序,不可重复</p><p>三个主要的实现类 </p><p>HashSet:hash</p><p>LinkedHashList:有顺序 </p><p>TreeSet:排序的,内部是树 </p></blockquote><h2 id="Iterator"><a href="#Iterator" class="headerlink" title="Iterator"></a><strong>Iterator</strong></h2><blockquote><p>迭代器 用来从所有的Collection集合中遍历数组 提供三个方法 </p><p>boolean hasNext():是否有下一个未遍历到的元素 </p><p>E next():取出一个元素 </p><p>void remove():删除正在取出的元素 </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></pre></td><td class="code"><pre><span class="line"><span class="comment">//代码模版如下 </span></span><br><span class="line">Iteartor ite=collection.iterator();</span><br><span class="line"> <span class="keyword">while</span>(ite.hasNext()){</span><br><span class="line"> E e=ite.next();</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="LinkedHashSet"><a href="#LinkedHashSet" class="headerlink" title="LinkedHashSet"></a><strong>LinkedHashSet</strong></h2><blockquote><p>LinkedHashSet是对HashSet的扩展,内部也是一个HashSet,但是按存入的顺序进行排列的</p><p>LinkdeHashSet中的元素也是不可重复的</p></blockquote><h2 id="SortedSet"><a href="#SortedSet" class="headerlink" title="SortedSet"></a><strong>SortedSet</strong></h2><blockquote><p>SortedSet:是Set的子接口,具备排序的能力 </p><p>TreeSet:是SortedSet的实现类,内部是一个树结构</p></blockquote><p><img src="https://s3.bmp.ovh/imgs/2023/02/25/0f0daa7cf5dd4d9f.png"></p><h2 id="Map"><a href="#Map" class="headerlink" title="Map"></a><strong>Map</strong></h2><blockquote><p>1.Map是集合框架中的另一个顶层接口 Map结构的特点是 kev-value</p><p>2.集合中,key 是不可以重复的</p><p>3.key 和 value的类型都是引用类型</p></blockquote><p>常用方法</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><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">put(k,v):增加一对元素</span><br><span class="line">putAll(Map):将map中的所有元素增加到集合中</span><br><span class="line">v <span class="title function_">get</span><span class="params">(k)</span>:根据key,来查找value</span><br><span class="line"><span class="title function_">remove</span><span class="params">(k)</span>:根据key,来删除元素(key-value)</span><br><span class="line"><span class="type">int</span> <span class="title function_">size</span><span class="params">()</span>:获取集合中元素的个数</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">isEmpty</span><span class="params">()</span>:是否为空</span><br><span class="line">clear():清空</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">containsKey</span><span class="params">(k)</span>:是否包含某个key</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">containsValue</span><span class="params">(v)</span>:是否包含某个value</span><br><span class="line">#遍历</span><br><span class="line">Set <span class="title function_">keySet</span><span class="params">()</span>:得到所有的key的集合</span><br><span class="line">Collection <span class="title function_">values</span><span class="params">()</span>:获得所有value的集合</span><br><span class="line">entrySet():获得所有的元素的集合(Entry(key,value))</span><br></pre></td></tr></table></figure><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><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></pre></td><td class="code"><pre><span class="line"> <span class="comment">//遍历的示例</span></span><br><span class="line"> Map<Integer, String> map = <span class="keyword">new</span> <span class="title class_">HashMap</span><Integer, String>();</span><br><span class="line"><span class="comment">//增加</span></span><br><span class="line"> map.put(<span class="number">1</span>,<span class="string">"james"</span>);</span><br><span class="line"> map.put(<span class="number">2</span>,<span class="string">"jack"</span>);</span><br><span class="line"> map.put(<span class="number">3</span>,<span class="string">"james"</span>);</span><br><span class="line"> map.put(<span class="number">4</span>,<span class="string">"owen"</span>);</span><br><span class="line"> map.put(<span class="number">3</span>,<span class="string">"scott"</span>);</span><br><span class="line"> <span class="comment">//1.如何遍历集合 keySet</span></span><br><span class="line"> Set<Integer> set = map.keySet();</span><br><span class="line">System.out.println(set);</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line"> Integer k:set)</span><br><span class="line"></span><br><span class="line"> {</span><br><span class="line"> System.out.println(k + <span class="string">":"</span> + map.get(k));</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//2.values</span></span><br><span class="line"> Collection<String> coll = map.values();</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line"> String s:coll)</span><br><span class="line"></span><br><span class="line"> {</span><br><span class="line"> System.out.println(s);</span><br><span class="line"> }</span><br><span class="line">System.out.println(<span class="string">"----------------"</span>);</span><br><span class="line"> <span class="comment">//3.key-value</span></span><br><span class="line"> Set<Entry<Integer, String>> es = map.entrySet();</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line"> Entry<Integer, String> e:es)</span><br><span class="line"></span><br><span class="line"> {</span><br><span class="line"> System.out.println(e.getKey() + <span class="string">":"</span> + e.getValue());</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h2 id="HashMap的内部结构"><a href="#HashMap的内部结构" class="headerlink" title="HashMap的内部结构"></a><strong>HashMap</strong>的内部结构</h2><blockquote><p>1.key-value在内部被封装成了一个内部类 Node</p><p>2.HashMap中定义了一个Node类型的数组用来保存元素</p><p>3.Node还是一个单向链表 当链表中的元素超过8时,则转换成红黑树</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></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Node</span><K,V> <span class="keyword">implements</span> <span class="title class_">Map</span>.Entry<K,V> {</span><br><span class="line"> <span class="keyword">final</span> <span class="type">int</span> hash;</span><br><span class="line"> <span class="keyword">final</span> K key; <span class="comment">//key</span></span><br><span class="line"> V value; <span class="comment">//value</span></span><br><span class="line"> Node<K,V> next; <span class="comment">//下一个节点,Node是封装了key和value,同时也是一个单向链表 </span></span><br><span class="line"> Node(<span class="type">int</span> hash, K key, V value, Node<K,V> next) {</span><br><span class="line"> <span class="built_in">this</span>.hash = hash;</span><br><span class="line"> <span class="built_in">this</span>.key = key;</span><br><span class="line"> <span class="built_in">this</span>.value = value;</span><br><span class="line"> <span class="built_in">this</span>.next = next;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">transient</span> Node<K,V>[] table; <span class="comment">//将所有的key-value对,即node,都存在table中,table是一个数组</span></span><br></pre></td></tr></table></figure><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></pre></td><td class="code"><pre><span class="line"><span class="comment">//put方法</span></span><br><span class="line"><span class="keyword">public</span> V <span class="title function_">put</span><span class="params">(K key, V value)</span> {</span><br><span class="line"> <span class="keyword">return</span> putVal(hash(key), key, value, <span class="literal">false</span>, <span class="literal">true</span>);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><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><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></pre></td><td class="code"><pre><span class="line"> <span class="keyword">final</span> V <span class="title function_">putVal</span><span class="params">(<span class="type">int</span> hash, K key, V value, <span class="type">boolean</span> onlyIfAbsent,</span></span><br><span class="line"><span class="params"> <span class="type">boolean</span> evict)</span> {</span><br><span class="line"> Node<K, V>[] tab; <span class="comment">//table的引用</span></span><br><span class="line"> Node<K, V> p; <span class="comment">//元素中的首个Node节点 </span></span><br><span class="line"> <span class="type">int</span> n; <span class="comment">//table的长度</span></span><br><span class="line"> <span class="type">int</span> i; <span class="comment">//元素的下标 通过hash后,模运行(实际是 (n - 1) & hash])</span></span><br><span class="line"> <span class="keyword">if</span> ((tab = table) == <span class="literal">null</span> || (n = tab.length) == <span class="number">0</span>)</span><br><span class="line"> n = (tab = resize()).length; <span class="comment">//重新分配长度,算出tal的长度</span></span><br><span class="line"><span class="comment">//如果元素中无值,则将Node放在索引为i的下标下 </span></span><br><span class="line"> <span class="keyword">if</span> ((p = tab[i = (n - <span class="number">1</span>) & hash]) == <span class="literal">null</span>)</span><br><span class="line"> tab[i] = newNode(hash, key, value, <span class="literal">null</span>);</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> Node<K, V> e; <span class="comment">//如果有相同的key,e存储的是重复节点的引用 </span></span><br><span class="line"> K k;</span><br><span class="line"><span class="comment">//如果元素中的首Node与新节点相同 则</span></span><br><span class="line"> <span class="keyword">if</span> (p.hash == hash &&</span><br><span class="line"> ((k = p.key) == key || (key != <span class="literal">null</span> && key.equals(k))))</span><br><span class="line"> e = p;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (p <span class="keyword">instanceof</span> TreeNode) <span class="comment">//如果是树结点,则使用树节点的方式查找 </span></span><br><span class="line"> e = ((TreeNode<K, V>) p).putTreeVal(<span class="built_in">this</span>, tab, hash, key, value);</span><br><span class="line"> <span class="keyword">else</span> {<span class="comment">//遍历链表,如果有重复的,将重复的节点赋值给e,并break,否则,将新节点加到</span></span><br><span class="line"> 链表尾部</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">binCount</span> <span class="operator">=</span> <span class="number">0</span>; ; ++binCount) {</span><br><span class="line"> <span class="keyword">if</span> ((e = p.next) == <span class="literal">null</span>) {<span class="comment">//链表中最后一个结点</span></span><br><span class="line"> p.next = newNode(hash, key, value, <span class="literal">null</span>);</span><br><span class="line"><span class="comment">//如果长度大于8,则转成树</span></span><br><span class="line"> <span class="keyword">if</span> (binCount >= TREEIFY_THRESHOLD - <span class="number">1</span>) <span class="comment">// -1 for 1st</span></span><br><span class="line"> treeifyBin(tab, hash);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"><span class="comment">//如果有重复的,则不再比较</span></span><br><span class="line"> <span class="keyword">if</span> (e.hash == hash &&</span><br><span class="line"> ((k = e.key) == key || (key != <span class="literal">null</span> && key.equals(k))))</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> p = e;<span class="comment">//指向链表的下一个元素,用来遍历 </span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (e != <span class="literal">null</span>) { <span class="comment">// existing mapping for key 如果有重复的,进行替换</span></span><br><span class="line"> <span class="type">V</span> <span class="variable">oldValue</span> <span class="operator">=</span> e.value;</span><br><span class="line"> <span class="keyword">if</span> (!onlyIfAbsent || oldValue == <span class="literal">null</span>)<span class="comment">//根据onlyIfAbsend决定是否替</span></span><br><span class="line"> 换</span><br><span class="line"> e.value = value;</span><br><span class="line"> afterNodeAccess(e);</span><br><span class="line"> <span class="keyword">return</span> oldValue;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ++modCount;</span><br><span class="line"> <span class="keyword">if</span> (++size > threshold)</span><br><span class="line"> resize();</span><br><span class="line"> afterNodeInsertion(evict);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h2 id="Hashtable"><a href="#Hashtable" class="headerlink" title="Hashtable"></a><strong>Hashtable</strong></h2><blockquote><p>Hashtable 是一个古老的 Map 实现类,不建议使用</p><p>Hashtable 是一个线程安全的 Map 实现,但 HashMap 是线程不安全的。</p><p>Hashtable 不允许使用 null 作为 key 和 value,而 HashMap 可以</p></blockquote><h2 id="TreeMap"><a href="#TreeMap" class="headerlink" title="TreeMap"></a><strong>TreeMap</strong></h2><blockquote><p>TreeMap 存储 Key-Value 对时,需要根据 Key 对 key-value 对进行排序。TreeMap 内部是同红黑</p><p>树来实现的。</p><p>TreeMap 的 Key 的排序:</p><p>自然排序:TreeMap 的所有的 Key 必须实现 Comparable 接口,而且所有的 Key 应该是同一个类的对</p><p>象,否则将会抛出 ClasssCastException</p><p>定制排序:创建 TreeMap 时,传入一个 Comparator 对象,该对象负责对 TreeMap 中的所有 key 进</p><p>行排序。此时不需要 Map 的 Key 实现 Comparable 接口</p></blockquote><h3 id=""><a href="#" class="headerlink" title=""></a></h3>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> Java </tag>
</tags>
</entry>
<entry>
<title>Elasticsearch 入门</title>
<link href="/2023/02/24/Elasticsearch_%E5%85%A5%E9%97%A8/"/>
<url>/2023/02/24/Elasticsearch_%E5%85%A5%E9%97%A8/</url>
<content type="html"><![CDATA[<h2 id="Elasticsearch-入门"><a href="#Elasticsearch-入门" class="headerlink" title="Elasticsearch 入门"></a>Elasticsearch 入门</h2><p>由于工作需要,所以不得不接触es。而且还要我写相关的工具类,虽然说照葫芦画瓢容易,但是了解到这个东西之后,就想好好学习以下。当然了也算作我的个人笔记,大部分都是看官方文章的记录,所以不会标注版权什么的,官方链接下面会有,想深入了解可以去看看。</p><h3 id="es介绍"><a href="#es介绍" class="headerlink" title="es介绍"></a>es介绍</h3><blockquote><p>Elasticsearch是一个搜索引擎</p></blockquote><p>下面简称为es</p><blockquote><p>Elasticsearch 是一个分布式、免费和开放的搜索和分析引擎,适用于所有类型的数据,包括文本、数字、地理空间、结构化和非结构化数据。 Elasticsearch 基于 Apache Lucene 构建,并于 2010 年由 Elasticsearch N.V. 首次发布(现在称为 Elastic)。Elasticsearch 以其简单的 REST API、分布式特性、速度和可扩展性而闻名,是 Elastic Stack 的核心组件,Elastic Stack 是一组用于数据摄取、丰富、存储、分析和可视化的免费开放工具。 通常被称为 ELK Stack。</p></blockquote><p>上面是官方原话,感兴趣的可以去看看。链接贴在这里</p><p><a href="https://elasticstack.blog.csdn.net/article/details/98871531">Elasticsearch 简介</a></p><h3 id="es能做什么?"><a href="#es能做什么?" class="headerlink" title="es能做什么?"></a>es能做什么?</h3><blockquote><p>Elasticsearch 的速度和可扩展性及其为多种类型的内容编制索引的能力意味着它可用于多种用例:</p><p>应用搜索,比如我们常见的 github,linkedin,滴滴,美团,抖音,点评,音乐,视频,银行,证券,保险,电信 app 里的搜索<br>网站搜索<br>企业搜索<br>日志记录和日志分析<br>基础设施指标和容器监控<br>应用性能监控<br>地理空间数据分析和可视化<br>安全分析<br>商业分析</p></blockquote><p>公司平常就用这个存一些数据,比如日志什么。速度确实快</p><h4 id="es安装"><a href="#es安装" class="headerlink" title="es安装"></a>es安装</h4><p>公司用的是Linux,所以下面我会贴出win和Linux的安装方法。</p><h4 id="Java(JVM)版本"><a href="#Java(JVM)版本" class="headerlink" title="Java(JVM)版本"></a>Java(JVM)版本</h4><blockquote><p>Elasticsearch是使用Java构建的,包括JDK维护者的OpenJDK捆绑版本(GPLv2 + CE)。 在每个分布中。捆绑的 JVM 是推荐的 JVM 和 位于 Elasticsearch 主目录的目录中。jdk要使用您自己的 Java 版本,请设置环境变量。 如果必须使用与捆绑的 JVM 不同的 Java 版本。请看supported LTS version of Java</p></blockquote><p><img src="https://s3.bmp.ovh/imgs/2023/02/24/db05e724e6b8ad0e.png"></p><p>尽量选择LTS</p><h4 id="Windows安装"><a href="#Windows安装" class="headerlink" title="Windows安装"></a>Windows安装</h4><p>从该位置下载.zip 文件</p><p><a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-windows-x86_64.zip">地址</a></p><p>下载完找个舒服的地方解压就行惹</p><p><img src="https://s3.bmp.ovh/imgs/2023/02/24/a93cdd18e8c37f50.png"></p><p>在bin目录下找到 <code>elasticsearch.bat</code> 启动就好了。也可以通过cmd来启动,不过最好用管理员权限打开喔</p><p>然后我们在浏览器或者postman上面输入 <code>http://localhost:9200/</code> 会出现以下信息</p><p><img src="https://s3.bmp.ovh/imgs/2023/02/24/04571b8c08ba9a1b.png"></p><p>其中config里面的 <code>elasticsearch.yml</code> 是配置文件 里面的</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">network.host:</span> <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span></span><br></pre></td></tr></table></figure><p>如果你想让其他人访问es 可以改成0.0.0.0,这样会绑定成任意IP 而非localhost 。这里和redis改bind差不多</p><h4 id="Linux安装"><a href="#Linux安装" class="headerlink" title="Linux安装"></a>Linux安装</h4><p>下载:<a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.3.0-linux-x86_64.tar.gz">地址</a></p><ol><li><p>创建用户</p><p>es禁止root用户启动,所以我们创建一个新用户es</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">adduser es</span><br><span class="line"><span class="comment">#修改密码</span></span><br><span class="line">passwes</span><br></pre></td></tr></table></figure></li><li><p>创建es的数据、日志目录</p><figure class="highlight bash"><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">#创建日志目录</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /data/elasticsearch/logs</span><br><span class="line"></span><br><span class="line"><span class="comment">#授权</span></span><br><span class="line"><span class="built_in">chown</span> es:es -R /data/</span><br></pre></td></tr></table></figure></li><li><p>解压es安装包</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf elasticsearch-oss-7.3.0-linux-x86_64.tar.gz</span><br></pre></td></tr></table></figure></li><li><p>授权</p><figure class="highlight bash"><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">chown</span> es:es -R /opt/elasticsearch-oss-7.3.0-linux-x86_64</span><br></pre></td></tr></table></figure><p>将权限都给es这个用户</p></li><li><p>修改yml</p><p>在elasticsearch.yml中修改下面属性</p><figure class="highlight yml"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 集群名称</span></span><br><span class="line"><span class="attr">cluster.name:</span> <span class="string">ihbe-cluster</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 节点名称,其余两个节点分别为node-2 和node-3,别一样 (集群)</span></span><br><span class="line"><span class="attr">node.name:</span> <span class="string">node-1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定该节点是否有资格被选举成为master节点,默认为true (集群)</span></span><br><span class="line"><span class="attr">node.master:</span> <span class="literal">true</span></span><br><span class="line"><span class="comment"># 允许该节点存储数据(默认开启)</span></span><br><span class="line"><span class="attr">node.data:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 索引数据的存储路径</span></span><br><span class="line"><span class="attr">path.data:</span> <span class="string">/data/elasticsearch/data</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 日志文件的存储路径</span></span><br><span class="line"><span class="attr">path.logs:</span> <span class="string">/data/elasticsearch/logs</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 绑定当前机器节点的IP地址, 其他节点配置自己的IP地址</span></span><br><span class="line"><span class="attr">network.host:</span> <span class="string">*.*.*.*</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置对外服务的http端口,默认为9200</span></span><br><span class="line"><span class="attr">http.port:</span> <span class="number">9200</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置节点间交互的tcp端口,默认为9300</span></span><br><span class="line"><span class="attr">transport.tcp.port:</span> <span class="number">9300</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#集群的所有机器节点的IP地址</span></span><br><span class="line"><span class="string">discovery.zen.ping.unicast.hosts:["*.*.*.*","*.*.*.*","*.*.*.*"]</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#通过配置大多数节点(符合主节点数/ 2 + 1)来防止分裂。</span></span><br><span class="line"><span class="attr">discovery.zen.minimum_master_nodes:</span> <span class="number">2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#设置为true锁住内存。因为内存交换到磁盘对服务器性能是致命的</span></span><br><span class="line"><span class="attr">bootstrap.memory_lock:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure></li><li><p>修改jvm启动项</p><p>进入config,找到<code>jvm.options</code> vi进入编辑</p><figure class="highlight properties"><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="comment"># 配置ES占用物理内存大小,根据具体机器本身大小来定,一半物理内存</span></span><br><span class="line"><span class="attr">-Xms20g</span></span><br><span class="line"></span><br><span class="line"><span class="attr">-Xmx20g</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 修正CVE-2021-44228漏洞</span></span><br><span class="line"></span><br><span class="line"><span class="attr">-Dlog4j2.formatMsgNoLookups</span>=<span class="string">true </span></span><br></pre></td></tr></table></figure></li><li><p>(集群) 拷贝目录到其他节点</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scp -r /opt/elasticsearch root@*.*.*.*:/opt/</span><br></pre></td></tr></table></figure><p>注意这里的文件夹,是你安装的文件夹名,我这里简写了。不要直接复制改一改名字。<br><code>同时重复第5步操作,将yml里面的network.host</code>改成当前服务器的ip,然后<code>找到node.name:</code>改成其他名字,(与其他节点不重复)</p></li><li><p>启动服务<br>到安装es的节点下</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./bin/elasticsearch -d -p pid</span><br></pre></td></tr></table></figure><p>使用jps看是否启动</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jps</span><br></pre></td></tr></table></figure></li><li><p>验证</p><p>在任意的服务器上面<br>验证集群</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -XGET <span class="string">'http://*.*.*.*:9200/_cat/nodes?pretty'</span></span><br></pre></td></tr></table></figure><p>如果能正确显示每个节点ip则成功</p><p>查询集群状态</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -XGET <span class="string">'http://*.*.*.*:9200/_cluster/nodes?pretty'</span></span><br></pre></td></tr></table></figure><p>在返回的json中,看<code>status</code>的值<br><code>-green</code> 正常,表示集群一切正常。<br><code>-yellow</code> 黄表示集群不可靠但可用,一般单节时候就是这个状态。<br><code>-red</code> 红表示集群不可用,有故障。</p><p>关闭es</p><p>使用jps查询进程ID<br>然后kill -9</p></li></ol>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> Elasticsearch </tag>
</tags>
</entry>
<entry>
<title>博客基础用法</title>
<link href="/2023/02/23/%E5%8D%9A%E5%AE%A2%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95/"/>
<url>/2023/02/23/%E5%8D%9A%E5%AE%A2%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95/</url>
<content type="html"><![CDATA[<p>这一篇主要讲解写文章所需要的一些配置</p><p>1.运行<code>hexo new 博客名</code></p><p>2.复制显示的路径,使用 <code>xdg-open 路径</code> 来编辑它</p><p>3.运行<code>hexo generate</code></p><p>4.运行<code>hexo deploy</code> 然后就可以看新写的博客了</p><h2 id="Front-matter"><a href="#Front-matter" class="headerlink" title="Front-matter"></a>Front-matter</h2><ul><li><h3 id="Page-Front-matter-用于页面配置"><a href="#Page-Front-matter-用于页面配置" class="headerlink" title="Page Front-matter 用于页面配置"></a>Page Front-matter 用于页面配置</h3><figure class="highlight markdown"><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></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title:</span><br><span class="line">date:</span><br><span class="line">updated:</span><br><span class="line">type:</span><br><span class="line">comments:</span><br><span class="line">description:</span><br><span class="line">keywords:</span><br><span class="line">top<span class="emphasis">_img:</span></span><br><span class="line"><span class="emphasis">mathjax:</span></span><br><span class="line"><span class="emphasis">katex:</span></span><br><span class="line"><span class="emphasis">aside:</span></span><br><span class="line"><span class="emphasis">aplayer:</span></span><br><span class="line"><span class="emphasis">highlight_</span>shrink:</span><br><span class="line">---</span><br></pre></td></tr></table></figure><table><thead><tr><th align="center">解释</th><th align="center">用法</th></tr></thead><tbody><tr><td align="center">updated</td><td align="center">【可选】页面更新日期</td></tr><tr><td align="center">description</td><td align="center">【可选】页面描述</td></tr><tr><td align="center">keywords</td><td align="center">【可选】页面关键字</td></tr><tr><td align="center">comments</td><td align="center">【可选】显示页面评论模块(默认 true)</td></tr><tr><td align="center">top_img</td><td align="center">【可选】页面顶部图片</td></tr><tr><td align="center">mathjax</td><td align="center">【可选】显示mathjax(当设置mathjax的per_page: false时,才需要配置,默认 false)</td></tr><tr><td align="center">kates</td><td align="center">【可选】显示katex(当设置katex的per_page: false时,才需要配置,默认 false)</td></tr><tr><td align="center">aside</td><td align="center">【可选】显示侧边栏 (默认 true)</td></tr><tr><td align="center">aplayer</td><td align="center">【可选】在需要的页面加载aplayer的js和css,请参考文章下面的音乐 配置</td></tr><tr><td align="center">highlight_shrink</td><td align="center">【可选】配置代码框是否展开(true/false)(默认为设置中highlight_shrink的配置)</td></tr></tbody></table></li><li><h3 id="Post-Front-matter-用于页面配置"><a href="#Post-Front-matter-用于页面配置" class="headerlink" title="Post Front-matter 用于页面配置"></a>Post Front-matter 用于页面配置</h3><figure class="highlight markdown"><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><br><span class="line">title:</span><br><span class="line">date:</span><br><span class="line">updated:</span><br><span class="line">tags:</span><br><span class="line">categories:</span><br><span class="line">keywords:</span><br><span class="line">description:</span><br><span class="line">top<span class="emphasis">_img:</span></span><br><span class="line"><span class="emphasis">comments:</span></span><br><span class="line"><span class="emphasis">cover:</span></span><br><span class="line"><span class="emphasis">toc:</span></span><br><span class="line"><span class="emphasis">toc_</span>number:</span><br><span class="line">toc<span class="emphasis">_style_</span>simple:</span><br><span class="line">copyright:</span><br><span class="line">copyright<span class="emphasis">_author:</span></span><br><span class="line"><span class="emphasis">copyright_</span>author<span class="emphasis">_href:</span></span><br><span class="line"><span class="emphasis">copyright_</span>url:</span><br><span class="line">copyright<span class="emphasis">_info:</span></span><br><span class="line"><span class="emphasis">mathjax:</span></span><br><span class="line"><span class="emphasis">katex:</span></span><br><span class="line"><span class="emphasis">aplayer:</span></span><br><span class="line"><span class="emphasis">highlight_</span>shrink:</span><br><span class="line"><span class="section">aside:</span></span><br><span class="line"><span class="section">---</span></span><br></pre></td></tr></table></figure></li></ul><table><thead><tr><th align="center">解释</th><th align="center">用法</th></tr></thead><tbody><tr><td align="center">title</td><td align="center">【必需】文章标题</td></tr><tr><td align="center">date</td><td align="center">【必需】文章创建日期</td></tr><tr><td align="center">updated</td><td align="center">【可选】文章更新日期</td></tr><tr><td align="center">tags</td><td align="center">【可选】文章标籤</td></tr><tr><td align="center">categories</td><td align="center">【可选】文章分类</td></tr><tr><td align="center">keywords</td><td align="center">【可选】文章关键字</td></tr><tr><td align="center">description</td><td align="center">【可选】文章描述</td></tr><tr><td align="center">top_img</td><td align="center">【可选】文章顶部图片</td></tr><tr><td align="center">cover</td><td align="center">【可选】文章缩略图(如果没有设置top_img,文章页顶部将显示缩略图,可设为 false/图片地址/留空)</td></tr><tr><td align="center">comments</td><td align="center">【可选】显示文章评论模块(默认 true)</td></tr><tr><td align="center">toc</td><td align="center">【可选】显示文章TOC(默认为设置中toc的enable配置)</td></tr><tr><td align="center">toc_number</td><td align="center">【可选】显示toc_number(默认为设置中toc的number配置)</td></tr><tr><td align="center">toc_style_simple</td><td align="center">【可选】显示 toc 简洁模式</td></tr><tr><td align="center">copyright</td><td align="center">【可选】显示文章版权模块(默认为设置中post_copyright的enable配置)</td></tr><tr><td align="center">copyright_author</td><td align="center">【可选】文章版权模块的文章作者</td></tr><tr><td align="center">copyright_author_href</td><td align="center">【可选】文章版权模块的文章作者链接</td></tr><tr><td align="center">copyright_url</td><td align="center">【可选】文章版权模块的文章连结链接</td></tr><tr><td align="center">copyright_info</td><td align="center">【可选】文章版权模块的版权声明文字</td></tr><tr><td align="center">mathjax</td><td align="center">【可选】显示mathjax(当设置mathjax的per_page: false时,才需要配置,默认 false)</td></tr><tr><td align="center">katex</td><td align="center">【可选】显示katex(当设置katex的per_page: false时,才需要配置,默认 false)</td></tr><tr><td align="center">aplayer</td><td align="center">【可选】在需要的页面加载aplayer的js和css,请参考文章下面的音乐 配置</td></tr><tr><td align="center">highlight_shrink</td><td align="center">【可选】配置代码框是否展开(true/false)(默认为设置中highlight_shrink的配置)</td></tr><tr><td align="center">aside</td><td align="center">【可选】显示侧边栏 (默认 true)</td></tr></tbody></table>]]></content>
<categories>
<category> 基础 </category>
</categories>
<tags>
<tag> 博客 </tag>
</tags>
</entry>
</search>