把java中的字段转译成xml格式显示出来并注入相应的值
publicclassa{privateStringa1;privateStringa2;privateBooleana4=false;privateList<b>ds;...
public class a {
private String a1;
private String a2;
private Boolean a4 = false;
private List<b> ds;
public List<b> getDs() {
return ds;
}
public void setDs(List<b> ds) {
this.ds = ds;
}
public String getA1() {
return a1;
}
public void setA1(String a1) {
this.a1 = a1;
}
public String getA2() {
return a2;
}
public void setA2(String a2) {
this.a2 = a2;
}
public Boolean getA4() {
return a4;
}
public void setA4(Boolean a4) {
this.a4 = a4;
}
}
public class b {
private List<c> cList;
private List<d> dList;
public List<c> getcList() {
return cList;
}
public void setcList(List<c> cList) {
this.cList = cList;
}
public List<d> getdList() {
return dList;
}
public void setdList(List<d> dList) {
this.dList = dList;
}
} 展开
private String a1;
private String a2;
private Boolean a4 = false;
private List<b> ds;
public List<b> getDs() {
return ds;
}
public void setDs(List<b> ds) {
this.ds = ds;
}
public String getA1() {
return a1;
}
public void setA1(String a1) {
this.a1 = a1;
}
public String getA2() {
return a2;
}
public void setA2(String a2) {
this.a2 = a2;
}
public Boolean getA4() {
return a4;
}
public void setA4(Boolean a4) {
this.a4 = a4;
}
}
public class b {
private List<c> cList;
private List<d> dList;
public List<c> getcList() {
return cList;
}
public void setcList(List<c> cList) {
this.cList = cList;
}
public List<d> getdList() {
return dList;
}
public void setdList(List<d> dList) {
this.dList = dList;
}
} 展开
1个回答
展开全部
Book book=new Book();
book.setName("zhangsan");
JAXBContext context = JAXBContext.newInstance(Book.class);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(book, System.out);
//Book类头上要加@xmlRootElemet
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询