查询城市列表

@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);
}

 

public class City {
    private String citycode;

    private String cityname;

    private String cityparentcode;

    private Integer citylevel;
    private List<City> children = new ArrayList<>();

    public List<City> getChildren() {
        return children;
    }

    public void setChildren(List<City> children) {
        this.children = children;
    }

    public String getCitycode() {
        return citycode;
    }

    public void setCitycode(String citycode) {
        this.citycode = citycode == null ? null : citycode.trim();
    }

    public String getCityname() {
        return cityname;
    }

    public void setCityname(String cityname) {
        this.cityname = cityname == null ? null : cityname.trim();
    }

    public String getCityparentcode() {
        return cityparentcode;
    }

    public void setCityparentcode(String cityparentcode) {
        this.cityparentcode = cityparentcode == null ? null : cityparentcode.trim();
    }

    public Integer getCitylevel() {
        return citylevel;
    }

    public void setCitylevel(Integer citylevel) {
        this.citylevel = citylevel;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值