系统菜单的分层设计

public List findAll() {
    List list = organizationRepository.findAll();
    Map map = new HashMap();
    List mlist = new ArrayList<>();
    list.stream().forEach(temp -> {
        Menu m = new Menu();
        m.setLabel(temp.getName());
        m.setId(temp.getId());
        m.setUrl("");
        map.put(temp.getId(), m);
    });

    Menu root = new Menu();
    root.setLabel("root");
    for (int i = 0; i < list.size(); i++) {
        Long parentId = list.get(i).getId();
        List mchild=setMenu(Long.valueOf(parentId),map,list);
        Menu parent = map.get(parentId);
        parent.setChildren(mchild);
    }
    root.setChildren(setMenu(Long.valueOf(0),map,list));
    return root.getChildren();
}

public List setMenu(Long parentId,Map map,List list){
    List child = list.stream()
            .filter(temp -> temp.getParentId() == parentId)
            .map(tmp -> tmp.getId())
            .collect(Collectors.toList());
    List mchild = new ArrayList<>();
    for (int j = 0; j < child.size(); j++) {
        mchild.add(map.get(child.get(j)));
    }
    return mchild;
}
 
  
 
  
var vm =new Vue({
    el: '#app',
    data: { content:[],visible: false, defaultProps: {
        children: 'children',
        label: 'label'
    }},
    mounted: function () {
      this.getMenu();
    },
    methods: {
     getMenu: function () {
         this.listLoading = true;

         var params_ = {};

         this.$http.get("/getMenu", {params: params_}).then(function (response) {
             console.log(response.data);
             this.content=response.data;
         }).catch(function (response) {
             console.error(response);
         });
         this.listLoading = false;
     },
        handleNodeClick :function(data) {
            console.log(data);
        }
    }
});

 
 

你可能感兴趣的:(系统菜单的分层设计)