简单实体类和xml文件的相互转换方法(2)

package com.pcq.entity; import java.io.Serializable; public class Emp implements Serializable{ private Integer id; private String name; private Integer deptNo; private Integer age; private String gender; private Integer bossId; private Double salary; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getDeptNo() { return deptNo; } public void setDeptNo(Integer deptNo) { this.deptNo = deptNo; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public Integer getBossId() { return bossId; } public void setBossId(Integer bossId) { this.bossId = bossId; } public Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } }

那么写出来的xml文件格式如下:

<?xml version="1.0" encoding="utf-8"?> <emps> <emp> <id>1</id> <name>张三</name> <deptNo>50</deptNo> <age>25</age> <gender>男</gender> <bossId>6</bossId> <salary>9000.0</salary> </emp> <emp> <id>2</id> <name>李四</name> <deptNo>50</deptNo> <age>22</age> <gender>女</gender> <bossId>6</bossId> <salary>8000.0</salary> </emp> </emps>

假如有个实体类如下:

package com.pcq.entity; public class Student { private Integer id; private String name; private Integer age; private String gender; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } }

那么写出来的xml文件如下

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjswsy.html