目录
1、此类情况使用场景
2、实现代码
3、数据结果展示:
如果直接通过SQL查询,返回给所需树状结构数据,同时按照树的层级进行了排序 如下图所示:
public static JSONArray treeRecursionDataList(List
{
"rows": [
{
"ownerCompany": 10002,
"modifyTime": 1537325781000,
"createTime": 1536891501000,
"modifyId": 2592,
"categoryLevel": "1",
"creatorId": 1071,
"categoryState": "1",
"childList": [
{
"ownerCompany": 10002,
"modifyTime": 1536891514000,
"createTime": 1536891514000,
"modifyId": 1071,
"categoryLevel": "2",
"creatorId": 1071,
"categoryState": "1",
"childList": [
{
"ownerCompany": 10002,
"modifyTime": 1537240127000,
"createTime": 1536891591000,
"modifyId": 1172,
"categoryLevel": "3",
"creatorId": 1071,
"categoryState": "1",
"childList": [ ],
"id": 152,
"categoryName": "职业素养",
"parentId": 148,
"orgId": 133
}
],
"id": 148,
"categoryName": "专业理论知识",
"parentId": 147,
"orgId": 1
}
],
"id": 147,
"categoryName": "岗位资格性培训1",
"parentId": 0,
"orgId": 156
},
{
"ownerCompany": 10002,
"modifyTime": 1535097185000,
"createTime": 1534737840000,
"modifyId": 1071,
"categoryLevel": "1",
"creatorId": 1071,
"categoryState": "1",
"childList": [
{
"ownerCompany": 10002,
"modifyTime": 1536721891000,
"createTime": 1534738691000,
"modifyId": 2585,
"categoryLevel": "2",
"creatorId": 1071,
"categoryState": "1",
"childList": [
{
"ownerCompany": 10002,
"modifyTime": 1537240535000,
"createTime": 1537240489000,
"modifyId": 1172,
"categoryLevel": "3",
"creatorId": 1172,
"categoryState": "1",
"childList": [ ],
"id": 160,
"categoryName": "子分类1",
"parentId": 100,
"orgId": 133
}
],
"id": 100,
"categoryName": "工班长培训",
"parentId": 82,
"orgId": 1
},
{
"ownerCompany": 10002,
"modifyTime": 1535104574000,
"createTime": 1535104547000,
"modifyId": 1071,
"categoryLevel": "2",
"creatorId": 1071,
"categoryState": "1",
"childList": [
{
"ownerCompany": 10002,
"modifyTime": 1537240549000,
"createTime": 1537240549000,
"modifyId": 1172,
"categoryLevel": "3",
"creatorId": 1172,
"categoryState": "1",
"childList": [ ],
"id": 161,
"categoryName": "子分类2",
"parentId": 118,
"orgId": 133
}
],
"id": 118,
"categoryName": "特种设备作业培训",
"parentId": 82,
"orgId": 1
}
],
"id": 82,
"categoryName": "岗位资格性培训",
"parentId": 0,
"orgId": 1
}
],
"msgInfo": "",
"msgCode": "0",
"isSuccess": "true"
}
记录一下可参考文章:https://www.jb51.net/article/125076.htm