mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-08-29 18:23:25 +08:00
170 lines
7.8 KiB
HTML
170 lines
7.8 KiB
HTML
<div class="header">
|
||
<div class="subTitle">
|
||
javax.xml.bind.annotation
|
||
</div>
|
||
<h2 class="title" title="Annotation Type XmlElements">Annotation Type XmlElements</h2>
|
||
</div><div class="contentContainer">
|
||
<div class="description">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<hr/> <br/> <pre><a href="../../../../java/lang/annotation/Retention.html" title="annotation in java.lang.annotation">@Retention</a>(<a href="../../../../java/lang/annotation/Retention.html#value--">value</a>=<a href="../../../../java/lang/annotation/RetentionPolicy.html#RUNTIME">RUNTIME</a>)
|
||
<a href="../../../../java/lang/annotation/Target.html" title="annotation in java.lang.annotation">@Target</a>(<a href="../../../../java/lang/annotation/Target.html#value--">value</a>={<a href="../../../../java/lang/annotation/ElementType.html#FIELD">字段</a>,<a href="../../../../java/lang/annotation/ElementType.html#METHOD">METHOD</a>})
|
||
public @interface <span class="memberNameLabel">XmlElements</span></pre>
|
||
<div class="block">
|
||
<p> <span>多个@ <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="javax.xml.bind.annotation中的注释"><code>XmlElement</code></a>注释的容器。</span> <span>程序元素不允许使用相同类型的多个注释。</span> <span>因此,此注释作为多个@XmlElements的容器注释,如下所示:</span> </p>
|
||
<pre> <span>@XmlElements({ @XmlElement(...),@XmlElement(...) })</span> </pre>
|
||
<p> <span><tt>@XmlElements</tt>注解可以与以下程序元素一起使用:</span> </p>
|
||
<ul>
|
||
<li> <span>一个JavaBean属性</span> </li>
|
||
<li> <span>非静态,非瞬态场</span> </li>
|
||
</ul>
|
||
<span>此注释用于注释JavaBean集合属性(例如List)。</span>
|
||
<p> <span><b>用法</b></span> </p>
|
||
<p> <span>用法受以下限制:</span> </p>
|
||
<ul>
|
||
<li> <span>此注释可以与以下注释一起使用:@ <a href="../../../../javax/xml/bind/annotation/XmlIDREF.html" title="javax.xml.bind.annotation中的注释"><code>XmlIDREF</code></a> ,@ <a href="../../../../javax/xml/bind/annotation/XmlElementWrapper.html" title="javax.xml.bind.annotation中的注释"><code>XmlElementWrapper</code></a> 。</span> </li>
|
||
<li> <span>如果在JavaBean属性中也指定了@XmlIDREF,那么每个@ XmlElement.type()都必须包含一个带有<tt>@XmlID注释</tt>的JavaBean属性。</span> </li>
|
||
</ul>
|
||
<p> <span>有关其他常见信息,请参阅javax.xml.bind.package javadoc中的“Package Specification”。</span> </p>
|
||
<hr/>
|
||
<p> <span><b>示例1:</b>映射到元素列表</span> </p>
|
||
<pre> <span>// Mapped code fragment
|
||
public class Foo {
|
||
@XmlElements(
|
||
@XmlElement(name="A", type=Integer.class),
|
||
@XmlElement(name="B", type=Float.class)
|
||
}
|
||
public List items;
|
||
}
|
||
|
||
<!-- XML Representation for a List of {1,2.5}
|
||
XML output is not wrapped using another element -->
|
||
...
|
||
<A> 1 </A>
|
||
<B> 2.5 </B>
|
||
...
|
||
|
||
<!-- XML Schema fragment -->
|
||
<xs:complexType name="Foo">
|
||
<xs:sequence>
|
||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||
<xs:element name="A" type="xs:int"/>
|
||
<xs:element name="B" type="xs:float"/>
|
||
<xs:choice>
|
||
</xs:sequence>
|
||
</xs:complexType></span> </pre>
|
||
<p> <span><b>示例2:</b>映射到包含另一个元素的元素列表</span> </p>
|
||
<pre> <span>// Mapped code fragment
|
||
public class Foo {
|
||
@XmlElementWrapper(name="bar")
|
||
@XmlElements(
|
||
@XmlElement(name="A", type=Integer.class),
|
||
@XmlElement(name="B", type=Float.class)
|
||
}
|
||
public List items;
|
||
}
|
||
|
||
<!-- XML Schema fragment -->
|
||
<xs:complexType name="Foo">
|
||
<xs:sequence>
|
||
<xs:element name="bar">
|
||
<xs:complexType>
|
||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||
<xs:element name="A" type="xs:int"/>
|
||
<xs:element name="B" type="xs:float"/>
|
||
</xs:choice>
|
||
</xs:complexType>
|
||
</xs:element>
|
||
</xs:sequence>
|
||
</xs:complexType></span> </pre>
|
||
<p> <span><b>示例3:</b>使用适配器根据类型更改元素名称。</span> </p>
|
||
<pre> <span>class Foo {
|
||
@XmlJavaTypeAdapter(QtoPAdapter.class)
|
||
@XmlElements({
|
||
@XmlElement(name="A",type=PX.class),
|
||
@XmlElement(name="B",type=PY.class)
|
||
})
|
||
Q bar;
|
||
}
|
||
|
||
@XmlType abstract class P {...}
|
||
@XmlType(name="PX") class PX extends P {...}
|
||
@XmlType(name="PY") class PY extends P {...}
|
||
|
||
<!-- XML Schema fragment -->
|
||
<xs:complexType name="Foo">
|
||
<xs:sequence>
|
||
<xs:element name="bar">
|
||
<xs:complexType>
|
||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||
<xs:element name="A" type="PX"/>
|
||
<xs:element name="B" type="PY"/>
|
||
</xs:choice>
|
||
</xs:complexType>
|
||
</xs:element>
|
||
</xs:sequence>
|
||
</xs:complexType></span> </pre>
|
||
</div>
|
||
<dl>
|
||
<dt>
|
||
<span class="simpleTagLabel">从以下版本开始:</span>
|
||
</dt>
|
||
<dd>
|
||
JAXB2.0
|
||
</dd>
|
||
<dt>
|
||
<span class="seeLabel">另请参见:</span>
|
||
</dt>
|
||
<dd>
|
||
<span><a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="javax.xml.bind.annotation中的注释"><code>XmlElement</code></a> , <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html" title="javax.xml.bind.annotation中的注释"><code>XmlElementRef</code></a> , <a href="../../../../javax/xml/bind/annotation/XmlElementRefs.html" title="javax.xml.bind.annotation中的注释"><code>XmlElementRefs</code></a> , <a href="../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="javax.xml.bind.annotation.adapters中的注释"><code>XmlJavaTypeAdapter</code></a></span>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="summary">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== -->
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="annotation.type.required.element.summary">
|
||
<!-- --> </a> <h3>Required Element Summary</h3>
|
||
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Required Element Summary table, listing required elements, and an explanation">
|
||
<caption>
|
||
<span>Required Elements</span>
|
||
<span class="tabEnd"> </span>
|
||
</caption>
|
||
<tbody>
|
||
<tr>
|
||
<th class="colFirst" scope="col">Modifier and Type</th>
|
||
<th class="colLast" scope="col">Required Element and Description</th>
|
||
</tr>
|
||
<tr class="altColor">
|
||
<td class="colFirst"><code><a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="annotation in javax.xml.bind.annotation">XmlElement</a>[]</code></td>
|
||
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../javax/xml/bind/annotation/XmlElements.html#value--">value</a></span></code>
|
||
<div class="block">
|
||
<span>@ <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="javax.xml.bind.annotation中的注释"><code>XmlElement</code></a>注解的集合</span>
|
||
</div> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table> </li>
|
||
</ul> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="details">
|
||
<ul class="blockList">
|
||
<li class="blockList">
|
||
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
|
||
<ul class="blockList">
|
||
<li class="blockList"><a name="annotation.type.element.detail">
|
||
<!-- --> </a> <h3>Element Detail</h3> <a name="value--">
|
||
<!-- --> </a>
|
||
<ul class="blockListLast">
|
||
<li class="blockList"> <h4>value</h4> <pre>public abstract <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="annotation in javax.xml.bind.annotation">XmlElement</a>[] value</pre>
|
||
<div class="block">
|
||
<span>收集@ <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="javax.xml.bind.annotation中的注释"><code>XmlElement</code></a>注释</span>
|
||
</div> </li>
|
||
</ul> </li>
|
||
</ul> </li>
|
||
</ul>
|
||
</div>
|
||
</div> |