XStream混叠

Git ww9992019com 发表于 1 周前

www.9951026.net开户请拨15894452300黑熊与人亲安乐死宁波江东区VF41bQ<div style="width:100%;float:left;" class="article-content">

                <input type="hidden" name="article_id" id="article_id" value="6160">
                <input type="hidden" name="catid" id="catid" value="0">

                <p>

混叠是一种技术来定制生成XML或者使用XStream特定的格式化XML。假设,一个下面的XML格式是用于序列化/反序列化Student对象。</p>

<pre class="prettyprint prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb>

<span class="tag">&lt;student</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Suresh"</span><span class="tag">&gt;</span><span class="pln">

</span><span class="tag">&lt;note&gt;</span><span class="pln">

</span><span class="tag">&lt;title&gt;</span><span class="pln">first</span><span class="tag">&lt;/title&gt;</span><span class="pln">

  </span><span class="tag">&lt;description&gt;</span><span class="pln">My first assignment.</span><span class="tag">&lt;/description&gt;</span><span class="pln">

</span><span class="tag">&lt;/note&gt;</span><span class="pln">

</span><span class="tag">&lt;note&gt;</span><span class="pln">

  </span><span class="tag">&lt;title&gt;</span><span class="pln">second</span><span class="tag">&lt;/title&gt;</span><span class="pln">

  </span><span class="tag">&lt;description&gt;</span><span class="pln">My second assignment.</span><span class="tag">&lt;/description&gt;</span><span class="pln">

</span><span class="tag">&lt;/note&gt;</span><span class="pln">

</span><span class="tag">&lt;/student&gt;</span></pre>

<p>

根椐上面的XML格式,让我们创建的模型类。</p>

<pre class="prettyprint prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb>

