@Retention(value=RUNTIME) @Target(value={字段,METHOD}) public @interface XmlAttribute
将JavaBean属性映射到XML属性。
用法
@XmlAttribute注释可以与以下程序元素一起使用:
静态最终字段映射到XML固定属性。
有关其他常见信息,请参阅javax.xml.bind.package javadoc中的“Package Specification”。
用法受以下限制: // Examples
@XmlAttribute List<Integer> items; //legal
@XmlAttribute List<Bar> foo; // illegal if Bar does not map to a schema simple type
// Examples
@XmlAttribute int foo; // legal
@XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type
XmlID
, XmlIDREF
, XmlList
, XmlSchemaType
, XmlValue
, XmlAttachmentRef
, XmlMimeType
, XmlInlineBinaryData
, XmlJavaTypeAdapter
。 示例1:将JavaBean属性映射到XML属性。
//Example: Code fragment
public class USPrice {
@XmlAttribute
public java.math.BigDecimal getPrice() {...} ;
public void setPrice(java.math.BigDecimal ) {...};
}
<!-- Example: XML Schema fragment -->
<xs:complexType name="USPrice">
<xs:sequence>
</xs:sequence>
<xs:attribute name="price" type="xs:decimal"/>
</xs:complexType>
示例2:将JavaBean属性映射到具有匿名类型的XML属性。
参见@XmlType
中的例7。
示例3:将JavaBean集合属性映射到XML属性。
// Example: Code fragment
class Foo {
...
@XmlAttribute List<Integer> items;
}
<!-- Example: XML Schema fragment -->
<xs:complexType name="foo">
...
<xs:attribute name="items">
<xs:simpleType>
<xs:list itemType="xs:int"/>
</xs:simpleType>
</xs:complexType>
XmlType
public abstract String name
public abstract boolean required
public abstract String namespace
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.