如何使用 JAXB 生成以下 XML?
<sport type="" gender="">
sport description
</sport>
使用注释类型和性别属性@XmlAttribute
和描述属性@XmlValue
:
package org.example.sport;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Sport {
@XmlAttribute
protected String type;
@XmlAttribute
protected String gender;
@XmlValue;
protected String description;
}
了解更多信息
- http://bdoughan.blogspot.com/2011/06/jaxb-and-complex-types-with-simple.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)