@Override
public String listCity(String parentId) throws Exception {
List<City> all = cityMapper.selectProvinceInfo();
Map<String, City> cityMap = new HashMap<>();
List<City> result = new ArrayList<>();
for (City city : all){
cityMap.put(city.getCitycode(), city);
}
for (City city : all){
if (city.getCityparentcode().equals("0")){
result.add(city);
}else {
cityMap.get(city.getCityparentcode()).getChildren().add(city);
}
}
return JSONObject.toJSONString(result);
}@Override
public String listCity(String p