生成递归树
电脑版发表于:2021/11/9 16:45
注意:在生成树时最好从子集开始生产。
//Dto
public class FormsTest2Dto <E>{ @ApiModelProperty("框架id") private Long Id;//子级id @ApiModelProperty(value = "父级id") //example = "0代表顶级或无" 举例说明 private Long p_id; //父级id 0代表顶级或无 @ApiModelProperty("部门名称") private String form_Name;//--部门名称 @ApiModelProperty(value = "人数") private Integer people_Number;//人数(管理多少人) private List<E> ChildrenE; public FormsTest2Dto(Long id, String form_Name) { Id = id; this.form_Name = form_Name; } }
//子集树 方法
public List<FormsTest2Dto> getTree2(Long P_id) { List<FormsTest2Dto> matters = iFormsMapper.queryFormAllDto(new Forms(null, P_id, null)); List<FormsTest2Dto> listreturn=new ArrayList<>(); for (int i = 0; i < matters.size(); i++) { FormsTest2Dto dto= new FormsTest2Dto(matters.get(i).getId(),matters.get(i).getForm_Name()); dto.setChildrenE(getTree2(matters.get(i).getId())); listreturn.add(dto); } return listreturn; }
案例
1
2.1
2.2