在XmlElement上添加嵌套对象的属性

时间:2015-10-26 12:00:10

标签: java xml jaxb

我有以下代码

@XmlAccessorType(XmlAccessType.NONE)
public class SeatDescriptor {

  String id;
  Seat seat;

  @XmlAttribute
  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  @XmlElement
  public Seat getSeat() {
    return seat;
  }
  public void setSeat(Seat seat) {
    this.seat = seat;
  }
}

@XmlAccessorType(XmlAccessType.NONE)
public class Seat {
  int number;

  @XmlAttribute
  public int getNumber() {
    return number;
  }

  public void setNumber(int number) {
    this.number = number;
  }
}

代码生成以下类型的XML

<seatdesc id="ii">
        <seat number="20"/>
    </seatdesc>

我想要的是seatdesc标签上的Seat对象的属性。我怎样才能做到这一点?

<seatdesc id="ii"  number="20" />

0 个答案:

没有答案