<span class="kwd">class</span><span class="pln"> </span><span class="typ">Student</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> studentName</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;</span><span class="pln"> notes </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;();</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">Student</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> name</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">studentName </span><span class="pun">=</span><span class="pln"> name</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> addNote</span><span class="pun">(</span><span class="typ">Note</span><span class="pln"> note</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  notes</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">note</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getName</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> studentName</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;</span><span class="pln"> getNotes</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> notes</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">Note</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">Note</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> title</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> description</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">title </span><span class="pun">=</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">description </span><span class="pun">=</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getTitle</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getDescription</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span></pre>

<p>

我们使用 XStream 测试上述对象序列化。</p>

<p>

创建一个Java类名为XStreamTester在文件 C:\&gt;XStream_WORKSPACE\com\yiibai\xstream.</p>

<p>

<i>File: XStreamTester.java</i></p>

<pre class="prettyprint tryit prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb cursor: default background-image: url background-attachment: initial background-size: background-origin: background-clip: background-position: background-repeat: no-repeat>

<span class="kwd">package</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">yiibai</span><span class="pun">.</span><span class="pln">xstream</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">ByteArrayInputStream</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">ByteArrayOutputStream</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">ArrayList</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">List</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="typ">OutputKeys</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="typ">Source</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="typ">Transformer</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="pln">sax</span><span class="pun">.</span><span class="typ">SAXSource</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="pln">sax</span><span class="pun">.</span><span class="typ">SAXTransformerFactory</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">.</span><span class="pln">stream</span><span class="pun">.</span><span class="typ">StreamResult</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">sax</span><span class="pun">.</span><span class="typ">InputSource</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">thoughtworks</span><span class="pun">.</span><span class="pln">xstream</span><span class="pun">.</span><span class="typ">XStream</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">thoughtworks</span><span class="pun">.</span><span class="pln">xstream</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="pln">xml</span><span class="pun">.</span><span class="typ">StaxDriver</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">XStreamTester</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> main</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> args</span><span class="pun">[]){</span><span class="pln">

  </span><span class="typ">XStreamTester</span><span class="pln"> tester </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">XStreamTester</span><span class="pun">();</span><span class="pln">

  </span><span class="typ">XStream</span><span class="pln"> xstream </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">XStream</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StaxDriver</span><span class="pun">());</span><span class="pln">

  </span><span class="typ">Student</span><span class="pln"> student </span><span class="pun">=</span><span class="pln"> tester</span><span class="pun">.</span><span class="pln">getStudentDetails</span><span class="pun">();</span><span class="pln">

  </span><span class="com">//Object to XML Conversion</span><span class="pln">

  </span><span class="typ">String</span><span class="pln"> xml </span><span class="pun">=</span><span class="pln"> xstream</span><span class="pun">.</span><span class="pln">toXML</span><span class="pun">(</span><span class="pln">student</span><span class="pun">);</span><span class="pln">

  </span><span class="typ">System</span><span class="pun">.</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">formatXml</span><span class="pun">(</span><span class="pln">xml</span><span class="pun">));</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">Student</span><span class="pln"> getStudentDetails</span><span class="pun">(){</span><span class="pln">

  </span><span class="typ">Student</span><span class="pln"> student </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Student</span><span class="pun">(</span><span class="str">"Mahesh"</span><span class="pun">);</span><span class="pln">

  student</span><span class="pun">.</span><span class="pln">addNote</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Note</span><span class="pun">(</span><span class="str">"first"</span><span class="pun">,</span><span class="str">"My first assignment."</span><span class="pun">));</span><span class="pln">

  student</span><span class="pun">.</span><span class="pln">addNote</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Note</span><span class="pun">(</span><span class="str">"second"</span><span class="pun">,</span><span class="str">"My Second assignment."</span><span class="pun">));</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> student</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> formatXml</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> xml</span><span class="pun">){</span><span class="pln">

  </span><span class="kwd">try</span><span class="pun">{</span><span class="pln">

     </span><span class="typ">Transformer</span><span class="pln"> serializer</span><span class="pun">=</span><span class="pln"> </span><span class="typ">SAXTransformerFactory</span><span class="pun">.</span><span class="pln">newInstance</span><span class="pun">().</span><span class="pln">newTransformer</span><span class="pun">();</span><span class="pln">

     serializer</span><span class="pun">.</span><span class="pln">setOutputProperty</span><span class="pun">(</span><span class="typ">OutputKeys</span><span class="pun">.</span><span class="pln">INDENT</span><span class="pun">,</span><span class="pln"> </span><span class="str">"yes"</span><span class="pun">);</span><span class="pln">

     serializer</span><span class="pun">.</span><span class="pln">setOutputProperty</span><span class="pun">(</span><span class="str">"{http://xml.apache.org/xslt}indent-amount"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"2"</span><span class="pun">);</span><span class="pln">

     </span><span class="typ">Source</span><span class="pln"> xmlSource</span><span class="pun">=</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">SAXSource</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">InputSource</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayInputStream</span><span class="pun">(</span><span class="pln">xml</span><span class="pun">.</span><span class="pln">getBytes</span><span class="pun">())));</span><span class="pln">

     </span><span class="typ">StreamResult</span><span class="pln"> res </span><span class="pun">=</span><span class="pln">  </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StreamResult</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayOutputStream</span><span class="pun">());</span><span class="pln">

     serializer</span><span class="pun">.</span><span class="pln">transform</span><span class="pun">(</span><span class="pln">xmlSource</span><span class="pun">,</span><span class="pln"> res</span><span class="pun">);</span><span class="pln">

     </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">String</span><span class="pun">(((</span><span class="typ">ByteArrayOutputStream</span><span class="pun">)</span><span class="pln">res</span><span class="pun">.</span><span class="pln">getOutputStream</span><span class="pun">()).</span><span class="pln">toByteArray</span><span class="pun">());</span><span class="pln">

  </span><span class="pun">}</span><span class="kwd">catch</span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">){</span><span class="pln">

     </span><span class="kwd">return</span><span class="pln"> xml</span><span class="pun">;</span><span class="pln">

  </span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">Student</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> studentName</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;</span><span class="pln"> notes </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ArrayList</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;();</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">Student</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> name</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">studentName </span><span class="pun">=</span><span class="pln"> name</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> addNote</span><span class="pun">(</span><span class="typ">Note</span><span class="pln"> note</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  notes</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">note</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getName</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> studentName</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">Note</span><span class="pun">&gt;</span><span class="pln"> getNotes</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> notes</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">Note</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">Note</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> title</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> description</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">title </span><span class="pun">=</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">description </span><span class="pun">=</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getTitle</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> title</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getDescription</span><span class="pun">(){</span><span class="pln">

  </span><span class="kwd">return</span><span class="pln"> description</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span></pre>

<p>

<strong>验证结果</strong></p>

<p>

使用javac编译器编译如下类:</p>

<pre class="prettyprint notranslate prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb>

<span class="pln">C</span><span class="pun">:</span><span class="pln">\X</span><span class="typ">Stream_WORKSPACE</span><span class="pln">\com\yiibai\xstream</span><span class="pun">&gt;</span><span class="pln">javac </span><span class="typ">XStreamTester</span><span class="pun">.</span><span class="pln">java</span></pre>

<p>

现在运行XStreamTester看到的结果:</p>

<pre class="prettyprint notranslate prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb>

