-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
2155 lines (1601 loc) · 148 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[SargerasWang's Blog]]></title>
<link href="https://sargeraswang.com/atom.xml" rel="self"/>
<link href="https://sargeraswang.com/"/>
<updated>2018-11-28T10:22:37+08:00</updated>
<id>https://sargeraswang.com/</id>
<author>
<name><![CDATA[SargerasWang]]></name>
<email><![CDATA[sargeraswang@gmail.com]]></email>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[ExcelUtil 1.2.1 doc]]></title>
<link href="https://sargeraswang.com/blog/2018/11/27/excelutil-1-dot-2-1-doc/"/>
<updated>2018-11-27T17:08:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/27/excelutil-1-dot-2-1-doc</id>
<content type="html"><![CDATA[<p><a href="https://github.com/SargerasWang/ExcelUtil">GitHub地址</a></p>
<p>事实上,使用方式在 <code>test</code> 中有,因为有这个Issue,所以贴到这里来.</p>
<!--more-->
<h4>数据模型</h4>
<p>通常可以使用你的数据表bean,当然如果需要导入/导出的字段与数据表差异很大,可以新增bean,当然也可以跳过bean,直接使用<code>Map</code>,下面是示例Bean:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Model</span> <span class="o">{</span>
</span><span class='line'> <span class="nd">@ExcelCell</span><span class="o">(</span><span class="n">index</span> <span class="o">=</span> <span class="mi">0</span><span class="o">)</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">String</span> <span class="n">a</span><span class="o">;</span>
</span><span class='line'> <span class="nd">@ExcelCell</span><span class="o">(</span><span class="n">index</span> <span class="o">=</span> <span class="mi">1</span><span class="o">)</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">String</span> <span class="n">b</span><span class="o">;</span>
</span><span class='line'> <span class="nd">@ExcelCell</span><span class="o">(</span><span class="n">index</span> <span class="o">=</span> <span class="mi">2</span><span class="o">)</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">String</span> <span class="n">c</span><span class="o">;</span>
</span><span class='line'> <span class="nd">@ExcelCell</span><span class="o">(</span><span class="n">index</span> <span class="o">=</span> <span class="mi">3</span><span class="o">)</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">Date</span> <span class="n">d</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="n">Date</span> <span class="nf">getD</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'> <span class="k">return</span> <span class="n">d</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setD</span><span class="o">(</span><span class="n">Date</span> <span class="n">d</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="nf">Model</span><span class="o">(</span><span class="n">String</span> <span class="n">a</span><span class="o">,</span> <span class="n">String</span> <span class="n">b</span><span class="o">,</span> <span class="n">String</span> <span class="n">c</span><span class="o">,</span><span class="n">Date</span> <span class="n">d</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">a</span> <span class="o">=</span> <span class="n">a</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">b</span> <span class="o">=</span> <span class="n">b</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">c</span> <span class="o">=</span> <span class="n">c</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">//setter and getter 省略...</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<h4>导出-Bean方式</h4>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'> <span class="c1">//用排序的Map且Map的键应与ExcelCell注解的index对应</span>
</span><span class='line'> <span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">String</span><span class="o">></span> <span class="n">map</span> <span class="o">=</span> <span class="k">new</span> <span class="n">LinkedHashMap</span><span class="o"><>();</span>
</span><span class='line'> <span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"a"</span><span class="o">,</span><span class="s">"姓名"</span><span class="o">);</span>
</span><span class='line'> <span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"b"</span><span class="o">,</span><span class="s">"年龄"</span><span class="o">);</span>
</span><span class='line'> <span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"c"</span><span class="o">,</span><span class="s">"性别"</span><span class="o">);</span>
</span><span class='line'> <span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"d"</span><span class="o">,</span><span class="s">"出生日期"</span><span class="o">);</span>
</span><span class='line'> <span class="n">Collection</span><span class="o"><</span><span class="n">Object</span><span class="o">></span> <span class="n">dataset</span><span class="o">=</span><span class="k">new</span> <span class="n">ArrayList</span><span class="o"><</span><span class="n">Object</span><span class="o">>();</span>
</span><span class='line'> <span class="n">dataset</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="n">Model</span><span class="o">(</span><span class="s">""</span><span class="o">,</span> <span class="s">""</span><span class="o">,</span> <span class="s">""</span><span class="o">,</span><span class="kc">null</span><span class="o">));</span>
</span><span class='line'> <span class="n">dataset</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="n">Model</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span><span class="kc">null</span><span class="o">));</span>
</span><span class='line'> <span class="n">dataset</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="n">Model</span><span class="o">(</span><span class="s">"王五"</span><span class="o">,</span> <span class="s">"34"</span><span class="o">,</span> <span class="s">"男"</span><span class="o">,</span><span class="k">new</span> <span class="n">Date</span><span class="o">()));</span>
</span><span class='line'> <span class="n">File</span> <span class="n">f</span><span class="o">=</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">"test.xls"</span><span class="o">);</span>
</span><span class='line'> <span class="n">OutputStream</span> <span class="n">out</span> <span class="o">=</span><span class="k">new</span> <span class="n">FileOutputStream</span><span class="o">(</span><span class="n">f</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'> <span class="n">ExcelUtil</span><span class="o">.</span><span class="na">exportExcel</span><span class="o">(</span><span class="n">map</span><span class="o">,</span> <span class="n">dataset</span><span class="o">,</span> <span class="n">out</span><span class="o">);</span>
</span><span class='line'> <span class="n">out</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
</span></code></pre></td></tr></table></div></figure>
<h4>导出-Map方式</h4>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">List</span><span class="o"><</span><span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">Object</span><span class="o">>></span> <span class="n">list</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="o"><>();</span>
</span><span class='line'><span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">Object</span><span class="o">></span> <span class="n">map</span> <span class="o">=</span><span class="k">new</span> <span class="n">LinkedHashMap</span><span class="o"><>();</span>
</span><span class='line'><span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="s">""</span><span class="o">);</span>
</span><span class='line'><span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"age"</span><span class="o">,</span> <span class="s">""</span><span class="o">);</span>
</span><span class='line'><span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"birthday"</span><span class="o">,</span><span class="s">""</span><span class="o">);</span>
</span><span class='line'><span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"sex"</span><span class="o">,</span><span class="s">""</span><span class="o">);</span>
</span><span class='line'><span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">Object</span><span class="o">></span> <span class="n">map2</span> <span class="o">=</span><span class="k">new</span> <span class="n">LinkedHashMap</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">>();</span>
</span><span class='line'><span class="n">map2</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="s">"测试是否是中文长度不能自动宽度.测试是否是中文长度不能自动宽度."</span><span class="o">);</span>
</span><span class='line'><span class="n">map2</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"age"</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
</span><span class='line'><span class="n">map2</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"sex"</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
</span><span class='line'><span class="n">map</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"birthday"</span><span class="o">,</span><span class="kc">null</span><span class="o">);</span>
</span><span class='line'><span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">Object</span><span class="o">></span> <span class="n">map3</span> <span class="o">=</span><span class="k">new</span> <span class="n">LinkedHashMap</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">>();</span>
</span><span class='line'><span class="n">map3</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="s">"张三"</span><span class="o">);</span>
</span><span class='line'><span class="n">map3</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"age"</span><span class="o">,</span> <span class="mi">12</span><span class="o">);</span>
</span><span class='line'><span class="n">map3</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"sex"</span><span class="o">,</span> <span class="s">"男"</span><span class="o">);</span>
</span><span class='line'><span class="n">map3</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"birthday"</span><span class="o">,</span><span class="k">new</span> <span class="n">Date</span><span class="o">());</span>
</span><span class='line'><span class="n">list</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">map</span><span class="o">);</span>
</span><span class='line'><span class="n">list</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">map2</span><span class="o">);</span>
</span><span class='line'><span class="n">list</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">map3</span><span class="o">);</span>
</span><span class='line'><span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span><span class="n">String</span><span class="o">></span> <span class="n">map1</span> <span class="o">=</span> <span class="k">new</span> <span class="n">LinkedHashMap</span><span class="o"><>();</span>
</span><span class='line'><span class="n">map1</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span><span class="s">"姓名"</span><span class="o">);</span>
</span><span class='line'><span class="n">map1</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"age"</span><span class="o">,</span><span class="s">"年龄"</span><span class="o">);</span>
</span><span class='line'><span class="n">map1</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"birthday"</span><span class="o">,</span><span class="s">"出生日期"</span><span class="o">);</span>
</span><span class='line'><span class="n">map1</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"sex"</span><span class="o">,</span><span class="s">"性别"</span><span class="o">);</span>
</span><span class='line'><span class="n">File</span> <span class="n">f</span><span class="o">=</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">"test.xls"</span><span class="o">);</span>
</span><span class='line'><span class="n">OutputStream</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FileOutputStream</span><span class="o">(</span><span class="n">f</span><span class="o">);</span>
</span><span class='line'><span class="n">ExcelUtil</span><span class="o">.</span><span class="na">exportExcel</span><span class="o">(</span><span class="n">map1</span><span class="o">,</span><span class="n">list</span><span class="o">,</span> <span class="n">out</span> <span class="o">);</span>
</span><span class='line'><span class="n">out</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
</span></code></pre></td></tr></table></div></figure>
<h4>导入</h4>
<p><code>ExcelUtil.importExcel</code> 方法的第一个参数,是个<code>Class</code>,如果你有<code>Bean</code>,就写Bean的Class,反之,直接<code>Map.class</code></p>
<h5>XLS 文件</h5>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">File</span> <span class="n">f</span><span class="o">=</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">"src/test/resources/test.xls"</span><span class="o">);</span>
</span><span class='line'><span class="n">InputStream</span> <span class="n">inputStream</span><span class="o">=</span> <span class="k">new</span> <span class="n">FileInputStream</span><span class="o">(</span><span class="n">f</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="n">ExcelLogs</span> <span class="n">logs</span> <span class="o">=</span><span class="k">new</span> <span class="n">ExcelLogs</span><span class="o">();</span>
</span><span class='line'><span class="n">Collection</span><span class="o"><</span><span class="n">Map</span><span class="o">></span> <span class="n">importExcel</span> <span class="o">=</span> <span class="n">ExcelUtil</span><span class="o">.</span><span class="na">importExcel</span><span class="o">(</span><span class="n">Map</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">inputStream</span><span class="o">,</span> <span class="s">"yyyy/MM/dd HH:mm:ss"</span><span class="o">,</span> <span class="n">logs</span> <span class="o">,</span> <span class="mi">0</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="k">for</span><span class="o">(</span><span class="n">Map</span> <span class="n">m</span> <span class="o">:</span> <span class="n">importExcel</span><span class="o">){</span>
</span><span class='line'> <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">m</span><span class="o">);</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<h5>XLSX 文件</h5>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">File</span> <span class="n">f</span><span class="o">=</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">"src/test/resources/test.xlsx"</span><span class="o">);</span>
</span><span class='line'><span class="n">InputStream</span> <span class="n">inputStream</span><span class="o">=</span> <span class="k">new</span> <span class="n">FileInputStream</span><span class="o">(</span><span class="n">f</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="n">ExcelLogs</span> <span class="n">logs</span> <span class="o">=</span><span class="k">new</span> <span class="n">ExcelLogs</span><span class="o">();</span>
</span><span class='line'><span class="n">Collection</span><span class="o"><</span><span class="n">Map</span><span class="o">></span> <span class="n">importExcel</span> <span class="o">=</span> <span class="n">ExcelUtil</span><span class="o">.</span><span class="na">importExcel</span><span class="o">(</span><span class="n">Map</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">inputStream</span><span class="o">,</span> <span class="s">"yyyy/MM/dd HH:mm:ss"</span><span class="o">,</span> <span class="n">logs</span> <span class="o">,</span> <span class="mi">0</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="k">for</span><span class="o">(</span><span class="n">Map</span> <span class="n">m</span> <span class="o">:</span> <span class="n">importExcel</span><span class="o">){</span>
</span><span class='line'> <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">m</span><span class="o">);</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[树洞App 隐私政策]]></title>
<link href="https://sargeraswang.com/blog/2018/11/27/shu-dong-app-yin-si-sheng-ming/"/>
<updated>2018-11-27T13:01:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/27/shu-dong-app-yin-si-sheng-ming</id>
<content type="html"><![CDATA[<p>树洞app尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更有个性化的服务,树洞app会按照本隐私权政策的规定使用和披露您的个人信息。但树洞app将以高度的勤勉、审慎义务对待这些信息。</p>
<p>除本隐私权政策另有规定外,在未征得您事先许可的情况下,树洞app不会将这些信息对外披露或向第三方提供。树洞app会不时更新本隐私权政策。</p>
<p>您在同意树洞app服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于树洞app服务使用协议不可分割的一部分。</p>
<!--more-->
<ol>
<li>适用范围</li>
</ol>
<p>a) 在您使用树洞app网络服务,或访问树洞app平台网页时,树洞app自动接收并记录的您的浏览器和计算机上的信息,包括但不限于您的IP地址、浏览器的类型、使用的语言、访问日期和时间、软硬件特征信息及您需求的网页记录等数据;</p>
<p>b) 树洞app通过合法途径从商业伙伴处取得的用户个人数据。</p>
<ol>
<li>信息使用</li>
</ol>
<p>a) 树洞app不会向任何无关第三方提供、出售、出租、分享或交易您的个人信息,除非事先得到您的许可,或该第三方和树洞app(含树洞app关联公司)单独或共同为您提供服务,且在该服务结束后,其将被禁止访问包括其以前能够访问的所有这些资料。</p>
<p>b) 树洞app亦不允许任何第三方以任何手段收集、编辑、出售或者无偿传播您的个人信息。任何树洞app平台用户如从事上述活动,一经发现,我司有权立即终止与该用户的服务协议。</p>
<p>c) 为服务用户的目的,树洞app可能通过使用您的个人信息,向您提供您感兴趣的信息,包括但不限于向您发出产品和服务信息,或者与我司合作伙伴共享信息以便他们向您发送有关其产品和服务的信息(后者需要您的事先同意)。</p>
<ol>
<li>信息披露</li>
</ol>
<p>在如下情况下,树洞app将依据您的个人意愿或法律的规定全部或部分的披露您的个人信息:</p>
<p>a) 经您事先同意,向第三方披露;</p>
<p>b) 为提供您所要求的产品和服务,而必须和第三方分享您的个人信息;</p>
<p>c) 根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露;
d) 如您出现违反中国有关法律、法规或者树洞app服务协议或相关规则的情况,需要向第三方披露;</p>
<p>e) 如您是适格的知识产权投诉人并已提起投诉,应被投诉人要求,向被投诉人披露,以便双方处理可能的权利纠纷;
f) 在树洞app平台上创建的某一交易中,如交易任何一方履行或部分履行了交易义务并提出信息披露请求的,树洞app有权决定向该用户提供其交易对方的联络方式等必要信息,以促成交易的完成或纠纷的解决。</p>
<p>g) 其它树洞app根据法律、法规或者网站政策认为合适的披露。</p>
<ol>
<li>信息存储和交换</li>
</ol>
<p>树洞app收集的有关您的信息和资料将保存在树洞app及(或)其关联公司的服务器上,这些信息和资料可能传送至您所在国家、地区或树洞app收集信息和资料所在地的境外并在境外被访问、存储和展示。</p>
<ol>
<li>信息安全</li>
</ol>
<p>a) 树洞app帐号均有安全保护功能,请妥善保管您的用户名及密码信息。树洞app将通过对用户密码进行加密等安全措施确保您的信息不丢失,不被滥用和变造。尽管有前述安全措施,但同时也请您注意在信息网络上不存在“完善的安全措施”。</p>
<p>b) 在使用树洞app网络服务进行网上交易时,您不可避免的要向交易对方或潜在的交易对方披露自己的个人信息,如联络方式或者邮政地址。请您妥善保护自己的个人信息,仅在必要的情形下向他人提供。如您发现自己的个人信息泄密,尤其是树洞app用户名及密码发生泄露,请您立即联络树洞app客服,以便树洞app采取相应措施。</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[树洞APP]]></title>
<link href="https://sargeraswang.com/blog/2018/11/27/treehole-readme/"/>
<updated>2018-11-27T11:51:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/27/treehole-readme</id>
<content type="html"><![CDATA[<!--more-->
<p>树洞是一个可以让用户放心诉说私密心事的地方.</p>
<p>在这个互联网时代,大数据时代,各种工具给用户提供方便的同时令用户的隐私变得脆弱,方便与安全在一定程度上是鱼和熊掌不可兼得.树洞APP在设计时,如果遇到方便与安全冲突,会完全舍弃方便.</p>
<p>树洞APP没有任何第三方登录,不是以用户为单位,而是以”树洞”为一个单位.用户可以创建一个树洞,这个树洞的进入所需信息保存在用户的大脑中.目前,任何方便的措施例如:第三方登录,指纹解锁,滑动解锁,手机短信验证等等,虽然使用上方便了,但都有手机不在身边,被人施压等偷偷破解的可能.所以,只有大脑中记忆的东西,才是最安全的.</p>
<h4>首页</h4>
<p>树洞APP打开后的界面如下:</p>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/index.jpeg" alt="" /></p>
<blockquote><p>在这个界面稍作等待,会发现彩蛋哦~</p></blockquote>
<h4>创建一个树洞</h4>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/create.jpeg" alt="" /></p>
<p>创建成功后会直接进入树洞</p>
<h4>我的树洞</h4>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/myhole.jpeg" alt="" /></p>
<p>点击右上角齿轮按钮可进入设置界面</p>
<h4>设置</h4>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/setting.jpeg" alt="" /></p>
<p>可以修改[树洞名称]</p>
<p>关于[树洞暗号],创建时已提醒过用户,为了确保安全,只有在当初创建树洞的iphone上可以进行[修改暗号]这一操作</p>
<p>还可以设置[自动退出到首页]</p>
<p>同时,也有[意见反馈]功能</p>
<h4>自动退出到首页</h4>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/setting2.jpeg" alt="" /></p>
<p>考虑到用户手机有可能会无意被他人查看,APP可以设置当切换到后台时自动退出到首页,摇一摇同理.</p>
<h4>我想说</h4>
<p>点击我的树洞界面下方的[我想说]按钮</p>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/say.jpeg" alt="" /></p>
<p>用户最多可以输入250个字</p>
<p>点击[格式]按钮可对文字字体/大小/颜色进行设置</p>
<p>点击右上角[完成]按钮,可发表到我的树洞</p>
<h4>完成</h4>
<p><img src="https://sargeraswang.com/images/blog_img/treehole/myhole2.jpeg" alt="" /></p>
<h3>联系我们</h3>
<p>Email: <a href="mailto:sargeraswang@gmail.com">sargeraswang@gmail.com</a></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[jdk8到jdk11 springboot 踩坑指南]]></title>
<link href="https://sargeraswang.com/blog/2018/11/10/jdk8dao-jdk11-springboot-cai-keng-zhi-nan/"/>
<updated>2018-11-10T00:16:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/10/jdk8dao-jdk11-springboot-cai-keng-zhi-nan</id>
<content type="html"><![CDATA[<p>由于打算在项目中使用一些 java9 的特性,而 oracle 官方是从 java8 直接就到 java11 ,所以决定直接升级到java11.</p>
<!--more-->
<p>整个过程<strong>最关键的是注意当前环境变量</strong>,下面开始:</p>
<h3>下载jdk11</h3>
<ul>
<li>去<code>oracle</code>官网下载对应你系统的jdk,这个页面:</li>
</ul>
<p><a href="https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html">https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html</a></p>
<ul>
<li>安装之后,修改环境变量<code>JAVA_HOME</code></li>
<li>确保执行<code>java -version</code>看到的版本是11 —这里很重要</li>
</ul>
<h3>下载安装3.5.0以上的maven</h3>
<ul>
<li>去<code>maven</code>官网下载最新的3.6.0版本,这个页面:</li>
</ul>
<p><a href="https://maven.apache.org/download.cgi">https://maven.apache.org/download.cgi</a></p>
<ul>
<li>解压到合适的目录后,修改环境变量<code>MAVEN_HOME</code></li>
<li>确保执行<code>mvn -v</code>看到的是<code>maven 3.6.0</code>并且 <code>java 11</code> —这里很重要</li>
<li>如下截图:</li>
</ul>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/mvn-v.right.png" alt="" /></p>
<ul>
<li>只要maven或者java版本显示不正确,就考虑环境变量生效的问题,例如我的MAC,我改了<code>~/.bash_profile</code>但是很奇怪不生效,才想起来自己用的是<code>zsh</code>,又去改了<code>~/.zshrc</code>才生效,改完记得用<code>source</code>命令才可以立即生效</li>
<li>实在无解就重启下试试</li>
</ul>
<h3>修改pom.xml</h3>
<ul>
<li><code>spring boot parent</code>版本更新到 <code>2.1.0</code></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt"><parent></span>
</span><span class='line'> <span class="nt"><groupId></span>org.springframework.boot<span class="nt"></groupId></span>
</span><span class='line'> <span class="nt"><artifactId></span>spring-boot-starter-parent<span class="nt"></artifactId></span>
</span><span class='line'> <span class="nt"><version></span>2.1.0.RELEASE<span class="nt"></version></span>
</span><span class='line'> <span class="nt"><relativePath/></span> <span class="c"><!-- lookup parent from repository --></span>
</span><span class='line'><span class="nt"></parent></span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><code>java.version</code>修改为11</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt"><properties></span>
</span><span class='line'> ...
</span><span class='line'> <span class="nt"><java.version></span>11<span class="nt"></java.version></span>
</span><span class='line'><span class="nt"></properties></span>
</span></code></pre></td></tr></table></div></figure>
<p>只要改这两处就ok了,不用看别的教程里还需要增加或修改<code><plugins></code>内容,这坑我已经踩过了,不需要的.</p>
<h3>阶段性尝试</h3>
<ul>
<li>前面步骤做完,到目前,在终端下,应该已经可以正常打包了</li>
<li><code>cd</code>到项目目录下,执行<code>mvn clean package</code>试试看</li>
<li>没有报错就ok了,继续往下进行IDE的配置</li>
</ul>
<h3>IntelliJ IDEA 的配置</h3>
<p>这里才是巨坑的.</p>
<ul>
<li>在项目根目录上右键,选择<code>Open Module Settings</code></li>
<li>需要配置<code>jdk</code>的地方如下几张截图</li>
</ul>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-1.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-2.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-3.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-4.png" alt="" /></p>
<p>如果有漏配呢,就会有类似这样的输出:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>Error:java:无效的源发行版:11
</span></code></pre></td></tr></table></div></figure>
<p>如下图:</p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-5.png" alt="" /></p>
<ul>
<li>配置好之后点击<code>OK</code>关闭,然后按下<code>command+,</code>打开<code>Preferences</code>界面,左侧搜索输入<code>maven</code>,需要配置的地方如下几张截图</li>
</ul>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-6.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-7.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-setting-8.png" alt="" /></p>
<p>如果有漏配呢,就会有类似这样的输出:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project xxx: Fatal error compiling: 无效的目标发行版: 11 -> [Help 1]
</span></code></pre></td></tr></table></div></figure>
<p>或者是<code>Fatal error compiling: 无效的标记: --release</code></p>
<p>这个<code>Fatal error compiling: 无效的目标发行版: 11</code>坑的突破天际!</p>
<h3>别的问题:mybatis警告</h3>
<ul>
<li>如果你的项目使用了<code>mybatis</code>,那可能会在启动时看到如下日志</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>WARNING: An illegal reflective access operation has occurred
</span><span class='line'>WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector (file:/.../org/mybatis/mybatis/3.4.6/mybatis-3.4.6.jar) to method java.lang.Integer.getChars(int,int,byte[])
</span><span class='line'>WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
</span><span class='line'>WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
</span><span class='line'>WARNING: All illegal access operations will be denied in a future release
</span></code></pre></td></tr></table></div></figure>
<p>这个问题mybatis团队在修复了,<code>3.5.0</code>中应该能修复,但目前还没有release,所以暂时先忍着吧,详情见github答复:
<a href="https://github.com/mybatis/mybatis-3/issues/1156">MyBatis and JDK 9: Illegal reflective access</a></p>
<h3>别的问题:Unable to import maven project: See logs for details</h3>
<p>当你对pom.xml 做修改保存,IDEA右下角会有提示 <code>Unable to import maven project: See logs for details</code>,提示让我们去看日志.</p>
<p>点击[Help]–>[Show Log in Finder],可以看到错误信息如下:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>2018-11-10 14:55:54,580 [58702502] WARN - ution.rmi.RemoteProcessSupport - Unrecognized option: -d64
</span><span class='line'>2018-11-10 14:55:54,580 [58702502] WARN - ution.rmi.RemoteProcessSupport - Error: Could not create the Java Virtual Machine.
</span><span class='line'>2018-11-10 14:55:54,580 [58702502] WARN - ution.rmi.RemoteProcessSupport - Error: A fatal exception has occurred. Program will exit.
</span><span class='line'>2018-11-10 14:55:54,656 [58702578] WARN - ution.rmi.RemoteProcessSupport - Unrecognized option: -d64
</span><span class='line'>2018-11-10 14:55:54,656 [58702578] WARN - ution.rmi.RemoteProcessSupport - Error: Could not create the Java Virtual Machine.
</span><span class='line'>2018-11-10 14:55:54,656 [58702578] WARN - ution.rmi.RemoteProcessSupport - Error: A fatal exception has occurred. Program will exit.
</span><span class='line'>2018-11-10 14:55:54,657 [58702579] ERROR - #org.jetbrains.idea.maven - Cannot reconnect.
</span><span class='line'>java.lang.RuntimeException: Cannot reconnect.
</span><span class='line'> at ...
</span><span class='line'>Caused by: java.rmi.RemoteException: Cannot start maven service; nested exception is:
</span><span class='line'> com.intellij.execution.ExecutionException: Unrecognized option: -d64
</span><span class='line'>Error: Could not create the Java Virtual Machine.
</span><span class='line'>Error: A fatal exception has occurred. Program will exit.
</span><span class='line'>
</span><span class='line'> at ...
</span><span class='line'>Caused by: com.intellij.execution.ExecutionException: Unrecognized option: -d64
</span><span class='line'>Error: Could not create the Java Virtual Machine.
</span><span class='line'>Error: A fatal exception has occurred. Program will exit.
</span><span class='line'>
</span><span class='line'> at com.intellij.execution.rmi.RemoteProcessSupport.acquire(RemoteProcessSupport.java:159)
</span><span class='line'> at org.jetbrains.idea.maven.server.MavenServerManager.create(MavenServerManager.java:158)
</span><span class='line'> ... 37 more
</span></code></pre></td></tr></table></div></figure>
<p>关键是其中的 <code>com.intellij.execution.ExecutionException: Unrecognized option: -d64</code>,这是由于<code>-d64</code>在java10中已经被移除了.</p>
<h5>下面关于这个问题的解决步骤,不要照着做,直接看最后的正确解决办法就好.</h5>
<h5>下面关于这个问题的解决步骤,不要照着做,直接看最后的正确解决办法就好.</h5>
<h5>下面关于这个问题的解决步骤,不要照着做,直接看最后的正确解决办法就好.</h5>
<ul>
<li>我们先修改IDEA使用java11.</li>
</ul>
<p>修改方法:点击[Help]–>[Find Action…]–>输入[Switch],选中[Switch Boot JDK …],选择jdk11,点击[Save and restart],如下图所示:</p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-switch-boot.png" alt="" /></p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/idea-switch-boot2.png" alt="" /></p>
<p>重启完成,发现问题依旧,怀疑是这个<code>-d64</code>在项目中有配置,搜索后并没有发现.</p>
<ul>
<li><p>试一下删除IDEA的缓存文件夹,目录在<code>~/Library/Caches/产品名称(比方说我的是IntelliJIdea2018.2)</code>,病情没有好转 .</p></li>
<li><p>删除掉配置信息:<code>rm -rf ~/Library/Preferences/IntelliJIdea*</code></p></li>
</ul>
<p>然后,奇迹发生了,重置之后的IDEA已经无法导入我的项目了,生无可恋…</p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/want-die.jpg" alt="" /></p>
<p>再仔细看下日志,发现后面几行:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>2018-11-10 15:40:28,342 [ 38826] ERROR - llij.ide.plugins.PluginManager - IntelliJ IDEA 2018.2.5 Build #IU-182.4892.20
</span><span class='line'>2018-11-10 15:40:28,342 [ 38826] ERROR - llij.ide.plugins.PluginManager - JDK: 1.8.0_152-release
</span><span class='line'>2018-11-10 15:40:28,342 [ 38826] ERROR - llij.ide.plugins.PluginManager - VM: OpenJDK 64-Bit Server VM
</span><span class='line'>2018-11-10 15:40:28,343 [ 38827] ERROR - llij.ide.plugins.PluginManager - Vendor: JetBrains s.r.o
</span><span class='line'>2018-11-10 15:40:28,343 [ 38827] ERROR - llij.ide.plugins.PluginManager - OS: Mac OS X
</span><span class='line'>2018-11-10 15:40:28,343 [ 38827] ERROR - llij.ide.plugins.PluginManager - Last Action:
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>好,按照官方所说,修改一下IDEA的启动jdk,在 <code>~/Library/Preferences/IntelliJIdea2018.2</code>下创建一个<code>idea.jdk</code>文件,内容是<code>/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk</code></li>
</ul>
<p>再启动加载项目试试,日志中虽然jdk版本是11了,可是依旧报错.绝望中,google到这么一个网页,里面也是同样的问题,答复是:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='xml'><span class='line'>Hi.
</span><span class='line'>
</span><span class='line'>It should be fixed in 2018.3:
</span></code></pre></td></tr></table></div></figure>
<p>What ? 2018.3目前还是EAP版本,下载一个试试吧
<a href="https://www.jetbrains.com/idea/nextversion/">https://www.jetbrains.com/idea/nextversion/</a></p>
<p>下载完成打开拖拽到<code>应用程序</code>,运行<code>IntelliJ IDEA 2018.3 EAP.app</code>,导入我的项目,惊喜来了,成功了!!!<code>JetBrains</code>诚不欺我!</p>
<h3>总结就是:解决</h3>
<p><code>com.intellij.execution.ExecutionException: Unrecognized option: -d64</code></p>
<h3>办法就是使用<code>2018.3</code>及更新版本.</h3>
<h3>完成</h3>
<p>至此,坑已踩完,可以愉快的使用java11开发啦,比方说使用<code>Map.of</code>来快速的创建<code>Map</code>.</p>
<p><img src="https://sargeraswang.com/images/blog_img/java8-java11/java9-mapof.png" alt="" /></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[java 链式调用的正确姿势]]></title>
<link href="https://sargeraswang.com/blog/2018/11/09/java-lian-shi-diao-yong-de-zi-shi/"/>
<updated>2018-11-09T16:43:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/09/java-lian-shi-diao-yong-de-zi-shi</id>
<content type="html"><![CDATA[<p>Google 上搜索”java链式调用”前两名的大哥用的例子是一样的,并且不正确.</p>
<p>他们代码中<code>build</code>出来的并不是<code>Student</code>,而是一个<code>Builder</code>.</p>
<p>这里的链式调用(链式编程),是设计模式中的<code>Builder模式</code>,要点就是通过一个代理来完成对象的构建过程。这个代理职责就是完成构建的各个步骤,同时它也是易扩展的。</p>
<p>如下类似代码:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Response</span> <span class="o">{</span>
</span><span class='line'> <span class="kd">private</span> <span class="kd">final</span> <span class="n">Integer</span> <span class="n">status</span><span class="o">;</span>
</span><span class='line'> <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">message</span><span class="o">;</span>
</span><span class='line'> <span class="kd">private</span> <span class="kd">final</span> <span class="n">Object</span> <span class="n">result</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="nf">Response</span><span class="o">(</span><span class="n">Builder</span> <span class="n">builder</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">status</span><span class="o">=</span><span class="n">builder</span><span class="o">.</span><span class="na">status</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">message</span><span class="o">=</span><span class="n">builder</span><span class="o">.</span><span class="na">message</span><span class="o">;</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">result</span><span class="o">=</span><span class="n">builder</span><span class="o">.</span><span class="na">result</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">Builder</span><span class="o">{</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">Integer</span> <span class="n">status</span><span class="o">;</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">String</span> <span class="n">message</span><span class="o">;</span>
</span><span class='line'> <span class="kd">private</span> <span class="n">Object</span> <span class="n">result</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">public</span> <span class="n">Response</span> <span class="nf">build</span><span class="o">(){</span>
</span><span class='line'> <span class="k">return</span> <span class="k">new</span> <span class="nf">Response</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'> <span class="kd">public</span> <span class="n">Builder</span> <span class="nf">withStatus</span><span class="o">(</span><span class="n">Integer</span> <span class="n">status</span><span class="o">){</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">status</span><span class="o">=</span><span class="n">status</span><span class="o">;</span>
</span><span class='line'> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'> <span class="kd">public</span> <span class="n">Builder</span> <span class="nf">withMessage</span><span class="o">(</span><span class="n">String</span> <span class="n">message</span><span class="o">){</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">message</span> <span class="o">=</span> <span class="n">message</span><span class="o">;</span>
</span><span class='line'> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'> <span class="kd">public</span> <span class="n">Builder</span> <span class="nf">withResult</span><span class="o">(</span><span class="n">Object</span> <span class="n">result</span><span class="o">){</span>
</span><span class='line'> <span class="k">this</span><span class="o">.</span><span class="na">result</span> <span class="o">=</span> <span class="n">result</span><span class="o">;</span>
</span><span class='line'> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'> <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>调用时如下方式:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">Response</span> <span class="n">response</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Response</span><span class="o">.</span><span class="na">Builder</span><span class="o">()</span>
</span><span class='line'> <span class="o">.</span><span class="na">withStatus</span><span class="o">(</span><span class="mi">1</span><span class="o">)</span>
</span><span class='line'> <span class="o">.</span><span class="na">withMessage</span><span class="o">(</span><span class="s">"请求成功"</span><span class="o">)</span>
</span><span class='line'> <span class="o">.</span><span class="na">withResult</span><span class="o">(</span><span class="n">XXX</span><span class="o">)</span>
</span><span class='line'> <span class="o">.</span><span class="na">build</span><span class="o">();</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[generatePrivate Exception 解决]]></title>
<link href="https://sargeraswang.com/blog/2018/11/06/generateprivate-exception-jie-jue/"/>
<updated>2018-11-06T18:11:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/06/generateprivate-exception-jie-jue</id>
<content type="html"><![CDATA[<blockquote><p>java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format 异常解决</p></blockquote>
<p>私钥是直接生成的<code>pkcs8</code>格式,类似如下:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL21hi3tyVA2ILrk
</span><span class='line'>...
</span><span class='line'>+bojB4QWBQi9zg==</span></code></pre></td></tr></table></div></figure>
<p>直接在代码中使用<code>String</code>存储,利用类似如下代码进行签名:</p>
<!--more-->
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">PKCS8EncodedKeySpec</span> <span class="n">priPKCS8</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PKCS8EncodedKeySpec</span><span class="o">(</span><span class="n">prikeyvalue</span><span class="o">.</span><span class="na">getBytes</span><span class="o">());</span>
</span><span class='line'><span class="n">KeyFactory</span> <span class="n">keyf</span> <span class="o">=</span> <span class="n">KeyFactory</span><span class="o">.</span><span class="na">getInstance</span><span class="o">(</span><span class="s">"RSA"</span><span class="o">);</span>
</span><span class='line'><span class="n">PrivateKey</span> <span class="n">myprikey</span> <span class="o">=</span> <span class="n">keyf</span><span class="o">.</span><span class="na">generatePrivate</span><span class="o">(</span><span class="n">priPKCS8</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>其中第三行报错,如下:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">spec</span><span class="o">.</span><span class="na">InvalidKeySpecException</span><span class="o">:</span> <span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">InvalidKeyException</span><span class="o">:</span> <span class="n">invalid</span> <span class="n">key</span> <span class="n">format</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">rsa</span><span class="o">.</span><span class="na">RSAKeyFactory</span><span class="o">.</span><span class="na">engineGeneratePrivate</span><span class="o">(</span><span class="n">RSAKeyFactory</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">217</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">KeyFactory</span><span class="o">.</span><span class="na">generatePrivate</span><span class="o">(</span><span class="n">KeyFactory</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">372</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="o">...</span>
</span><span class='line'><span class="n">Caused</span> <span class="nl">by:</span> <span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">InvalidKeyException</span><span class="o">:</span> <span class="n">invalid</span> <span class="n">key</span> <span class="n">format</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">pkcs</span><span class="o">.</span><span class="na">PKCS8Key</span><span class="o">.</span><span class="na">decode</span><span class="o">(</span><span class="n">PKCS8Key</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">330</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">pkcs</span><span class="o">.</span><span class="na">PKCS8Key</span><span class="o">.</span><span class="na">decode</span><span class="o">(</span><span class="n">PKCS8Key</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">356</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">rsa</span><span class="o">.</span><span class="na">RSAPrivateCrtKeyImpl</span><span class="o">.<</span><span class="n">init</span><span class="o">>(</span><span class="n">RSAPrivateCrtKeyImpl</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">91</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">rsa</span><span class="o">.</span><span class="na">RSAPrivateCrtKeyImpl</span><span class="o">.</span><span class="na">newKey</span><span class="o">(</span><span class="n">RSAPrivateCrtKeyImpl</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">75</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">rsa</span><span class="o">.</span><span class="na">RSAKeyFactory</span><span class="o">.</span><span class="na">generatePrivate</span><span class="o">(</span><span class="n">RSAKeyFactory</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">316</span><span class="o">)</span>
</span><span class='line'> <span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">rsa</span><span class="o">.</span><span class="na">RSAKeyFactory</span><span class="o">.</span><span class="na">engineGeneratePrivate</span><span class="o">(</span><span class="n">RSAKeyFactory</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">213</span><span class="o">)</span>
</span><span class='line'> <span class="o">...</span> <span class="mi">77</span> <span class="n">more</span>
</span></code></pre></td></tr></table></div></figure>
<p>解决方式,秘钥<code>String</code>要先经过<code>Base64 Decode</code>,如下:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">PKCS8EncodedKeySpec</span> <span class="n">priPKCS8</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PKCS8EncodedKeySpec</span><span class="o">(</span><span class="n">prikeyvalue</span><span class="o">.</span><span class="na">getBytes</span><span class="o">());</span>
</span><span class='line'><span class="c1">//改成如下</span>
</span><span class='line'><span class="n">PKCS8EncodedKeySpec</span> <span class="n">priPKCS8</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PKCS8EncodedKeySpec</span><span class="o">(</span><span class="k">new</span> <span class="n">Base64</span><span class="o">().</span><span class="na">decode</span><span class="o">(</span><span class="n">prikeyvalue</span><span class="o">.</span><span class="na">getBytes</span><span class="o">()));</span>
</span></code></pre></td></tr></table></div></figure>
<p>这里的<code>Base64</code>类是指<code>org.apache.commons.codec.binary.Base64</code>.</p>
<p>问题解决</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[MacOS Mojave 重新安装mysql步骤及连接问题处理]]></title>
<link href="https://sargeraswang.com/blog/2018/11/03/macos-mojave-zhong-xin-an-zhuang-mysqlbu-zou-ji-lian-jie-wen-ti-chu-li/"/>
<updated>2018-11-03T15:35:00+08:00</updated>
<id>https://sargeraswang.com/blog/2018/11/03/macos-mojave-zhong-xin-an-zhuang-mysqlbu-zou-ji-lian-jie-wen-ti-chu-li</id>
<content type="html"><![CDATA[<h3>卸载并清理原有mysql</h3>
<p>1.数据备份,具体请查看<a href="https://www.jianshu.com/p/0a82d115d54d">mysqldump 的使用</a>,如果不需要备份,直接到下一步</p>
<!-- more -->
<p>2.查看当前系统是否有<code>mysql</code>进程:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>ps -ax|grep mysql
</span></code></pre></td></tr></table></div></figure>
<p>3.如果有,<code>kill</code>掉</p>
<p>4.使用<code>HomeBrew</code>删除</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>brew remove mysql
</span><span class='line'>brew cleanup
</span></code></pre></td></tr></table></div></figure>
<p>5.删除文件:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>sudo rm /usr/local/mysql
</span><span class='line'>sudo rm -rf /usr/local/var/mysql
</span><span class='line'>sudo rm -rf /usr/local/mysql*
</span><span class='line'>sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
</span><span class='line'>sudo rm -rf /Library/StartupItems/MySQLCOM
</span><span class='line'>sudo rm -rf /Library/PreferencePanes/My*
</span></code></pre></td></tr></table></div></figure>
<p>6.取消MySQL自动启动:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
</span></code></pre></td></tr></table></div></figure>
<p>7.删除MySQL的设置:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>subl /etc/hostconfig
</span><span class='line'><span class="c"># 删除这一行 MYSQLCOM=-YES-</span>
</span></code></pre></td></tr></table></div></figure>
<p>8.删除MySQL的首选项:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>rm -rf ~/Library/PreferencePanes/My*
</span><span class='line'>sudo rm -rf /Library/Receipts/mysql*
</span><span class='line'>sudo rm -rf /Library/Receipts/MySQL*
</span><span class='line'>sudo rm -rf /private/var/db/receipts/*mysql*
</span></code></pre></td></tr></table></div></figure>
<p>9.重新启动Mac</p>
<h3>下载并安装新mysql</h3>
<p>1.<a href="https://www.mysql.com/cn/">MySQL官网</a> –> 下载 –> 选择最下面的社区版本(MySQL Community Edition) –> 点第一个 MySQL Community Server (GPL) –> 选择DMG安装下载 (
macOS 10.14 (x86, 64-bit), DMG Archive)</p>
<blockquote><p>最终的下载地址是 <a href="https://dev.mysql.com/downloads/file/?id=480768">https://dev.mysql.com/downloads/file/?id=480768</a></p></blockquote>
<p>2.打开DMG,运行安装包,通常都是选择下一步,有一部会问你是使用8.0新版的更强健的安全的方式,还是兼容5.0,我们选择下面的兼容5.0</p>
<p>3.提示输入root密码两次,要记住这里的密码哦</p>
<p>4.安装完成</p>
<p>5.安装程序默认不会添加mysql命令到终端,所以需要自己配置:</p>
<ol>
<li>打开<code>/.bash_profile</code>文件</li>
<li>添加一行 <code>export PATH=$PATH:/usr/local/mysql/bin</code></li>
<li>保存</li>
<li>执行 <code>source ~/.bash_profile</code></li>
</ol>
<p>6.尝试连接mysql服务,运行 <code>mysql -uroot -p</code>回车</p>
<p>7.输入安装时设置的root密码</p>
<p>8.连接成功,并且控制台会打印出mysql版本 <code>Server version: 8.0.13 MySQL Community Server - GPL</code></p>
<h3>尝试使用数据库工具连接</h3>
<ol>
<li>使用 DbVisualizer 添加新的 connection</li>
<li>像往常一样 <code>Driver</code>选择了<code>MySQL</code></li>
<li>点击<code>Ping Server</code> 提示正常</li>
<li>点击<code>Connect</code>则无法连接显示如下:</li>
</ol>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>An error occurred <span class="k">while </span>establishing the connection:
</span><span class='line'>
</span><span class='line'>Long Message:
</span><span class='line'>Could not create connection to database server.