@Retention(value=RUNTIME) @Target(value=TYPE) public @interface XmlRootElement
用法
@XmlRootElement注释可以与以下程序元素一起使用:
有关其他常见信息,请参阅javax.xml.bind.package javadoc中的“Package Specification”。
当顶级类或枚举类型使用@XmlRootElement注释进行注释时,其值将表示为XML文档中的XML元素。
 此注释可与以下注释一起使用: XmlType , XmlEnum , XmlAccessorType , XmlAccessorOrder 。 
示例1:将元素与XML模式类型相关联
  // Example: Code fragment
     @XmlRootElement
     class Point {
        int x;
        int y;
        Point(int _x,int _y) {x=_x;y=_y;}
     }  
         //Example: Code fragment corresponding to XML output
     marshal( new Point(3,5), System.out);  
         <!-- Example: XML output -->
     <point>
       <x> 3 
       <y> 5 
     </point>  
       注释导致在模式中生成全局元素声明。 
       全局元素声明与类映射到的XML模式类型相关联。 
         <!-- Example: XML schema definition -->
     <xs:element name="point" type="point"/>
     <xs:complexType name="point">
       <xs:sequence>
         <xs:element name="x" type="xs:int"/>
         <xs:element name="y" type="xs:int"/>
       </xs:sequence>
     </xs:complexType>  
       示例2:类型继承的正交性
在类型上注释的元素声明不会由其派生类型继承。 以下示例显示。
  // Example: Code fragment
     @XmlRootElement
     class Point3D extends Point {
         int z;
         Point3D(int _x,int _y,int _z) {super(_x,_y);z=_z;}
     }
     //Example: Code fragment corresponding to XML output *
     marshal( new Point3D(3,5,0), System.out );
     <!-- Example: XML output -->
     <!-- The element name is point3D not point -->
     <point3D>
       <x>3</x>
       <y>5</y>
       <z>0</z>
     </point3D>
     <!-- Example: XML schema definition -->
     <xs:element name="point3D" type="point3D"/>
     <xs:complexType name="point3D">
       <xs:complexContent>
         <xs:extension base="point">
           <xs:sequence>
             <xs:element name="z" type="xs:int"/>
           </xs:sequence>
         </xs:extension>
       </xs:complexContent>
     </xs:complexType>  
       示例3:将全局元素与类映射到的XML模式类型相关联。 
         //Example: Code fragment
     @XmlRootElement(name="PriceElement")
     public class USPrice {
         @XmlElement
         public java.math.BigDecimal price;
     }
     <!-- Example: XML schema definition -->
     <xs:element name="PriceElement" type="USPrice"/>
     <xs:complexType name="USPrice">
       <xs:sequence>
         <xs:element name="price" type="xs:decimal"/>
       </sequence>
     </xs:complexType>  
       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.