mybits查询树形结构

1、数据库结构

mybits查询树形结构_第1张图片

2、po类结构

mybits查询树形结构_第2张图片

3、xml文件配置

  
        
        
    

    

4、mapper层

 /**
     * 通过父节点递归找到所有的子节点
     * @param pid
     * @return
     */
    public List findChildrenAll(@Param("id") Integer pid);

5、测试

  @Test
    public void umTGroupService(){
       List umTGroups = umTGroupService.findChildrenAll(0);
       System.out.println("umTGroups = " + JSON.toJSONString(umTGroups));
   }

6、结果

[{
	"areaid": 1,
	"children": [{
		"areaid": 1,
		"children": [],
		"code": "1111",
		"id": 2,
		"name": "分公司1",
		"pid": 1
	}, {
		"areaid": 1,
		"children": [],
		"code": "1122",
		"id": 3,
		"name": "分公司2",
		"pid": 1
	}, {
		"areaid": 1,
		"children": [],
		"code": "1133",
		"id": 4,
		"name": "分公司3",
		"pid": 1
	}],
	"code": "11",
	"id": 1,
	"name": "保险总公司",
	"pid": 0
}, {
	"areaid": 1,
	"children": [{
		"areaid": 1,
		"children": [],
		"code": "2211",
		"id": 6,
		"name": "交警分工四1",
		"pid": 5
	}, {
		"areaid": 1,
		"children": [],
		"code": "2222",
		"id": 7,
		"name": "交警分公司2",
		"pid": 5
	}],
	"code": "22",
	"id": 5,
	"name": "交警总公司",
	"pid": 0
}]


你可能感兴趣的:(mybits)