博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java递归mysql生成树_java递归生成树结构的数据
阅读量:7024 次
发布时间:2019-06-28

本文共 1884 字,大约阅读时间需要 6 分钟。

@Data

@EqualsAndHashCode(callSuper =true)

@ApiModel(value = "AccountCaptionVo", description = "会计科目")

public class AccountCaptionVo extends BaseModel {

@ApiModelProperty(value ="会计科目名称",name = "captionName")

private String captionName;

@ApiModelProperty(value = "会计科目编码",name = "captionCode")

private String captionCode;

@ApiModelProperty(value = "父类编码",name = "parentId")

private Long parentId;

@ApiModelProperty(value = "系统科目",name = "systematicSubjects")

private String systematicSubjects;

@ApiModelProperty(value = "借贷方向",name = "lendingDirection")

private String lendingDirection;

@ApiModelProperty(value = "子集",name = "children")

private List children;

@ApiModelProperty(value = "科目名称助记码",name = "mnemonicCode")

private String mnemonicCode;

public static List listToTree(List list) {

//用递归找子。

List treeList = new ArrayList();

for (AccountCaptionVo tree : list) {

//根目录的parentId为-1

if (tree.getParentId() == -1 ) {

treeList.add(findChildren(tree, list));

}

}

return treeList;

}

private static AccountCaptionVo findChildren(AccountCaptionVo tree, List list) {

for (AccountCaptionVo node : list) {

if (node.getParentId().longValue() == tree.getId().longValue()) {

if (tree.getChildren() == null) {

tree.setChildren(new ArrayList());

}

tree.getChildren().add(findChildren(node, list));

}

}

return tree;

}

@GetMapping(path="")

@ApiOperation(value="获取所有会计科目",nickname="getAccountCaption")

public Iterable List(){

List listAccountCaption= capAccountRepository.selecttSql();

List listAccountCaptionVos=new ArrayList<>();

listAccountCaption.stream().forEach(x->

{

AccountCaptionVo AccountCaptionVo=new AccountCaptionVo();

try {

BeanUtils.copyProperties(AccountCaptionVo,x);

listAccountCaptionVos.add(AccountCaptionVo);

} catch (IllegalAccessException e) {

e.printStackTrace();

} catch (InvocationTargetException e) {

e.printStackTrace();

}

});

return listToTree(listAccountCaptionVos);

}

转载地址:http://ewsxl.baihongyu.com/

你可能感兴趣的文章
阿里云计算公司总部开建 2021年竣工
查看>>
详解go语言的array和slice 【一】
查看>>
Microsoft Store 开发者分成已涨到 95%
查看>>
[20150803]无法通过sql_id找到sql语句2.txt
查看>>
简单分析percona-zabbix-templates
查看>>
VK11(SD) vs. MKE1(MM)
查看>>
ORACLE RAC 11.2.0.4 for RHEL6.8安装遭遇PRVF 9992与DBCA遭遇ORA-19504&ORA-15001
查看>>
持续近7个小时的索引扫描的查询优化分析
查看>>
相对传统桌面设计器,在线报表设计器价值何在?
查看>>
值得推荐的几部日本电影(三)(r10笔记第29天)
查看>>
攻城狮的自我营销
查看>>
SAP QM Source Inspection Demo
查看>>
[20151231]空文件.txt
查看>>
开始使用 Markdown
查看>>
WPF笔记(2.5 Canvas)——Layout
查看>>
logback自定义格式转换器
查看>>
双11黑科技,阿里百万级服务器自动化运维系统StarAgent揭秘
查看>>
Linux shell中的I/O重定向相关(转)
查看>>
非对称加密算法RSA使用注意事项
查看>>
SQL Server 2008 R2 性能计数器详细列表(五)
查看>>