-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
1109 lines (941 loc) · 116 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>xudshen's blog</title>
<subtitle>Be good!</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://xudshen.info/"/>
<updated>2016-03-21T06:29:26.000Z</updated>
<id>http://xudshen.info/</id>
<author>
<name>Xudong Shen</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Introducing DroidData (Preliminary)</title>
<link href="http://xudshen.info/2016/03/07/introducing-droiddata/"/>
<id>http://xudshen.info/2016/03/07/introducing-droiddata/</id>
<published>2016-03-07T07:34:24.000Z</published>
<updated>2016-03-21T06:29:26.000Z</updated>
<content type="html"><p>There are already lots of discussions about the architecture of a quality android application, such as <a href="https://github.com/pedrovgs/EffectiveAndroidUI/" target="_blank" rel="external">EffectiveAndroidUI</a>, <a href="http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/" target="_blank" rel="external">Android-CleanArchitecture</a>, which use some common patterns like MVC, MVP or MVVM. However, what we are going to talk about in this post is not which one of these architectures is the best, but some kind solution while implementing these architectures.</p>
<a id="more"></a>
<h1 id="query-update-data-and-display-in-view"><a href="#query-update-data-and-display-in-view" class="headerlink" title="query/update data and display in view"></a>query/update data and display in view</h1><p>We all meet this kind of use case while using a MVP/MVVM pattern as the diagram shows:<br><img src="DroidData.1.jpg" alt="Old Way"></p>
<ol>
<li><code>View</code> requests/updates data to <code>Presenter/ViewModel</code></li>
<li><code>Presenter/ViewModel</code> requests/updates data to <code>ModelDao</code>(the <code>Business Logic</code>)</li>
<li><code>ModelDao</code> retrieves data(in the form of <code>Model</code>) from <code>Database</code>/<code>Web/Remote</code> and returns to <code>Presenter</code><br>or <code>ModelDao</code> updates data to <code>Database</code>/<code>Web/Remote</code> and returns result to <code>Presenter</code></li>
<li><code>Presenter</code> updates <code>View</code> with retrieved data or the result</li>
<li>if we use a RecyclerView, <code>Presenter</code> will need update <code>Adapter</code> to update RecyclerView</li>
</ol>
<p>As we can see, <code>Presenter</code> part acts as two roles: manipulates data with <code>ModelDao</code> and displays data to <code>View</code>.<br>Coding often becomes trivial when we implementing the displaying part and complicated when we updating different views with the same data source.<br>Taking an Excel app for example, displaying all the records requires code like <code>EditText.setText()</code> to bind data with a RecyclerView. Also modifying record requires code to find that specific record in RecyclerView or the corresponding record in detail view, and update them.<br>(Show a diagram here)</p>
<p>We can skip <code>EditText.setText()</code> part by taking the advantage of Google’s <a href="http://developer.android.com/tools/data-binding/guide.html" target="_blank" rel="external">Data Binding</a> library.<br>But what if we go further and more aggressive and directly bind Database with view through some way, then all the <code>Presenter</code> has to do is updating the Database. <code>Presenter</code> doesn’t need to care when the record is changed or which one of record is changed.<br>That is where the DroidData based on.</p>
<h1 id="DroidData"><a href="#DroidData" class="headerlink" title="DroidData"></a>DroidData</h1><p>DroidData uses <a href="http://developer.android.com/tools/data-binding/guide.html" target="_blank" rel="external">Data Binding</a>(bind data to view), <a href="http://developer.android.com/guide/topics/providers/content-providers.html" target="_blank" rel="external">ContentProvider</a>(a native android library providing mechanisms to query data and notify data changes), <a href="https://github.com/greenrobot/greenDAO" target="_blank" rel="external">GreenDao</a>(a light &amp; fast ORM solution for manipulating data in SQLite Databases) to accomplish above goal.<br><img src="DroidData.2.jpg" alt="Old Way"></p>
<ol>
<li><code>View</code> requests/updates data to <code>Presenter/ViewModel</code></li>
<li><code>Presenter/ViewModel</code> requests/updates data to <code>ModelDao</code>(the <code>Business Logic</code>)</li>
<li><code>ModelDao</code> determines if need retrieve data from <code>Web/Remote</code> and saves data to <code>Database</code>;<br><code>ModelDao</code> updates data to <code>Database</code> or updates data to <code>Web/Remote</code> then saves result to <code>Database</code></li>
<li><code>ModelDao</code> asynchronously notifies <code>ModelObservable</code>/<code>ContentProvider</code> that data source has changed</li>
<li><code>ModelObservable</code>/<code>ContentProvider</code> notifies <code>View</code>/<code>RecyclerView</code>, and <code>View</code>/<code>RecyclerView</code> gets refreshed with new data</li>
</ol>
<p>The step4 and step5 are auto triggered with the generated code by DroidData. This will make our code more </p>
<h1 id="efficiency-concern-and-violation-of-pattern"><a href="#efficiency-concern-and-violation-of-pattern" class="headerlink" title="efficiency concern and violation of pattern"></a>efficiency concern and violation of pattern</h1><p>All the notifications are triggered by the native ContentProvider.Also, DroidData provides a <code>DDCursorRecyclerAdapter</code> to bind database with view by <code>Cursor</code>, and ModelObservable map is stored with WeakReference.</p>
<p>It seems that DroidData violated the MV* pattern to some extent, because we connect <code>View</code> and <code>Model</code> directly. From another point of view, we actually connect <code>View</code> with ContentProvider which can also be considered as <code>Presenter</code>. Furthermore, DroidData makes test more straightforward. We can test the <code>Presenter</code> without the <code>View</code>.</p>
<h1 id="conclusion"><a href="#conclusion" class="headerlink" title="conclusion"></a>conclusion</h1><!---
retrieve data from db and internet
handle all the other queries
do special logic depending on the internet connectivity
when we use list, for the efficiency, we need load data with pagination,
this also requires we judge when we should load local/remote
with cursorAdapter, we could load all the data in db. after that, we can do the load more action on the end of the list
furthermore, when we need update/insert/delete item in that list, we should notify the cursor with data changes. this is also some repeat? code
how could we get notified when the data has changed? With Android ContentProvider, we could achieve this, even ContentProvider is meant to share
data between applications(We could disable it by add some restrictions).
what if we combine this two, we could change data, then notify ContentProvider -> Cursor -> View.
because we only read data from cursor, even though it is somehow disobey the rule of MVC,
this make the unit test much more easier
Android DataBinding -> part of MVC, more like MVP
"some of the architectural aspects employed in Android violate the very basic principles of MVC/MVP"
Activity (and Fragment) is bad candidate for MVC view – it is too tightly coupled with Android framework
it is simply impossible to work around it and implement a proper MVC/MVP
make the CursorAdapter part is the presenter part
non-trivial
1. update one place, notify all place
2. decrease duplicate code
3. easy to test
-->
</content>
<summary type="html">
<p>There are already lots of discussions about the architecture of a quality android application, such as <a href="https://github.com/pedrovgs/EffectiveAndroidUI/">EffectiveAndroidUI</a>, <a href="http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/">Android-CleanArchitecture</a>, which use some common patterns like MVC, MVP or MVVM. However, what we are going to talk about in this post is not which one of these architectures is the best, but some kind solution while implementing these architectures.</p>
</summary>
<category term="Android" scheme="http://xudshen.info/tags/Android/"/>
<category term="MVVM" scheme="http://xudshen.info/tags/MVVM/"/>
<category term="DataBinding" scheme="http://xudshen.info/tags/DataBinding/"/>
<category term="GreenDao" scheme="http://xudshen.info/tags/GreenDao/"/>
</entry>
<entry>
<title>List All Classes after Multidex</title>
<link href="http://xudshen.info/2014/11/12/list-all-classes-after-multidex/"/>
<id>http://xudshen.info/2014/11/12/list-all-classes-after-multidex/</id>
<published>2014-11-12T11:02:29.000Z</published>
<updated>2014-11-12T17:05:39.000Z</updated>
<content type="html"><h2 id="Intro"><a href="#Intro" class="headerlink" title="Intro"></a>Intro</h2><p>Google recently posted an <a href="http://developer.android.com/tools/building/multidex.html" target="_blank" rel="external">article</a> to solve the <code>65K Reference Limit</code> problem.<br>It is such a relief that we will not need to worry about the following errors any more.</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></pre></td><td class="code"><pre><span class="line">Conversion to Dalvik format failed:</span><br><span class="line">Unable to execute dex: method ID not in [<span class="number">0</span>, <span class="number">0xffff</span>]: <span class="number">65536</span></span><br><span class="line"><span class="comment">//--or--</span></span><br><span class="line">trouble writing output:</span><br><span class="line">Too many field references: <span class="number">131000</span>; max is <span class="number">65536</span>.</span><br><span class="line">You may <span class="keyword">try</span> using --multi-dex option.</span><br></pre></td></tr></table></figure>
<h2 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h2><p>After configuring multidex in the module, some projects may encounter the loss of part of the the classes when using reflection to list all the classes in the apk.<br>The usual code may like this:</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="comment">//get the apk path</span></span><br><span class="line">String path = context.getPackageManager().getApplicationInfo(context.getPackageName(), <span class="number">0</span>).sourceDir;</span><br><span class="line"><span class="comment">//use DexFile the unzip the apk, find the *classes.dex* in the apk</span></span><br><span class="line">DexFile dexfile = <span class="keyword">new</span> DexFile(path);</span><br><span class="line"><span class="comment">//get all the classes in this dex</span></span><br><span class="line">Enumeration&lt;String&gt; dexEntries = dexfile.entries();</span><br><span class="line"><span class="keyword">while</span> (dexEntries.hasMoreElements()) &#123;</span><br><span class="line"> classNames.add(dexEntries.nextElement());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h2 id="Clue-1"><a href="#Clue-1" class="headerlink" title="Clue 1"></a>Clue 1</h2><p>It’s easy to get the source code of <code>DexFile.java</code>,<br><figure class="highlight java"><figcaption><span>DexFile.java</span><a href="https://android.googlesource.com/platform/libcore-snapshot/+/ics-mr1/dalvik/src/main/java/dalvik/system/DexFile.java" target="_blank" rel="external">link</a></figcaption><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><br><span class="line"> * Opens a DEX file from a given filename. This will usually be a ZIP/JAR</span><br><span class="line"> * file with a "classes.dex" inside.</span><br><span class="line"> *</span><br><span class="line"> * ...</span><br><span class="line"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="title">DexFile</span><span class="params">(String fileName)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br></pre></td></tr></table></figure></p>
<p>We can find out that the <code>DexFile</code> constructor only loads the <code>classes.dex</code> in the apk, while the file structure in the apk should be like this:</p>
<figure class="highlight plain"><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">test.apk</span><br><span class="line">├── classes.dex</span><br><span class="line">└── classes2.dex</span><br></pre></td></tr></table></figure>
<p>It means that the classes in <code>classes2.dex</code> will not be opened by default constructor.</p>
<p>And the post by Google says that,</p>
<blockquote>
<p>… it is possible that other included libraries have additional dependency requirements including the use of introspection or invocation of Java methods from native code.<br>Some libraries may not be able to be used until the multidex build tools are updated to allow you to specify classes that must be included in the primary dex file.</p>
</blockquote>
<p>If we want to load all the classes in our project, we will need load the <code>classes2.dex</code>, <code>classes3.dex</code> manually.</p>
<h2 id="Clue-2"><a href="#Clue-2" class="headerlink" title="Clue 2"></a>Clue 2</h2><p>Also from the post, we can find out that all the multi dex tasks start at <code>MultiDex.install(context)</code>(in <a href="https://android.googlesource.com/platform/frameworks/multidex/+/ddd65a611834d9a9222603b2e85d558265f0aa85/library/src/android/support/multidex/MultiDex.java" target="_blank" rel="external">MultiDex.java</a>), which calls the <code>MultiDexExtractor.load(context, applicationInfo, dexDir, false)</code>(in <a href="https://android.googlesource.com/platform/frameworks/multidex/+/ddd65a611834d9a9222603b2e85d558265f0aa85/library/src/android/support/multidex/MultiDexExtractor.java" target="_blank" rel="external">MultiDexExtractor.java</a>) to extract the apk and install extra dex files.</p>
<p>And we can find a method called <code>MultiDexExtractor.loadExistingExtractions(...)</code> which can load existing secondary dex files that extracted by <code>MultiDexExtractor.load(...)</code>.</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></pre></td><td class="code"><pre><span class="line"><span class="comment">//applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0)</span></span><br><span class="line"><span class="comment">//sourceApk = new File(applicationInfo.sourceDir)</span></span><br><span class="line"><span class="comment">// ie: test.apk</span></span><br><span class="line"><span class="comment">//dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME); (in MultiDex.java)</span></span><br><span class="line"><span class="comment">// ie: /data/data/info.xudshen.test/code_cache/secondary-dexes</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> List&lt;File&gt; <span class="title">loadExistingExtractions</span><span class="params">(Context context, File sourceApk, File dexDir)</span></span><br><span class="line"> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line"> Log.i(TAG, <span class="string">"loading existing secondary dex files"</span>);</span><br><span class="line"> <span class="comment">//the prefix of extracted file, ie: test.classes</span></span><br><span class="line"> <span class="keyword">final</span> String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;</span><br><span class="line"> <span class="comment">//the total dex numbers</span></span><br><span class="line"> <span class="keyword">int</span> totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">final</span> List&lt;File&gt; files = <span class="keyword">new</span> ArrayList&lt;File&gt;(totalDexNumber);</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> secondaryNumber = <span class="number">2</span>; secondaryNumber &lt;= totalDexNumber; secondaryNumber++) &#123;</span><br><span class="line"> <span class="comment">//for each dex file, ie: test.classes2.zip, test.classes3.zip...</span></span><br><span class="line"> String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;</span><br><span class="line"> File extractedFile = <span class="keyword">new</span> File(dexDir, fileName);</span><br><span class="line"> <span class="keyword">if</span> (extractedFile.isFile()) &#123;</span><br><span class="line"> files.add(extractedFile);</span><br><span class="line"> <span class="comment">//verify the zip file</span></span><br><span class="line"> <span class="keyword">if</span> (!verifyZipFile(extractedFile)) &#123;</span><br><span class="line"> Log.i(TAG, <span class="string">"Invalid zip file: "</span> + extractedFile);</span><br><span class="line"> <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"Invalid ZIP file."</span>);</span><br><span class="line"> &#125;</span><br><span class="line"> &#125; <span class="keyword">else</span> &#123;</span><br><span class="line"> <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"Missing extracted secondary dex file '"</span> +</span><br><span class="line"> extractedFile.getPath() + <span class="string">"'"</span>);</span><br><span class="line"> &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">return</span> files;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>The code indicates that all the extra dex files are extracted in <code>/data/data/&lt;packageName&gt;/code_cache/secondary-dexes</code>. What we need to do is getting the paths and passing it to <code>DexFile</code> constructor.</p>
<p>Unfortunately, we can not call this method directly since <code>MultiDexExtractor.java</code> is a private class.<br>We will implement this part of code in our own project.</p>
<h2 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h2><p>Here is the complete code in Gist.<br>This solution is based on <a href="https://android.googlesource.com/platform/frameworks/multidex/+/ddd65a611834d9a9222603b2e85d558265f0aa85" target="_blank" rel="external">platform/frameworks/multidex ddd65a611834d9a9222603b2e85d558265f0aa85</a>.</p>
<p>We will need update the code once the extract path changes in <code>MultiDex.java</code>.</p>
<script src="//gist.github.com/0a5e1a2a2814510f7f5a.js"></script>
</content>
<summary type="html">
<h2 id="Intro"><a href="#Intro" class="headerlink" title="Intro"></a>Intro</h2><p>Google recently posted an <a href="http://developer.android.com/tools/building/multidex.html">article</a> to solve the <code>65K Reference Limit</code> problem.<br>It is such a relief that we will not need to worry about the following errors any more.</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></pre></td><td class="code"><pre><span class="line">Conversion to Dalvik format failed:</span><br><span class="line">Unable to execute dex: method ID not in [<span class="number">0</span>, <span class="number">0xffff</span>]: <span class="number">65536</span></span><br><span class="line"><span class="comment">//--or--</span></span><br><span class="line">trouble writing output:</span><br><span class="line">Too many field references: <span class="number">131000</span>; max is <span class="number">65536</span>.</span><br><span class="line">You may <span class="keyword">try</span> using --multi-dex option.</span><br></pre></td></tr></table></figure>
<h2 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h2><p>After configuring multidex in the module, some projects may encounter the loss of part of the the classes when using reflection to list all the classes in the apk.<br>The usual code may like this:</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="comment">//get the apk path</span></span><br><span class="line">String path = context.getPackageManager().getApplicationInfo(context.getPackageName(), <span class="number">0</span>).sourceDir;</span><br><span class="line"><span class="comment">//use DexFile the unzip the apk, find the *classes.dex* in the apk</span></span><br><span class="line">DexFile dexfile = <span class="keyword">new</span> DexFile(path);</span><br><span class="line"><span class="comment">//get all the classes in this dex</span></span><br><span class="line">Enumeration&lt;String&gt; dexEntries = dexfile.entries();</span><br><span class="line"><span class="keyword">while</span> (dexEntries.hasMoreElements()) &#123;</span><br><span class="line"> classNames.add(dexEntries.nextElement());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</summary>
<category term="Android" scheme="http://xudshen.info/tags/Android/"/>
<category term="Multidex" scheme="http://xudshen.info/tags/Multidex/"/>
<category term="65K" scheme="http://xudshen.info/tags/65K/"/>
</entry>
<entry>
<title>令人惊叹的电音</title>
<link href="http://xudshen.info/2014/10/21/good-music-awsome/"/>
<id>http://xudshen.info/2014/10/21/good-music-awsome/</id>
<published>2014-10-21T10:50:28.000Z</published>
<updated>2016-03-06T15:37:17.000Z</updated>
<content type="html"><blockquote><p>不是摇滚,而是电音。<br>不是躁杂,而是节奏。<br>生命和心脏一起律动,<br>思维完全沉浸入音乐中,<br>是未来,是科学,是电子,是光,是电,是宇宙的文明在歌唱。</p>
</blockquote>
<p>闹了好久的音乐荒,今天终于发现了新大陆。</p>
<a id="more"></a>
<p>这次的主打是英法的电音,排名没有先后。</p>
<style>
.album {
display: inline;
float: left;
position: relative;
}
.album img{
-webkit-transition: all 0.5s ease; /* Safari and Chrome */
-moz-transition: all 0.5s ease; /* Firefox */
-ms-transition: all 0.5s ease; /* IE 9 */
-o-transition: all 0.5s ease; /* Opera */
transition: all 0.5s ease;
float: left;
}
.album:hover{
z-index:555555 !important;
}
.album:hover img {
-webkit-transform:scale(1.1); /* Safari and Chrome */
-moz-transform:scale(1.1); /* Firefox */
-ms-transform:scale(1.1); /* IE 9 */
-o-transform:scale(1.1); /* Opera */
transform:scale(1.1);
}
</style>
<div>
<a class="album" href="http://music.163.com/#/artist?id=95279" target="_blank" rel="external">
<img src="Kraftwerk.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=90513" target="_blank" rel="external">
<img src="DaftPunk.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=38865" target="_blank" rel="external">
<img src="M83.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=98547" target="_blank" rel="external">
<img src="PetShopBoys.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=98112" target="_blank" rel="external">
<img src="Orbital.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=104492" target="_blank" rel="external">
<img src="Underworld.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=35427" target="_blank" rel="external">
<img src="Justice.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=85501" target="_blank" rel="external">
<img src="Air.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=41144" target="_blank" rel="external">
<img src="Phoenix.jpeg">
</a>
<a class="album" href="http://music.163.com/#/artist?id=98538" target="_blank" rel="external">
<img src="PortisHead.jpeg">
</a>
</div>
<div style="clear:both"></div>
</content>
<summary type="html">
<blockquote><p>不是摇滚,而是电音。<br>不是躁杂,而是节奏。<br>生命和心脏一起律动,<br>思维完全沉浸入音乐中,<br>是未来,是科学,是电子,是光,是电,是宇宙的文明在歌唱。</p>
</blockquote>
<p>闹了好久的音乐荒,今天终于发现了新大陆。</p>
</summary>
<category term="日常" scheme="http://xudshen.info/tags/%E6%97%A5%E5%B8%B8/"/>
<category term="音乐" scheme="http://xudshen.info/tags/%E9%9F%B3%E4%B9%90/"/>
</entry>
<entry>
<title>Yosemite:安装和修复开发环境</title>
<link href="http://xudshen.info/2014/10/18/fix-package-with-Yosemite-update/"/>
<id>http://xudshen.info/2014/10/18/fix-package-with-Yosemite-update/</id>
<published>2014-10-18T03:10:52.000Z</published>
<updated>2014-10-18T04:53:00.000Z</updated>
<content type="html"><p>OS X Yosemite昨天如期而至,更新自不待说。有了上次升级OS X Yosemite Beta失败的经验,这次在按下那个大大的<code>继续</code>之前,先用Time Machine做了一个备份。</p>
<p>等待的过程尤其漫长,论坛上看到很多人都卡在<a href="http://www.v2ex.com/t/139538" target="_blank" rel="external">大约剩余2分钟</a>。我倒是没有出现这种情况,我只是卡在<a href="http://www.v2ex.com/t/139538" target="_blank" rel="external">大约剩余1分钟</a>而已(._.)。在安装界面使用<code>CMD</code>+<code>L</code>可以看到系统在不断拷贝<code>texlive</code>的文件,也算是蛮拼的了。</p>
<p>大约一个半小时后,锵锵,全新的OS X长这样。 </p>
<p><img src="/2014/10/18/fix-package-with-Yosemite-update/osx.jpg" alt="OS X Yosemite"></p>
<p>然后就是修复我的开发环境,毕竟还要靠它赚钱吃饭呐。</p>
<a id="more"></a>
<ul>
<li>Xcode CLT</li>
</ul>
<p>CLT每次升级系统都会出现问题,所以首先要<code>xcode-select --install</code>来同意Xcode的一个啥啥啥协议。另外因为我装的是Xcode-Beta,所以还要下面的命令来指定我的Xcode路径。</p>
<p><code>sudo xcode-select -switch /Applications/Xcode-Beta.app/Contents/Developer/</code></p>
<ul>
<li>Java</li>
</ul>
<p>Java也是每次升级系统都会出现问题,就像这样</p>
<p><img src="java.png" alt="Java"></p>
<p>点击<code>更多信息</code>会跳转到Apple的网站,把那里面的Java安装包装一下就好。</p>
<ul>
<li>Homebrew</li>
</ul>
<p>Homebrew的话使用<code>brew doctor</code>测一下就好,我倒是没出现什么问题。<a href="http://weibo.com/p/1001603766056865935197" target="_blank" rel="external">这里</a>倒是有个修复Homebrew的文章。</p>
<p>然后就是<code>brew update</code>、<code>brew upgrade</code>、<code>brew cleanup</code>,升级一下各种包。</p>
<p>至此就是Yosemite的初体验,更多新的特性(Handoff, Continuity…)还在试用中,以后再写好了。</p>
</content>
<summary type="html">
<p>OS X Yosemite昨天如期而至,更新自不待说。有了上次升级OS X Yosemite Beta失败的经验,这次在按下那个大大的<code>继续</code>之前,先用Time Machine做了一个备份。</p>
<p>等待的过程尤其漫长,论坛上看到很多人都卡在<a href="http://www.v2ex.com/t/139538">大约剩余2分钟</a>。我倒是没有出现这种情况,我只是卡在<a href="http://www.v2ex.com/t/139538">大约剩余1分钟</a>而已(._.)。在安装界面使用<code>CMD</code>+<code>L</code>可以看到系统在不断拷贝<code>texlive</code>的文件,也算是蛮拼的了。</p>
<p>大约一个半小时后,锵锵,全新的OS X长这样。 </p>
<p><img src="/2014/10/18/fix-package-with-Yosemite-update/osx.jpg" alt="OS X Yosemite"></p>
<p>然后就是修复我的开发环境,毕竟还要靠它赚钱吃饭呐。</p>
</summary>
<category term="Yosemite" scheme="http://xudshen.info/tags/Yosemite/"/>
<category term="Homebrew" scheme="http://xudshen.info/tags/Homebrew/"/>
<category term="Java" scheme="http://xudshen.info/tags/Java/"/>
<category term="Xcode" scheme="http://xudshen.info/tags/Xcode/"/>
</entry>
<entry>
<title>Bandwagon 被黑小记</title>
<link href="http://xudshen.info/2014/10/15/securing-vps-with-iptables/"/>
<id>http://xudshen.info/2014/10/15/securing-vps-with-iptables/</id>
<published>2014-10-15T14:33:02.000Z</published>
<updated>2014-10-16T07:10:21.000Z</updated>
<content type="html"><p>最近使用Azure和Bandwagon搭建了一个APNP梯子,顺畅无比。可惜好景不长,昨天下午突然就不能用了,心想不会那么快没流量吧。结果登上KiviVM一看,我的VPS居然被Suspend了,原因是Spam Email,顿时感到不妙,花了个擦,我的小梯子居然成了肉鸡?</p>
<a id="more"></a>
<p>使用<code>netstat -nap</code>一看,满满一屏的<code>postfix</code>在向25端口发包,也是醉了。当时也是慌了手脚,第一反应居然是改<code>iptables</code>,又是查手册,又是改代码。本来Bandwagon的线路延迟就大,在改配置的过程中又被系统Suspend了一次。心塞。</p>
<p>没办法,要是再被Suspend两次,今年就不要指望再用这个VPS了。也幸好服务器上的东西不多,就只有一个Shadowsocks,于是决定Install A New OS。用KiviVM重装了一个Ubuntu,心想这样总该没问题了吧。万万没想到不到五分钟,系统通知说我又被Suspend了。难道有人一直攻击我这个IP?这样再重装都没有用啊。于是开始切Data Center,重新分配IP,重装OS。这次学乖了,登上去之后就检查<code>netstat -nap</code>。令人惊讶的是,居然还有一堆的<code>postfix</code>,这可是新的OS啊。</p>
<blockquote>
<p>这里严重怀疑Bandwagon在背后搞鬼,或者Bandwagon后台被黑,全新的OS居然会自开端口发垃圾邮件。<br>有在V2EX上问过这样的事情,有人提出了相同的<a href="http://www.v2ex.com/t/138920#reply9" target="_blank" rel="external">怀疑</a>。</p>
</blockquote>
<p>顿时火大,立马把<code>postfix</code>给卸掉了,反正平常也不怎么用。</p>
<p>再次把<code>/etc/ssh/sshd_config</code>里面<code>PasswordAuthentication</code> <code>PermitRootLogin</code>置为<code>no</code>,安装<code>fail2ban</code>,三次失败就被ban一年,哼( ̄ェ ̄);设置<code>iptables</code>,只允许<code>80</code> <code>443</code> <code>53</code>端口的通信,这下总不能乱发邮件了吧。</p>
<p>总结一下,为了VPS的安全,<code>iptables</code>还是要仔细设置的,另外需要及时更改<code>ssh</code>的端口,同时仅允许证书登录。</p>
<blockquote>
<p>最最重要的是,谨防服务商。</p>
</blockquote>
<p>结尾附上我的<code>iptables</code>设置。</p>
<script src="//gist.github.com/debe533c89c21d2a1d87.js?file=iptables.conf"></script>
</content>
<summary type="html">
<p>最近使用Azure和Bandwagon搭建了一个APNP梯子,顺畅无比。可惜好景不长,昨天下午突然就不能用了,心想不会那么快没流量吧。结果登上KiviVM一看,我的VPS居然被Suspend了,原因是Spam Email,顿时感到不妙,花了个擦,我的小梯子居然成了肉鸡?</p>
</summary>
<category term="VPS" scheme="http://xudshen.info/tags/VPS/"/>
<category term="安全" scheme="http://xudshen.info/tags/%E5%AE%89%E5%85%A8/"/>
</entry>
<entry>
<title>视差滚动:初探</title>
<link href="http://xudshen.info/2014/08/13/parallax-scrolling-start/"/>
<id>http://xudshen.info/2014/08/13/parallax-scrolling-start/</id>
<published>2014-08-13T10:21:00.000Z</published>
<updated>2014-10-20T08:45:05.000Z</updated>
<content type="html"><p><a href="http://en.wikipedia.org/wiki/Parallax_scrolling#Parallax_scrolling_in_Web_design" target="_blank" rel="external">视差滚动</a>已经火了很久了,但一直没有空去尝试。</p>
<p>下面是利用<code>$(window).scroll</code>来控制<code>div</code>位置的尝试,重点在于各种高度的计算。</p>
<iframe scrolling="no" width="100%" height="300" src="http://jsfiddle.net/n3e50sze/embedded/result,js,html,css/light" frameborder="0" allowfullscreen></iframe>
</content>
<summary type="html">
<p><a href="http://en.wikipedia.org/wiki/Parallax_scrolling#Parallax_scrolling_in_Web_design" target="_blank" rel="external">视差滚动</a>已经火了很久了
</summary>
<category term="视差滚动" scheme="http://xudshen.info/tags/%E8%A7%86%E5%B7%AE%E6%BB%9A%E5%8A%A8/"/>
<category term="HTML" scheme="http://xudshen.info/tags/HTML/"/>
<category term="JS" scheme="http://xudshen.info/tags/JS/"/>
</entry>
<entry>
<title>RxMqtt:Reactive Extensions for the Mqtt</title>
<link href="http://xudshen.info/2014/07/21/rxmqtt-rxjava-with-mqtt/"/>
<id>http://xudshen.info/2014/07/21/rxmqtt-rxjava-with-mqtt/</id>
<published>2014-07-21T06:30:48.000Z</published>
<updated>2014-10-20T06:36:34.000Z</updated>
<content type="html"></content>
<summary type="html">
</summary>
<category term="RxMqtt" scheme="http://xudshen.info/tags/RxMqtt/"/>
<category term="RxJava" scheme="http://xudshen.info/tags/RxJava/"/>
<category term="MQTT" scheme="http://xudshen.info/tags/MQTT/"/>
</entry>
<entry>
<title>Gson在Spring MVC中的使用</title>
<link href="http://xudshen.info/2014/07/14/gson-with-spring-mvc/"/>
<id>http://xudshen.info/2014/07/14/gson-with-spring-mvc/</id>
<published>2014-07-14T11:14:13.000Z</published>
<updated>2014-10-20T09:18:48.000Z</updated>
<content type="html"><p>最近在用Spring MVC搭建一套Restful API,整个过程的最后一步就是数据序列化。Spring MVC默认使用<a href="http://jackson.codehaus.org" target="_blank" rel="external">Jackson</a>,但在使用过程中并不如想象中的顺手。因而尝试转向<a href="https://code.google.com/p/google-gson/" target="_blank" rel="external">Gson</a>。</p>
<p>Gson是Google出品的用来进行Java Object和JSON转换的类库。有人曾对Gson和Jackson的性能做过<a href="http://tuhrig.de/jaxb-vs-gson-and-jackson/" target="_blank" rel="external">比较</a>,Gson在读取和写入方面的速度都要逊于Jackson。不过现前并不需要在性能上作过多要求,容易上手和提高开发效率才是这个项目的重中之重。</p>
<h1 id="基本"><a href="#基本" class="headerlink" title="基本"></a>基本</h1><p>使用Gson来反序列化JSON十分简单,如下:</p>
<figure class="highlight java"><figcaption><span>User</span></figcaption><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="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span></span>&#123;</span><br><span class="line"> <span class="keyword">private</span> String name;</span><br><span class="line"> <span class="keyword">private</span> String password;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">User</span><span class="params">(String name, String password)</span></span>&#123;...&#125;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><figcaption><span>Gson反序列化User</span></figcaption><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">Gson gson = <span class="keyword">new</span> Gson();</span><br><span class="line">gson.toJson(<span class="keyword">new</span> User(<span class="string">"hello"</span>, <span class="string">"world"</span>), User.class);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Result:</span></span><br><span class="line"><span class="comment">// &#123;"name": "hello", "password": "world"&#125;</span></span><br></pre></td></tr></table></figure>
<p>但Gson的优点不仅仅在于这点,而是在自定义序列化方面。<br><a id="more"></a></p>
<h1 id="进阶"><a href="#进阶" class="headerlink" title="进阶"></a>进阶</h1><h2 id="使用-Expose注解忽略不想序列化的(敏感)字段"><a href="#使用-Expose注解忽略不想序列化的(敏感)字段" class="headerlink" title="使用@Expose注解忽略不想序列化的(敏感)字段"></a>使用@Expose注解忽略不想序列化的(敏感)字段</h2><p>很明显,在返回给用户的时候是不应该包含<code>password</code>这种字段的,在反序列化的过程中应该把它忽略掉。这里就可以使用Gson自带的注解<code>@Expose</code>来指定哪些字段需要被反序列化。<strong>注意:字段加了<code>@Expose</code>表明该字段会被反序列化,而不是被忽略。</strong></p>
<figure class="highlight java"><figcaption><span>User带@Expose注解</span></figcaption><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">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span></span>&#123;</span><br><span class="line"> <span class="meta">@Expose</span></span><br><span class="line"> <span class="keyword">private</span> String name;</span><br><span class="line"> <span class="keyword">private</span> String password;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">User</span><span class="params">(String name, String password)</span></span>&#123;...&#125;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><figcaption><span>Gson反序列化User</span></figcaption><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">Gson gson = <span class="keyword">new</span> GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();</span><br><span class="line">gson.toJson(<span class="keyword">new</span> User(<span class="string">"hello"</span>, <span class="string">"world"</span>), User.class);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Result:</span></span><br><span class="line"><span class="comment">// &#123;"name": "hello"&#125;</span></span><br></pre></td></tr></table></figure>
<h2 id="利用字段null来简化API的输出"><a href="#利用字段null来简化API的输出" class="headerlink" title="利用字段null来简化API的输出"></a>利用字段null来简化API的输出</h2><figure class="highlight java"><figcaption><span>CommonResponse</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CommonResponse</span>&lt;<span class="title">T</span>&gt;</span>&#123;</span><br><span class="line"> <span class="meta">@Expose</span></span><br><span class="line"> <span class="keyword">private</span> Int status; <span class="comment">//API状态码,与HttpStatus状态码类似,200为Success,10000以上则对应服务的各种错误</span></span><br><span class="line"> <span class="meta">@Expose</span> </span><br><span class="line"> <span class="keyword">private</span> T response; <span class="comment">// status == 200 时的具体返回值,status != 200 时不显示</span></span><br><span class="line"> <span class="meta">@Expose</span></span><br><span class="line"> <span class="keyword">private</span> String message; <span class="comment">//status != 200 时的详细消息输出,status == 200 时不显示</span></span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">CommonResponse</span><span class="params">(T response)</span></span>&#123;...&#125;</span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">CommonResponse</span><span class="params">(T response, String message)</span></span>&#123;...&#125;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>Json默认对于null的字段不输出,利用这种方式可以简化API的输出,压缩空间;同时利用上面<code>CommonResponse</code>的设计,<br>在输出正确时</p>
<figure class="highlight json"><figcaption><span>CommonResponse.status = 200</span></figcaption><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">&#123;</span><br><span class="line"> <span class="attr">"status"</span>: <span class="number">200</span>,</span><br><span class="line"> <span class="attr">"response"</span>: &#123;</span><br><span class="line"> <span class="attr">"name"</span>: <span class="string">"hello"</span></span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>输出错误时<br><figure class="highlight json"><figcaption><span>CommonResponse.status = 10001</span></figcaption><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">&#123;</span><br><span class="line"> <span class="attr">"status"</span>: <span class="number">10001</span>,</span><br><span class="line"> <span class="attr">"message"</span>: <span class="string">"no use found"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="与Spring-MVC整合"><a href="#与Spring-MVC整合" class="headerlink" title="与Spring MVC整合"></a>与Spring MVC整合</h2><figure class="highlight xml"><figcaption><span>web.xml</span></figcaption><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="tag">&lt;<span class="name">mvc:annotation-driven</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">mvc:message-converters</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--use utf-8--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">"org.springframework.http.converter.StringHttpMessageConverter"</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">value</span>=<span class="string">"UTF-8"</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"writeAcceptCharset"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">"info.xudshen.basic.util.gson.GsonHttpMessageConverter"</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--ignore the class in this list-&gt;</span><br><span class="line"> &lt;list&gt;</span><br><span class="line"> &lt;value&gt;com.wordnik.swagger.model.ResourceListing&lt;/value&gt;</span><br><span class="line"> &lt;value&gt;com.wordnik.swagger.model.ApiListing&lt;/value&gt;</span><br><span class="line"> &lt;/list&gt;</span><br><span class="line"> &lt;/constructor-arg&gt;</span><br><span class="line"> &lt;/bean&gt;</span><br><span class="line"> &lt;/mvc:message-converters&gt;</span><br><span class="line">&lt;/mvc:annotation-driven&gt;</span></span><br></pre></td></tr></table></figure>
<p>GsonHttpMessageConverter的代码在<a href="https://gist.github.com/xudshen/c7ee24ee6e4495b86834" target="_blank" rel="external">Gist</a>上</p>
<h2 id="更多Gson配置"><a href="#更多Gson配置" class="headerlink" title="更多Gson配置"></a>更多Gson配置</h2><figure class="highlight java"><figcaption><span>更多Gson配置</span></figcaption><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> Gson gson = <span class="keyword">new</span> GsonBuilder().enableComplexMapKeySerialization()</span><br><span class="line"> .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)</span><br><span class="line"> .excludeFieldsWithoutExposeAnnotation()</span><br><span class="line"> .setDateFormat(<span class="string">"yyyy-MM-dd HH:mm:ss.S Z"</span>)</span><br><span class="line"> .create();</span><br></pre></td></tr></table></figure></content>
<summary type="html">
<p>最近在用Spring MVC搭建一套Restful API,整个过程的最后一步就是数据序列化。Spring MVC默认使用<a href="http://jackson.codehaus.org">Jackson</a>,但在使用过程中并不如想象中的顺手。因而尝试转向<a href="https://code.google.com/p/google-gson/">Gson</a>。</p>
<p>Gson是Google出品的用来进行Java Object和JSON转换的类库。有人曾对Gson和Jackson的性能做过<a href="http://tuhrig.de/jaxb-vs-gson-and-jackson/">比较</a>,Gson在读取和写入方面的速度都要逊于Jackson。不过现前并不需要在性能上作过多要求,容易上手和提高开发效率才是这个项目的重中之重。</p>
<h1 id="基本"><a href="#基本" class="headerlink" title="基本"></a>基本</h1><p>使用Gson来反序列化JSON十分简单,如下:</p>
<figure class="highlight java"><figcaption><span>User</span></figcaption><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="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span></span>&#123;</span><br><span class="line"> <span class="keyword">private</span> String name;</span><br><span class="line"> <span class="keyword">private</span> String password;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">User</span><span class="params">(String name, String password)</span></span>&#123;...&#125;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><figcaption><span>Gson反序列化User</span></figcaption><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">Gson gson = <span class="keyword">new</span> Gson();</span><br><span class="line">gson.toJson(<span class="keyword">new</span> User(<span class="string">"hello"</span>, <span class="string">"world"</span>), User.class);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Result:</span></span><br><span class="line"><span class="comment">// &#123;"name": "hello", "password": "world"&#125;</span></span><br></pre></td></tr></table></figure>
<p>但Gson的优点不仅仅在于这点,而是在自定义序列化方面。<br>
</summary>
<category term="Gson" scheme="http://xudshen.info/tags/Gson/"/>
<category term="Spring MVC" scheme="http://xudshen.info/tags/Spring-MVC/"/>
</entry>
<entry>
<title>[知乎]答:为什么现在的 GUI 设计仍跳不出 button、list、icon,没有这些元素的 GUI 会是什么样子?</title>
<link href="http://xudshen.info/2013/06/08/why-are-button-list-the-basic-ui-control/"/>
<id>http://xudshen.info/2013/06/08/why-are-button-list-the-basic-ui-control/</id>
<published>2013-06-07T16:48:00.000Z</published>
<updated>2014-10-16T07:12:16.000Z</updated>
<content type="html"><p>此为知乎上的一个提问,<a href="http://www.zhihu.com/question/20269253" target="_blank" rel="external">原文在这里</a>。</p>
<p>button,list等作为一些基础控件,从较高的层面讲,他们阐释了<strong>基本的交互语言,从而实现界面交互</strong>;就像在研究素描时,大多也就可以由三角形、圆形、矩形等构成(图一)。</p>
<p><img src="/2013/06/08/why-are-button-list-the-basic-ui-control/sketch.jpg" alt="图一:素描"></p>
<a id="more"></a>
<p>举个例子吧,图二是一个颜色拾取板,简单分析一下,就会发现其实这一圈就是个list,只不过和一般直直的list不同,每个item进行了固定角度的旋转。</p>
<p><img src="circlelist.jpg" alt="图二"></p>
<p>再如1l所说的日期选择控件(图三),仍然逃不过所谓的button,list的命运。</p>
<p>我们可以叫他新控件,也可以叫做旧控件的新组合(并算不上新的交互)。</p>
<p><img src="datepicker.jpg" alt="图三"></p>
<p>因此,在控件设计时往往有一项准则:</p>
<blockquote><p>如果可以用以往的基本控件来组合,那么就不要重新创造一个新控件。</p>
</blockquote>
<p>个人看来,我们现在所说的新控件,往往是添加或重组了<strong>交互方式/顺序</strong>,并未能跳出基本控件的框框。(欢迎lx举出例子来反驳)</p>
<p>至于button,list这些基本控件是如何设计出来的,只能佩服前人的创造,简洁而又强大。</p>
<p>这样应该能够回答lz的“为什么现在的 GUI 设计仍跳不出 button,list的框架”这个问题。</p>
<hr>
<p>Add:<br>看了一些回答,有的从与日常生活的映射角度来分析。</p>
<p>突发奇想,要是从集合论的角度,</p>
<p>所有物体的集合对应list,</p>
<p>而对物体的操作对应button,</p>
<p>如此似乎能解释这些基础控件的起源=。=</p>
<p>想法不靠谱,额嗬嗬嗬嗬嗬嗬嗬嗬,,,</p>
</content>
<summary type="html">
<p>此为知乎上的一个提问,<a href="http://www.zhihu.com/question/20269253">原文在这里</a>。</p>
<p>button,list等作为一些基础控件,从较高的层面讲,他们阐释了<strong>基本的交互语言,从而实现界面交互</strong>;就像在研究素描时,大多也就可以由三角形、圆形、矩形等构成(图一)。</p>
<p><img src="/2013/06/08/why-are-button-list-the-basic-ui-control/sketch.jpg" alt="图一:素描"></p>
</summary>
<category term="设计" scheme="http://xudshen.info/tags/%E8%AE%BE%E8%AE%A1/"/>
<category term="日常" scheme="http://xudshen.info/tags/%E6%97%A5%E5%B8%B8/"/>
</entry>
<entry>
<title>软工_API定义</title>
<link href="http://xudshen.info/2013/04/19/se-api-define/"/>
<id>http://xudshen.info/2013/04/19/se-api-define/</id>
<published>2013-04-19T02:12:00.000Z</published>
<updated>2016-03-07T08:01:29.000Z</updated>
<content type="html"><p>软件工程课程项目API</p>
<p>为了进行更好的分工合作,将API罗列如下…</p>
<a id="more"></a>
<h1 id="教程"><a href="#教程" class="headerlink" title="教程"></a>教程</h1><p>由于项目将使用tomcat+struts2+mysql搭建,请认真阅读sample中的表格提交功能以及数据加载功能。</p>
<p><a href="http://6carol6.github.io/blog/2013/04/20/school-management-system-outline/" target="_blank" rel="external">Sample的一个简单的运行描述</a> 感谢小组长<a href="http://6carol6.github.io/" target="_blank" rel="external">@6carol6</a>童鞋。</p>
<h1 id="登陆-pages-Login-jsp"><a href="#登陆-pages-Login-jsp" class="headerlink" title="登陆(/pages/Login.jsp)"></a>登陆(/pages/Login.jsp)</h1><p><code>action name:</code> Login</p>
<p><code>servlet name:</code> SampleProject.Login</p>
<p><code>page value:</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">name</th>
<th style="text-align:left">type</th>
<th style="text-align:left">field</th>
<th style="text-align:left">more </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">username</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">用户名</td>
</tr>
<tr>
<td style="text-align:left">password</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">密码</td>
</tr>
<tr>
<td style="text-align:left">identity</td>
<td style="text-align:left">String</td>
<td style="text-align:left">{0,1,2}</td>
<td style="text-align:left">用户身份:学生、教师、管理员</td>
</tr>
</tbody>
</table>
<p><em>请注意这里page value的使用:是指页面将需要对应的action类中实现相应的getter和setter函数</em></p>
<p><em>例如:</em><br><figure class="highlight java"><figcaption><span>表单提交</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//表单提交将默认执行action中的execute函数</span></span><br><span class="line"><span class="comment">//在执行该函数之前,所有表单中的项 将 调用 对应的setter函数进行赋值</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//Login.jsp</span></span><br><span class="line">&lt;s:textfield key=<span class="string">"username"</span>/&gt;</span><br><span class="line"><span class="comment">//Login.java</span></span><br><span class="line"><span class="keyword">private</span> String username;</span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">getUsername</span><span class="params">()</span> </span><br><span class="line"></span>&#123;</span><br><span class="line"> <span class="keyword">return</span> username;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setUsername</span><span class="params">(String username)</span> <span class="comment">//username = "admin"</span></span><br><span class="line"></span>&#123;</span><br><span class="line"> <span class="keyword">this</span>.username = username; <span class="comment">//this.username = "admin"</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//此时调用</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">execute</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span><br><span class="line"></span>&#123;</span><br><span class="line"> getUsername();<span class="comment">//得到"admin"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>action method:</code></p>
<p>execute =&gt; 验证用户身份,失败返回INPUT</p>
<p><em>return: </em></p>
<p>“student” =&gt; student/StuInfo.action</p>
<p>“teacher” =&gt; teacher/TeacherInfo.action</p>
<p>“admin” =&gt; admin/AdminInfo.action</p>
<p>ERROR/INPUT =&gt; /pages/Login.jsp(with validation error)</p>
<p><code>on the back:</code></p>
<ul>
<li>验证用户名和密码</li>
</ul>
<p><code>more TODO:</code></p>
<ul>
<li>用户Cookie</li>
<li>用户密码RSA加密</li>
<li>验证码</li>
</ul>
<hr>
<h1 id="学生"><a href="#学生" class="headerlink" title="学生"></a>学生</h1><h2 id="class-StuClass-pages-student-info-jsp"><a href="#class-StuClass-pages-student-info-jsp" class="headerlink" title="class StuClass(/pages/student/info.jsp)"></a>class StuClass(/pages/student/info.jsp)</h2><table>
<thead>
<tr>
<th style="text-align:left">name</th>
<th style="text-align:left">type</th>
<th style="text-align:left">field</th>
<th style="text-align:left">more</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">no</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学号</td>
</tr>
<tr>
<td style="text-align:left">name</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">姓名 </td>
</tr>
<tr>
<td style="text-align:left">id</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">身份证</td>
</tr>
<tr>
<td style="text-align:left">birth</td>
<td style="text-align:left">Date</td>
<td style="text-align:left"></td>
<td style="text-align:left">出生日期</td>
</tr>
<tr>
<td style="text-align:left">dept</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">院系</td>
</tr>
<tr>
<td style="text-align:left">major</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">专业</td>
</tr>
<tr>
<td style="text-align:left">domain</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">研究方向</td>
</tr>
<tr>
<td style="text-align:left">enrollyear</td>
<td style="text-align:left">Date</td>
<td style="text-align:left"></td>
<td style="text-align:left">入学年份</td>
</tr>
<tr>
<td style="text-align:left">grade</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">所属年级</td>
</tr>
<tr>
<td style="text-align:left">schoolyear</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学制</td>
</tr>
<tr>
<td style="text-align:left">state</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学籍状态</td>
</tr>
<tr>
<td style="text-align:left">degree</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学位</td>
</tr>
<tr>
<td style="text-align:left">mobile</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">手机号</td>
</tr>
<tr>
<td style="text-align:left">email</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">邮箱</td>
</tr>
<tr>
<td style="text-align:left">addr</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">地址</td>
</tr>
<tr>
<td style="text-align:left">postcode</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">邮编</td>
</tr>
<tr>
<td style="text-align:left">fname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">父姓名</td>
</tr>
<tr>
<td style="text-align:left">fwork</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">父工作单位</td>
</tr>
<tr>
<td style="text-align:left">mname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">母姓名</td>
</tr>
<tr>
<td style="text-align:left">mname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">母工作单位</td>
</tr>
<tr>
<td style="text-align:left">homeNumber</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">家庭电话</td>
</tr>
</tbody>
</table>
<p><em>这里列出的是指对应的StuClass实例里面需要实现的getter和setter函数</em></p>
<p><em>例如:</em><br><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="comment">//页面需要name的值,</span></span><br><span class="line">&lt;s:property value=<span class="string">"detail.name"</span>&gt;</span><br><span class="line"><span class="comment">//而在后台action的类里面,有</span></span><br><span class="line"><span class="keyword">private</span> StuClass detail;</span><br><span class="line"><span class="function"><span class="keyword">public</span> StuClass <span class="title">getDetail</span><span class="params">()</span></span><br><span class="line"></span>&#123;</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">this</span>.detail;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setDetail</span><span class="params">(StuClass detail)</span></span><br><span class="line"></span>&#123;</span><br><span class="line"> <span class="keyword">this</span>.detail = detail;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//那么StuClass这个类中需要有name的getter,即:</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> StuClass <span class="title">getName</span><span class="params">()</span></span><br><span class="line"></span>&#123;</span><br><span class="line"> <span class="keyword">return</span> xxxxxx;<span class="comment">//随便返回什么,但它的值必须是我要的name</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><br></p>
<hr>
<h2 id="个人信息页面-pages-student-info-jsp"><a href="#个人信息页面-pages-student-info-jsp" class="headerlink" title="个人信息页面(/pages/student/info.jsp)"></a>个人信息页面(/pages/student/info.jsp)</h2><p><code>action name:</code> StuInfo</p>
<p><code>servlet name:</code> SampleProject.Student.Info</p>
<p><code>page value:</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">name</th>
<th style="text-align:left">type</th>
<th style="text-align:left">field</th>
<th style="text-align:left">more</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">username</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">用户名</td>
</tr>
<tr>
<td style="text-align:left">identity</td>
<td style="text-align:left">String</td>
<td style="text-align:left">{0,1,2}</td>
<td style="text-align:left">用户身份:学生、教师、管理员</td>
</tr>
</tbody>
</table>
<p><code>action method:</code></p>
<p>execute =&gt; 利用session获得用户名和用户身份</p>
<p><em>return:</em></p>
<p>SUCCESS =&gt; /pages/student/info.jsp</p>
<p>ERROR =&gt; Login.action</p>
<p><code>on the back:</code></p>
<ul>
<li>利用session获得用户名和用户身份</li>
<li>验证用户名权限,错误则返回Login.action</li>
</ul>
<p><code>more TODO:</code></p>
<ul>
<li>全局通知栏</li>
</ul>
<hr>
<h3 id="毕业信息核对-pages-student-infoCheck-jsp"><a href="#毕业信息核对-pages-student-infoCheck-jsp" class="headerlink" title="毕业信息核对(/pages/student/infoCheck.jsp)"></a>毕业信息核对(/pages/student/infoCheck.jsp)</h3><p><code>action name:</code> StuInfoCheck</p>
<p><code>servlet name:</code> SampleProject.Student.InfoCheck</p>
<p><code>page value:(????????)</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">name</th>
<th style="text-align:left">type</th>
<th style="text-align:left">field</th>
<th style="text-align:left">more</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">detail</td>
<td style="text-align:left"><a href="#2-0">StuClass</a></td>
<td style="text-align:left"></td>
<td style="text-align:left">用户信息</td>
</tr>
<tr>
<td style="text-align:left">detail.no</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学号</td>
</tr>
<tr>
<td style="text-align:left">detail.name</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">姓名 </td>
</tr>
<tr>
<td style="text-align:left">detail.id</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">身份证</td>
</tr>
<tr>
<td style="text-align:left">detail.dept</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">院系</td>
</tr>
<tr>
<td style="text-align:left">detail.major</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">专业</td>
</tr>
<tr>
<td style="text-align:left">detail.domain</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">研究方向</td>
</tr>
<tr>
<td style="text-align:left">detail.enrollyear</td>
<td style="text-align:left">Date</td>
<td style="text-align:left"></td>
<td style="text-align:left">入学年份</td>
</tr>
<tr>
<td style="text-align:left">detail.grade</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">所属年级</td>
</tr>
<tr>
<td style="text-align:left">detail.schoolyear</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学制</td>
</tr>
<tr>
<td style="text-align:left">detail.degree</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">学位</td>
</tr>
</tbody>
</table>
<p><a href="#2-0">使用说明</a>见学生类</p>
<p><code>action method:</code></p>
<p>execute =&gt; 执行基本信息的读取</p>
<p><em>return:</em></p>
<p>SUCCESS =&gt; /pages/student/infoCheck.jsp</p>
<p>ERROR =&gt; Login.action</p>
<p><code>on the back:</code></p>
<ul>
<li>利用session获得用户名和用户身份</li>
<li>验证用户名权限,错误则返回Login.action</li>
<li>读取学生毕业信息,填充相应字段</li>
</ul>
<p><code>more TODO:</code></p>
<hr>
<h3 id="基本信息修改-pages-student-infoModify-jsp"><a href="#基本信息修改-pages-student-infoModify-jsp" class="headerlink" title="基本信息修改(/pages/student/infoModify.jsp)"></a>基本信息修改(/pages/student/infoModify.jsp)</h3><p><code>action name:</code> StuInfoModify</p>
<p><code>servlet name:</code> SampleProject.Student.InfoModify</p>
<p><code>page value:</code></p>
<table>
<thead>
<tr>
<th style="text-align:left">name</th>
<th style="text-align:left">type</th>
<th style="text-align:left">field</th>
<th style="text-align:left">more</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">mobile</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">手机号</td>
</tr>
<tr>
<td style="text-align:left">email</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">邮箱</td>
</tr>
<tr>
<td style="text-align:left">addr</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">地址</td>
</tr>
<tr>
<td style="text-align:left">postcode</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">邮编</td>
</tr>
<tr>
<td style="text-align:left">fname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">父姓名</td>
</tr>
<tr>
<td style="text-align:left">fwork</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">父工作单位</td>
</tr>
<tr>
<td style="text-align:left">mname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">母姓名</td>
</tr>
<tr>
<td style="text-align:left">mname</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">母工作单位</td>
</tr>
<tr>
<td style="text-align:left">homeNumber</td>
<td style="text-align:left">String</td>
<td style="text-align:left"></td>
<td style="text-align:left">家庭电话</td>
</tr>
</tbody>
</table>
<p><em>注意</em></p>
<p><code>action method:</code></p>
<p>execute =&gt; 执行基本信息的读取</p>
<p><em>return</em></p>
<p>SUCCESS =&gt; /pages/student/infoModify.jsp</p>
<p>ERROR =&gt; Login.action</p>
<p><code>action method:</code></p>
<p>tryModify =&gt; 尝试执行基本信息的修改</p>
<p>成功:addActionMessage()</p>
<p>失败:addActionError()</p>
<p><em>return</em></p>
<p>SUCCESS =&gt; /pages/student/infoModify.jsp</p>
<p>“fail” =&gt; /pages/student/infoModify.jsp</p>
<p><code>on the back:</code></p>
<ul>
<li>利用session获得用户名和用户身份</li>
<li>验证用户名权限,错误则返回Login.action</li>
<li>在初次载入页面时,将 执行execute函数</li>
<li>在使用页面上的button提交修改时,将 执行 该action的 tryModify函数</li>
</ul>
<p><code>more TODO:</code></p>
</content>
<summary type="html">
<p>软件工程课程项目API</p>
<p>为了进行更好的分工合作,将API罗列如下…</p>
</summary>
<category term="软工" scheme="http://xudshen.info/tags/%E8%BD%AF%E5%B7%A5/"/>
</entry>
<entry>
<title>优酷手机党福利</title>
<link href="http://xudshen.info/2013/04/10/generate-html5-video/"/>
<id>http://xudshen.info/2013/04/10/generate-html5-video/</id>
<published>2013-04-10T08:27:00.000Z</published>
<updated>2016-03-06T15:30:07.000Z</updated>
<content type="html"><p>用lumia在优酷上看视频有个问题:不支持flash,</p>
<p>虽说有html5了,也有m.youku.com,但还是好多视频看不了,</p>
<p>所以搞了个小蛋疼代码。</p>
<h2 id=""><a href="#" class="headerlink" title=""></a><a id="more"></a></h2><p>###输入<br>
<script type="text/javascript">
function doAdd()
{
var element = document.getElementById("showFrame");
element.innerHTML = document.getElementById("srcUrl").value;
};
</script>
<div>
<input id="srcUrl" type="text" value="" autocomplete="off">
<button onclick="doAdd()">Generate</button>
</div>
<div id="showFrame">
</div>
</p>
<hr>
<p>###使用方法</p>
<ol>
<li><p>点击优酷页面中的分享,如下图</p>
<p><img src="youku1.jpg" alt="点击优酷页面中的分享"></p>
</li>
<li><p>选择通用代码,拷贝到上面的输入框中,如下图</p>
<p><img src="youku2.jpg" alt="选择通用代码"></p>
</li>
<li><p>点击Generate即可观看</p>
</li>
</ol>
</content>
<summary type="html">
<p>用lumia在优酷上看视频有个问题:不支持flash,</p>
<p>虽说有html5了,也有m.youku.com,但还是好多视频看不了,</p>
<p>所以搞了个小蛋疼代码。</p>
<h2 id=""><a href="#" class="headerlink" title=""></a>
</summary>
<category term="日常" scheme="http://xudshen.info/tags/%E6%97%A5%E5%B8%B8/"/>
</entry>
<entry>
<title>ListViewBase中的CanReorderItems属性</title>
<link href="http://xudshen.info/2013/04/10/canreorderitems-property-in-listviewbase/"/>
<id>http://xudshen.info/2013/04/10/canreorderitems-property-in-listviewbase/</id>
<published>2013-04-10T05:44:00.000Z</published>
<updated>2014-10-16T07:12:51.000Z</updated>
<content type="html"><p>最近使用GridView时,想实现Item之间的自由拖动排列,一开始自己写了个Panel,后来才发现自带的API中已经有了这么一个属性CanReorderItems,然而在设置为true之后,不没有能使Item自由排列,google了一下才找到原因。</p>
<a id="more"></a>
<p>下面是Flores Eken的解释</p>
<blockquote><p>But, there are some things you need to know to get it to work. First of all the AllowDrop property also needs to be set to true.</p>
<p>And the grid or list needs to be binded to a ObservableVector (no ObservableCollection is not good enough).<br>But in the developer preview only an interface exists for this collection, so you have to make your own implementation or borrow one.. like this one.</p>
<p>One caveat remains.. the ObservableVector needs to be initialized with object as T, strong types will not work in the developer preview of windows 8. Like so:</p>
<footer><strong>Flores Eken</strong><cite><a href="http://www.itq.nl/blogs/post/CanReorderItems3dtrue.aspx" target="_blank" rel="external">CanReorderItems=true</a></cite></footer></blockquote>
<p>简单易懂,就不翻译了=。=</p>
<p>但使用过程中有以下注意点(from <strong>MSDN</strong> <a href="http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.xaml.controls.listviewbase.canreorderitems.aspx" target="_blank" rel="external"><em>ListViewBase.CanReorderItems Property</em></a>):</p>
<blockquote>
<ul>
<li><p>如果启用了项目选择,并且将 <a href="http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.xaml.controls.listviewbase.isswipeenabled.aspx" target="_blank" rel="external">IsSwipeEnabled</a><br> 设置为 false,则用户可以通过鼠标右击来取消选择项目,但是不能通过重击手势,使用触控来取消选择项目。</p>