?
数据库表
?
?实体类
@Data
public class Pms implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 分类id
*/
private Long cat_Id;
/**
* 分类名称
*/
private String name;
/**
* 父分类id
*/
private Long parent_Cid;
/**
* 层级
*/
private Integer catLevel;
/**
* 是否显示[0-不显示,1显示]
*/
private Integer show_Status;
/**
* 排序
*/
private Integer sort;
/**
* 图标地址
*/
private String icon;
/**
* 计量单位
*/
private String product_Unit;
/**
* 商品数量
*/
private Integer product_Count;
private List<Pms> children;
}
controller?
@GetMapping("allll")
public R getAllPmss(){
//获取所有
List<Pms> allPms = pmsService.getAllPms();
List<Pms> collect1 = allPms.stream().filter(pms ->
pms.getParent_Cid() == 0
).map((menu)->{
menu.setChildren(getChildren(menu,allPms));
return menu;
}).collect(Collectors.toList());
return R.ok().data("collect1",collect1);
};
//递归
private List<Pms> getChildren(Pms root,List<Pms> all){
List<Pms> children = all.stream().filter(pms -> {
return pms.getParent_Cid() == root.getCat_Id();
}).map(pms -> {
pms.setChildren(getChildren(pms,all));
return pms;
}).collect(Collectors.toList());
return children;
}
效果
?
|