Java中将查询出来的数据转成树形结构

1.定义实体类


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

public class EstateReportCommCondition {

    private String commId;

    private String commName;

    private List nodes;

    public String getCommId() {
        return commId;
    }

    public void setCommId(String commId) {
        this.commId = commId;
    }

    public String getCommName() {
        return commName;
    }

    public void setCommName(String commName) {
        this.commName = commName;
    }

    public List getnodes() {
        return nodes;
    }

    public void setnodes(List nodes) {
        this.nodes = nodes;
    }

    @Override
    public String toString() {
        return "EstateReportCommCondition{" +
                "commId='" + commId + '\'' +
                ", commName='" + commName + '\'' +
                ", nodes=" + nodes +
                '}';
    }
}

2.数据库查询结果

3.MyBatis配置文件


		
		
		
			
			
		

4.返回结果

{
        "corpCostId": "001",
        "costName": "服务费",
        "nodes": [
          {
            "corpCostId": "1000001",
            "costName": "卫生服务费"
          },
          {
            "corpCostId": "1000002",
            "costName": "车位服务费"
          }
}

 

你可能感兴趣的:(java)