取出全球的主要国家城市(只有中国有省市区)

本文介绍了一种基于Java的方法来查询和组织国家、州/省及城市的数据。通过使用DAO层提供的方法,该方法实现了从数据库中获取国家信息,并进一步获取每个国家下对应的州/省及其所属的城市。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@Override
public List<ShpLocationYSVo> queryArza() {
List<ShpLocation> shpLocationList = shpLocationDao.queryContry();//国家
List<ShpLocationYSVo> shpLocationYSVoList = new ArrayList<ShpLocationYSVo>();
for (ShpLocation shpLocation : shpLocationList) {
ShpLocationYSVo shpLocationYSVo = new ShpLocationYSVo();
shpLocationYSVo.setId(shpLocation.getId());
shpLocationYSVo.setPid(shpLocation.getPid());
shpLocationYSVo.setNameEn(shpLocation.getNameEn());
shpLocationYSVo.setNamePinyin(shpLocation.getNamePinyin());
shpLocationYSVo.setsName(shpLocation.getsName());
shpLocationYSVoList.add(shpLocationYSVo);
/*********以上为国家*************/
List<ShpLocationState> shpLocationStateList = new ArrayList<ShpLocationState>();
ShpLocationState shpLocationState = null;
ShpLocation shpLocationstate = new ShpLocation();
if (shpLocation.getsName().equals("中国")) {
shpLocationstate.setId(shpLocation.getId());
List<ShpLocation> shpLocationStateLists = shpLocationDao.queryNodes(shpLocationstate);//根据id查省
for (ShpLocation shpLocation1 : shpLocationStateLists) {
shpLocationState = new ShpLocationState();
shpLocationState.setId(shpLocation1.getId());
shpLocationState.setPid(shpLocation1.getPid());
shpLocationState.setsName(shpLocation1.getsName());
shpLocationState.setNamePinyin(shpLocation1.getNamePinyin());
shpLocationState.setNameEn(shpLocation1.getNameEn());
shpLocationStateList.add(shpLocationState);
/*****************以上为省*****************/
ShpLocation shpLocationCity = new ShpLocation();
shpLocationCity.setId(shpLocation1.getId());
System.out.println(shpLocation1.getPid());
List<ShpLocation> shpLocationCityLists = shpLocationDao.queryNodes(shpLocationCity);//根据id查市
ShpLocationCity shpLocationCitys = null;
List<ShpLocationCity> shpLocationCityList = new ArrayList<ShpLocationCity>();
for (ShpLocation shpLocation2 : shpLocationCityLists) {
shpLocationCitys = new ShpLocationCity();
shpLocationCitys.setId(shpLocation2.getId());
shpLocationCitys.setPid(shpLocation2.getPid());
shpLocationCitys.setsName(shpLocation2.getsName());
shpLocationCitys.setNamePinyin(shpLocation2.getNamePinyin());
shpLocationCitys.setNameEn(shpLocation2.getNameEn());
shpLocationCityList.add(shpLocationCitys);
}
shpLocationState.setCityList(shpLocationCityList);
}
shpLocationYSVo.setStateList(shpLocationStateList);
}
}
return shpLocationYSVoList;
}

<!--查询国家下的州/省 市-->
<select id="queryNodes" resultMap="BaseShpLocationResultMap" parameterType="com.yryz.qsource.modules.shplocation.entity.ShpLocation">
SELECT
<include refid="Base_Shp_Location_Column_List"/>
FROM qsource_shp_location
<where>
1=1
<if test="id != null">
AND pid=#{id,jdbcType=INTEGER}
</if>
ORDER BY name_en ASC
</where>
</select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值