我已经以json格式返回我的数据,但我想将其转换为嵌套的json格式数据。
我的代码是在春天写的,跟随
@GET
@Path("/findall")
public List<UserRole> getAll() {
return userroleservice.findAll();
}
该程序返回以下输出
[{"roleId":1,"roleName":"system Admin","createUser":"1","createActive":"N"},{"roleId":2,"roleName":"admin","createUser":"1","createActive":"Y"},{"roleId":3,"roleName":"system Admin","createUser":"1","createActive":"Y"}]
如何将其转换为嵌套的json格式,如
[{ "id": 1, "data": "Category", "attr": { "id": "1", "selected": false }, "children":
[
{ "id": 2, "data": "SubCategory1", "attr": { "id": "2", "selected": false }, "children":
[{ "id": 4, "data": "Item1", "attr": { "id": "4", "selected": false }, "children": [] },
{ "id": 5, "data": "Item2", "attr": { "id": "5", "selected": false }, "children": [] },
{ "id": 6, "data": "Item3", "attr": { "id": "6", "selected": false }, "children": [] }
]
},
{ "id": 3, "data": "SubCategory2", "attr": { "id": "3", "selected": false }, "children":
[{ "id": 7, "data": "Item4", "attr": { "id": "7", "selected": false }, "children": [] },
{ "id": 8, "data": "Item5", "attr": { "id": "8", "selected": false }, "children": [] },
{ "id": 9, "data": "Item6", "attr": { "id": "9", "selected": false }, "children": [] }
]
}
]
}];
或如何以嵌套的json格式返回DB数据?
请任何人帮忙。
答案 0 :(得分:1)