{
"age": "20岁",
"id": 1,
"name": "snowalker",
"teacherBeans": [
{
"college": "学院0",
"name": "教师0"
},
{
"college": "学院1",
"name": "教师1"
},
{
"college": "学院2",
"name": "教师2"
}
]
}
[
{
"college": "学院0",
"name": "教师0"
},
{
"college": "学院1",
"name": "教师1"
},
{
"college": "学院2",
"name": "教师2"
}
]
@XmlRootElement(name="teachers")
@Path("root")
public class Root {
private List<TeacherBean> teacherBeans;
private Integer id;
private String name;
private String age;
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 String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public List<TeacherBean> getTeacherBeans() {
return teacherBeans;
}
public void setTeacherBeans(List<TeacherBean> teacherBeans) {
this.teacherBeans = teacherBeans;
}
}
@Path("root")
public class RootResource {
@GET
@Path("data")
@Produces(MediaType.APPLICATION_JSON)
public Root teachersInfo() {
Root root = new Root();
List<TeacherBean> teacherBeans = new ArrayList<>();
for (int i = 0; i < 3; i++) {
TeacherBean teacherBean = new TeacherBean();
teacherBean.setName("教师" + String.valueOf(i));
teacherBean.setCollege("学院" + String.valueOf(i));
teacherBeans.add(teacherBean);
}
root.setAge("20岁");
root.setId(1);
root.setName("snowalker");
root.setTeacherBeans(teacherBeans);
return root;
}
}
{
"age": "20岁",
"id": 1,
"name": "snowalker",
"teacherBeans": [
{
"college": "学院0",
"name": "教师0"
},
{
"college": "学院1",
"name": "教师1"
},
{
"college": "学院2",
"name": "教师2"
}
]
}
后台返回的数据均是各种数据之间通过组合之后而成,因此潜心分析一定可以得到想要的结果。