JAXB等于@Mappedsuperclass

时间:2016-08-10 13:34:32

标签: jaxb

以下面的两个类为例,我如何告诉JAXB将BaseEntity的id字段呈现为Person的属性?

@MappedSuperclass
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @XmlAttribute
    private Long id;

    @Temporal(TemporalType.TIMESTAMP)
    @XmlAttribute
    private Date createdDate;

    // Getters & setters

}

@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SuperHero extends BaseEntity {

    private String name;

    // Getters & setters

}

期望的输出:

<SuperHero id="XYZ" createdDate="today">
    <Name>Superman</Name>
</SuperHero>

1 个答案:

答案 0 :(得分:0)

我明白了,应该从BaseEntity中删除@XmlRootElement注释。