根据给定的数据结构和数据,写构造树状结构的java 代码,90% 可用。在通义千问,智谱 AI 测试良好。
下面的<json>是一个树状节点的列表,<code>定义了节点的类,parentId表示上级节点的ID,请写一个java方法把它整理成树状结构。
<code>
public class TreeNodeVO {
private Long id;
private Long appId;
private String tagName;
private Long parentId;
private String idPath;
private JSONObject extInfo;
private Long status;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date createdTime;
private List<TreeNodeVO> children;
}
</code>
<json>
[ { "id": 2, "appId": 1, "tagName": "C", "parentId": 1, "idPath": "1/", "extInfo": "{}", "status": 1, "createdTime": "2024-03-19 08:01:43" }, { "id": 3, "appId": 1, "tagName": "D", "parentId": 2, "idPath": "1/2/", "extInfo": "{}", "status": 1, "createdTime": "2024-03-19 18:44:27" }, { "id": 4, "appId": 1, "tagName": "E", "parentId": 3, "idPath": "1/2/3/", "extInfo": "{}", "status": 1, "createdTime": "2024-03-20 09:34:49" } ]
</json>