2016-08-10 138 views
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> 

回答

0

我想通了,應該從BaseEntity刪除@XmlRootElement註解。