<span class="pln">C</span><span class="pun">:</span><span class="pln">\X</span><span class="typ">Stream_WORKSPACE</span><span class="pln">\com\yiibai\xstream</span><span class="pun">&gt;</span><span class="pln">java </span><span class="typ">XStreamTester</span></pre>

<p>

<strong>验证输出</strong></p>

<pre class="prettyprint notranslate prettyprinted" courier new monospace border-top-left-radius: border-top-right-radius: border-bottom-right-radius: border-bottom-left-radius: width: line-height: font-size: overflow: auto color: rgb>

<span class="pun">&lt;?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pln"> encoding</span><span class="pun">=</span><span class="str">"UTF-8"</span><span class="pun">?&gt;</span><span class="pln">

</span><span class="tag">&lt;com.yiibai.xstream.Student&gt;</span><span class="pln">

</span><span class="tag">&lt;studentName&gt;</span><span class="pln">Mahesh</span><span class="tag">&lt;/studentName&gt;</span><span class="pln">

</span><span class="tag">&lt;notes&gt;</span><span class="pln">

</span><span class="tag">&lt;com.yiibai.xstream.Note&gt;</span><span class="pln">

  </span><span class="tag">&lt;title&gt;</span><span class="pln">first</span><span class="tag">&lt;/title&gt;</span><span class="pln">

  </span><span class="tag">&lt;description&gt;</span><span class="pln">My first assignment.</span><span class="tag">&lt;/description&gt;</span><span class="pln">

</span><span class="tag">&lt;/com.yiibai.xstream.Note&gt;</span><span class="pln">

</span><span class="tag">&lt;com.yiibai.xstream.Note&gt;</span><span class="pln">

  </span><span class="tag">&lt;title&gt;</span><span class="pln">second</span><span class="tag">&lt;/title&gt;</span><span class="pln">

  </span><span class="tag">&lt;description&gt;</span><span class="pln">My Second assignment.</span><span class="tag">&lt;/description&gt;</span><span class="pln">

</span><span class="tag">&lt;/com.yiibai.xstream.Note&gt;</span><span class="pln">

</span><span class="tag">&lt;/notes&gt;</span><span class="pln">

</span><span class="tag">&lt;/com.yiibai.xstream.Student&gt;</span></pre>

<p>

在上面的结果,我们已经看到了Student对象名称是完全合格的。要替换它作为学生的标签,按照下面的链接。</p>

<a href="http://www.yiibai.com/xstream/xstream_class_aliasing.html">类混叠</a>

<p>

另外,在上述结果中可以看出,所需studentName要重命名来命名。要取代它,按照下面的链接。</p>

<a href="http://www.yiibai.com/xstream/xstream_field_aliasing.html">字段混叠</a>

<p>

在上面的结果,我们可以看到,笔记标记被添加成为笔记列表。替换它,按照下面的链接。</p>

<a href="http://www.yiibai.com/xstream/xstream_implicit_aliasing.html">隐式集合混叠</a>

<p>

在上面的结果,我们可以看到这个名字来作为一个子节点,需要将它作为根节点的属性。替换它,按照下面的链接。</p>

<a href="http://www.yiibai.com/xstream/xstream_attribute_aliasing.html" target="_blank">属性混叠</a><br>

<br>

<a href="http://www.yiibai.com/xstream/xstream_package_aliasing.html" target="_blank">包混叠</a>

                <br>
                <p style="text-align:center;float:left;width:100%;margin-top:24px;margin-bottom:18px;">
                        <button class="layui-btn layui-btn-danger" id="btn-reward"> ¥ 我要打赏 </button>  
                        <button class="layui-btn" id="article-perfect">
                            <i class="layui-icon layui-icon-edit"></i>教程纠错
                        </button>
                        <button class="layui-btn layui-btn-normal" id="action-collection">
                            <i class="layui-icon layui-icon-rate"></i>收藏
                        </button>
                </p>



                <div style="width:100%;margin-bottom: 16px; height: 32px;margin-top:18px;float:left;">

                    <span style="float:left;">上一篇:<a href="http://f2e.im/u/ww9992019com" title="XStream入门应用程序"><i class="layui-icon"></i>
                            XStream入门应用程序</a></span>
                                            <span style="float:right;">下一篇:<a href="http://f2e.im/u/ww9992019com" style="float:right;" title="下一篇:XStream类混叠"><i class="layui-icon"></i>
                            XStream类混叠</a></span>
                                            <div id="googlead" style="float:left;margin-top:8px;">
                        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                        <!-- yiibai下方 -->
                        <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1090193214637198" data-ad-slot="6494738921"></ins>
                        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>
                    </div>
                </div>

                <div style="width:100%;margin-top:18px;float:left;">


            </div>
暂无回复,说出你的观点吧
登录后即可参与回复