关于element-ui:eltree-递归显示机构城市等信息

2次阅读

共计 1257 个字符,预计需要花费 4 分钟才能阅读完成。

构造最简略的 el-tree 应用, 常常用来显示机构, 菜单, 省市县等信息


<el-tree ref="tree" :data="treedata" :props="defaultProps2"></el-tree>

list: function(){u.axios.get("http://localhost:6088/treeList").then(function(res){console.log(res.data);
            // 为什么用 push
          quan.treedata.push(res.data);
        });
      }

后端, 应用正向递归查问

package com.bw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bw.entity.City;
import com.bw.entity.CityExample;
import com.bw.entity.CityExample.Criteria;
import com.bw.mapper.CityMapper;

@RestController
public class CityTreeController {
    @Autowired
    CityMapper cityMapper;
    
    /**
     * 
     * 难度系数在 ****
     * redisTemplate ***
     * @param city
     * @return
     */
    public City recur(City city){//city--> 父节点
        CityExample cityExample=new CityExample();
        Criteria criteria = cityExample.createCriteria();
        criteria.andPidEqualTo(city.getCityid());//pid=
        List<City> children = cityMapper.selectByExample(cityExample);//select * from city
        for (City child : children) {this.recur(child);
        }
        city.setChild(children);
        return city;
    }
    
    
    @RequestMapping("treeList")
    public City treeList(){City city = cityMapper.selectByPrimaryKey(1);//1--> 中国的节点
        city=this.recur(city);
        return city;
    }

}

数据库构造

1    中国    0
2    河北    1
3    河南    1
4    山东    1
5    邯郸    2
6    石家庄    2
7    郑州    3
8    洛阳    3
9    邯郸一街    5
10    邯郸二街    5
正文完
 0