78 lines
4.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="header">
<div class="subTitle">
javax.xml.bind.annotation
</div>
<h2 class="title" title="Annotation Type XmlValue">Annotation Type XmlValue</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">XmlValue</span></pre>
<div class="block">
<p> <span>使用simpleContent或XML Schema简单类型将类映射到XML模式复合类型。</span> </p>
<p> <span><b>用法:</b></span> </p>
<p> <span><tt>@XmlValue</tt>注释可以与以下程序元素一起使用:</span> </p>
<ul>
<li> <span>一个JavaBean属性。</span> </li>
<li> <span>非静态,非瞬态场。</span> </li>
</ul>
<p> <span>有关其他常见信息请参阅javax.xml.bind.package javadoc中的“Package Specification”。</span> </p>
<span>用法受以下使用限制:</span>
<ul>
<li> <span>最多一个字段或属性可以与<tt>@XmlValue</tt>的注解。</span> </li>
<li> <span><tt>@XmlValue</tt>可以使用以下注释: <a href="../../../../javax/xml/bind/annotation/XmlList.html" title="javax.xml.bind.annotation中的注释"><code>XmlList</code></a></span> <span>但是这是多余的,因为<a href="../../../../javax/xml/bind/annotation/XmlList.html" title="javax.xml.bind.annotation中的注释"><code>XmlList</code></a>将类型映射到按列表派生的简单模式类型,就像<a href="../../../../javax/xml/bind/annotation/XmlValue.html" title="javax.xml.bind.annotation中的注释"><code>XmlValue</code></a>那样。</span> </li>
<li> <span>如果字段或属性的类型是集合类型,则集合项类型必须映射到简单的模式类型。</span> </li>
<li> <span>如果字段或属性的类型不是集合类型那么类型必须映射到XML Schema简单类型。</span> </li>
</ul>
<p></p>
<p> <span>如果注释的JavaBean属性是映射到XML Schema构造的唯一类成员则将该类映射到简单类型。</span> <span>如果存在映射到XML属性的其他JavaBean属性除了使用<tt>@XmlValue注释</tt>注释的JavaBean属性之外那么该类将被映射到具有simpleContent的复杂类型。</span> </p>
<p> <span><b>示例1</b>将类映射到XML Schema simpleType</span> </p>
<pre> <span>// Example 1: Code fragment
public class USPrice {
@XmlValue
public java.math.BigDecimal price;
}
&lt;!-- Example 1: XML Schema fragment --&gt;
&lt;xs:simpleType name="USPrice"&gt;
&lt;xs:restriction base="xs:decimal"/&gt;
&lt;/xs:simpleType&gt;</span> </pre>
<p> <span><b>示例2</b>使用simpleContent将类映射到XML Schema complexType。</span> </p>
<pre> <span>// Example 2: Code fragment
public class InternationalPrice {
@XmlValue
public java.math.BigDecimal price;
@XmlAttribute
public String currency;
}
&lt;!-- Example 2: XML Schema fragment --&gt;
&lt;xs:complexType name="InternationalPrice"&gt;
&lt;xs:simpleContent&gt;
&lt;xs:extension base="xs:decimal"&gt;
&lt;xs:attribute name="currency" type="xs:string"/&gt;
&lt;/xs:extension&gt;
&lt;/xs:simpleContent&gt;
&lt;/xs:complexType&gt;</span> </pre>
<p></p>
</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/XmlType.html" title="javax.xml.bind.annotation中的注释"><code>XmlType</code></a></span>
</dd>
</dl> </li>
</ul>
</div>
</div>