jaxb
来源:互联网 发布:淘宝店铺宣传广告语 编辑:程序博客网 时间:2024/06/06 20:59
首先导入:javax.xml.bind
package com.xml;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Customer {
String name;
int age;
int id;
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
@XmlElement
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
@XmlAttribute
public void setId(int id) {
this.id = id;
}
}
package com.xml;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class JAXBExample {
public static void main(String[] args) {
Customer customer = new Customer();
customer.setId(100);
customer.setName("mkyong");
customer.setAge(29);
try {
File file = new File("f:\\file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(customer, file);
jaxbMarshaller.marshal(customer, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
- JAXB
- jaxb
- JAXB
- JAXB
- jaxb
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- JAXB
- WinCE串口编程API函数
- js发送邮件确定email地址
- sublime package control install
- 大数据时代,你还为数据单位,而困惑么? 计算机存储单位:Byte、KB、MB、GB、TB、PB、EB分别叫什么?他们的进率是多少?
- 10.1 NSThread 不常用 难以管理
- jaxb
- android button测试
- java之Integer知识整理
- 5,29 微积分 直线与曲线交面积
- jquery 中json数组的操作 增删改
- TP 配置项及说明
- 如何提高SAT文章阅读速度?
- Android WebView先加载网页文字,后加载图片
- 颜色对照表