Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在运行时设置@XmlRootElement?我有一个需要转换为 xml 的类,但该类应该转换为多个 XML,唯一不同的是根元素名称。
如果该类表示一种可由多个元素名称使用的 XML 模式类型,则不应对其进行注释@XmlRootElement。相反,它应该是 annotated @XmlType,并且当您想要将 XML 的实例编组MyType为 XML 时,您将其包装在JAXBElement<MyType>指定元素名称的 a 中。
@XmlRootElement
@XmlType
MyType
JAXBElement<MyType>