mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-07-05 00:04:33 +08:00
197 lines
8.1 KiB
HTML
197 lines
8.1 KiB
HTML
<div class="header">
|
||
<div class="subTitle">
|
||
javax.xml.bind.annotation
|
||
</div>
|
||
<h2 class="title" title="Annotation Type XmlIDREF">Annotation Type XmlIDREF</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">XmlIDREF</span></pre>
|
||
<div class="block">
|
||
<p> <span>将JavaBean属性映射到XML IDREF。</span> </p>
|
||
<p> <span>为了保持XML序列化之后的XML反序列化对象图的引用完整性,需要通过引用或遏制来对对象引用进行编组。</span> <span>注释<tt>@XmlID</tt>和<tt>@XmlIDREF</tt>一起允许通过遏制或引用定制映射JavaBean属性的类型。</span> </p>
|
||
<p> <span><b>用法</b></span> </p>
|
||
<span><tt>@XmlIDREF</tt>注释可以与以下程序元素一起使用:</span>
|
||
<ul>
|
||
<li> <span>一个JavaBean属性</span> </li>
|
||
<li> <span>非静态,非瞬态场</span> </li>
|
||
</ul>
|
||
<p> <span>有关其他常见信息,请参阅javax.xml.bind.package javadoc中的“Package Specification”。</span> </p>
|
||
<p> <span>用法受以下限制:</span> </p>
|
||
<ul>
|
||
<li> <span>如果字段或属性的类型是集合类型,则集合项类型必须包含一个注释为<tt>@XmlID</tt>的属性或字段。</span> </li>
|
||
<li> <span>如果字段或属性是单值,则属性或字段的类型必须包含用<tt>@XmlID注释</tt>的属性或字段。</span> <p> <span>注意:如果集合项目类型或属性类型(对于非集合类型)为java.lang.Object,则该实例必须包含带有<tt>@XmlID</tt>属性注释的属性/字段。</span> </p></li>
|
||
<li> <span>此注释可与以下注释一起使用: <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="javax.xml.bind.annotation中的注释"><code>XmlElement</code></a> , <a href="../../../../javax/xml/bind/annotation/XmlAttribute.html" title="javax.xml.bind.annotation中的注释"><code>XmlAttribute</code></a> , <a href="../../../../javax/xml/bind/annotation/XmlList.html" title="javax.xml.bind.annotation中的注释"><code>XmlList</code></a>和<a href="../../../../javax/xml/bind/annotation/XmlElements.html" title="javax.xml.bind.annotation中的注释"><code>XmlElements</code></a> 。</span> </li>
|
||
</ul>
|
||
<p> <span><b>示例:</b>将JavaBean属性映射到<tt>xs:IDREF</tt> (即通过引用而不是通过遏制)</span> </p>
|
||
<pre> <span>//EXAMPLE: Code fragment
|
||
public class Shipping {
|
||
@XmlIDREF public Customer getCustomer();
|
||
public void setCustomer(Customer customer);
|
||
....
|
||
}
|
||
|
||
<!-- Example: XML Schema fragment -->
|
||
<xs:complexType name="Shipping">
|
||
<xs:complexContent>
|
||
<xs:sequence>
|
||
<xs:element name="customer" type="xs:IDREF"/>
|
||
....
|
||
</xs:sequence>
|
||
</xs:complexContent>
|
||
</xs:complexType></span> </pre>
|
||
<p> <span><b>示例2:</b>以下是遏制与参考的完整示例。</span> </p>
|
||
<pre> <span>// By default, Customer maps to complex type <tt>xs:Customer</tt>
|
||
public class Customer {
|
||
|
||
// map JavaBean property type to <tt>xs:ID</tt>
|
||
@XmlID public String getCustomerID();
|
||
public void setCustomerID(String id);
|
||
|
||
// .... other properties not shown
|
||
}
|
||
|
||
|
||
// By default, Invoice maps to a complex type <tt>xs:Invoice</tt>
|
||
public class Invoice {
|
||
|
||
// map by reference
|
||
@XmlIDREF public Customer getCustomer();
|
||
public void setCustomer(Customer customer);
|
||
|
||
// .... other properties not shown here
|
||
}
|
||
|
||
// By default, Shipping maps to complex type <tt>xs:Shipping</tt>
|
||
public class Shipping {
|
||
|
||
// map by reference
|
||
@XmlIDREF public Customer getCustomer();
|
||
public void setCustomer(Customer customer);
|
||
}
|
||
|
||
// at least one class must reference Customer by containment;
|
||
// Customer instances won't be marshalled.
|
||
@XmlElement(name="CustomerData")
|
||
public class CustomerData {
|
||
// map reference to Customer by containment by default.
|
||
public Customer getCustomer();
|
||
|
||
// maps reference to Shipping by containment by default.
|
||
public Shipping getShipping();
|
||
|
||
// maps reference to Invoice by containment by default.
|
||
public Invoice getInvoice();
|
||
}
|
||
|
||
<!-- XML Schema mapping for above code frament -->
|
||
|
||
<xs:complexType name="Invoice">
|
||
<xs:complexContent>
|
||
<xs:sequence>
|
||
<xs:element name="customer" type="xs:IDREF"/>
|
||
....
|
||
</xs:sequence>
|
||
</xs:complexContent>
|
||
</xs:complexType>
|
||
|
||
<xs:complexType name="Shipping">
|
||
<xs:complexContent>
|
||
<xs:sequence>
|
||
<xs:element name="customer" type="xs:IDREF"/>
|
||
....
|
||
</xs:sequence>
|
||
</xs:complexContent>
|
||
</xs:complexType>
|
||
|
||
<xs:complexType name="Customer">
|
||
<xs:complexContent>
|
||
<xs:sequence>
|
||
....
|
||
</xs:sequence>
|
||
<xs:attribute name="CustomerID" type="xs:ID"/>
|
||
</xs:complexContent>
|
||
</xs:complexType>
|
||
|
||
<xs:complexType name="CustomerData">
|
||
<xs:complexContent>
|
||
<xs:sequence>
|
||
<xs:element name="customer" type="xs:Customer"/>
|
||
<xs:element name="shipping" type="xs:Shipping"/>
|
||
<xs:element name="invoice" type="xs:Invoice"/>
|
||
</xs:sequence>
|
||
</xs:complexContent>
|
||
</xs:complexType>
|
||
|
||
<xs:element name"customerData" type="xs:CustomerData"/>
|
||
|
||
<!-- Instance document conforming to the above XML Schema -->
|
||
<customerData>
|
||
<customer customerID="Alice">
|
||
....
|
||
</customer>
|
||
|
||
<shipping customer="Alice">
|
||
....
|
||
</shipping>
|
||
|
||
<invoice customer="Alice">
|
||
....
|
||
</invoice>
|
||
</customerData></span> </pre>
|
||
<p> <span><b>示例3:</b>将列表映射到IDREF类型的重复元素</span> </p>
|
||
<pre> <span>// Code fragment
|
||
public class Shipping {
|
||
@XmlIDREF
|
||
@XmlElement(name="Alice")
|
||
public List customers;
|
||
}
|
||
|
||
<!-- XML schema fragment -->
|
||
<xs:complexType name="Shipping">
|
||
<xs:sequence>
|
||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||
<xs:element name="Alice" type="xs:IDREF"/>
|
||
</xs:choice>
|
||
</xs:sequence>
|
||
</xs:complexType></span> </pre>
|
||
<p> <span><b>示例4:</b>将列表映射到IDREF类型的元素列表。</span> </p>
|
||
<pre> <span>//Code fragment
|
||
public class Shipping {
|
||
@XmlIDREF
|
||
@XmlElements(
|
||
@XmlElement(name="Alice", type="Customer.class")
|
||
@XmlElement(name="John", type="InternationalCustomer.class")
|
||
public List customers;
|
||
}
|
||
|
||
<!-- XML Schema fragment -->
|
||
<xs:complexType name="Shipping">
|
||
<xs:sequence>
|
||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||
<xs:element name="Alice" type="xs:IDREF"/>
|
||
<xs:element name="John" type="xs:IDREF"/>
|
||
</xs:choice>
|
||
</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/XmlID.html" title="javax.xml.bind.annotation中的注释"><code>XmlID</code></a></span>
|
||
</dd>
|
||
</dl> </li>
|
||
</ul>
|
||
</div>
|
||
</div> |