0
以下面兩個類爲例,如何告訴JAXB將BaseEntity的id字段作爲Person的屬性進行渲染?JAXB等價於@Mappedsuperclass
@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>