以下面的两个类为例,我如何告诉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>
答案 0 :(得分:0)
我明白了,应该从BaseEntity中删除@XmlRootElement
注释。