XmlRootElement 定义bean自动生成xml

 

最外层xml节点类:

 

import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement

public class Chart {

private String XAxisName;

private List<Dataset> dataSet;

private Categories categories;

public List<Dataset> getDataSet() {

return dataSet;

}

public void setDataSet(List<Dataset> dataSet) {

this.dataSet = dataSet;

}

public Categories getCategories() {

return categories;

}

public void setCategories(Categories categories) {

this.categories = categories;

}

@XmlAttribute

public String getXAxisName() {

return XAxisName;

}

public void setXAxisName(String axisName) {

XAxisName = axisName;

}

}


第二层节点类:

import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Dataset {
private String seriesName;
private  List<Set> sets;

@XmlAttribute
public String getSeriesName() {
return seriesName;
}
public void setSeriesName(String seriesName) {
this.seriesName = seriesName;
}
@XmlElement(name="set")
public List<Set> getSets() {
return sets;
}
public void setSets(List<Set> sets) {
this.sets = sets;
}
}
三层:

import java.util.List;

public class Categories {
private List<Category> category;

public List<Category> getCategory() {
return category;
}

public void setCategory(List<Category> category) {
this.category = category;
}
}

四层:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Category {
private String label;

@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
生成结果如附件

你可能感兴趣的:(XmlRootElement,bean自动生成xml)