代码拉取完成,页面将自动刷新
package jaxb;
import java.io.File;
import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author LiShixi
*/
public class TestJAXB {
public static void main(String[] args) {
TestJAXB testJAXB = new TestJAXB();
testJAXB.toXml();
testJAXB.readXml();
}
public void toXml() {
DemoBeanListWrapper lw = new DemoBeanListWrapper();
for (int i = 0; i < 37; i++) {
DemoBean dd = new DemoBean();
dd.setAge(1);
dd.setName("test" + i);
dd.setBirthday(LocalDate.of(1990, Month.MAY, 6));
lw.getList().add(dd);
}
try {
JAXBContext context = JAXBContext.newInstance(DemoBeanListWrapper.class);
Marshaller cm = context.createMarshaller();
File xmlfile = new File("lsx.xml");
cm.marshal(lw, xmlfile);
} catch (JAXBException ex) {
Logger.getLogger(TestJAXB.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void readXml() {
try {
JAXBContext ctx = JAXBContext.newInstance(DemoBeanListWrapper.class);
Unmarshaller cu = ctx.createUnmarshaller();
DemoBeanListWrapper dl = (DemoBeanListWrapper)cu.unmarshal(new File("lsx.xml"));
int size = dl.getList().size();
System.out.println("size = " + size);
} catch (JAXBException ex) {
Logger.getLogger(TestJAXB.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。