背景说明
需求开发过程中,经常涉及行政区划,这里提供一种获取相对权威的行政区划方案。
解决方案
数据来源
打开浏览器访问官方网址: http://202.108.98.30/map
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XyaiyjqY-1655307001424)(https://mingxun-image.oss-cn-hangzhou.aliyuncs.com/upic/2022/06-15/AIbZaY.png)]
接口检查
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k3zwbiSh-1655307001427)(https://mingxun-image.oss-cn-hangzhou.aliyuncs.com/upic/2022/06-15/vWf0dt.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BhJStLs4-1655307001428)(https://mingxun-image.oss-cn-hangzhou.aliyuncs.com/upic/2022/06-15/odB0Ge.png)]
初始数据
选择网络,CTRL+F全局搜索关键字,可以看到这里有省的初始数据。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PLkA41Pj-1655307001429)(https://mingxun-image.oss-cn-hangzhou.aliyuncs.com/upic/2022/06-15/image-20220615222122354.png)]
接口调用
public class TestMain {
public static String trimBrackets(String input){
int index= input.indexOf("(");
if(index != -1){
return input.substring(0,index);
}
return input;
}
public static void main(String[] args) {
RestTemplate template = new RestTemplate();
template.getMessageConverters().set(1,new StringHttpMessageConverter(Charset.forName("UTF-8")));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/x-www-form-urlencoded; charset=UTF-8"));
headers.add(HttpHeaders.ACCEPT_CHARSET,"UTF-8");
headers.add(HttpHeaders.ACCEPT,MediaType.APPLICATION_JSON_VALUE);
MultiValueMap<String,String> valueMap = new LinkedMultiValueMap<>();
valueMap.add("shenji", "北京市(京)");
HttpEntity<MultiValueMap<String,String>> entity = new HttpEntity<>(valueMap,headers);
ResponseEntity<String> bodyEntity = template.postForEntity("http://202.108.98.30/selectJson", entity, String.class);
System.out.println(bodyEntity.getBody());
}
}
通过省查询下级时,传入参数shenji
通过市查询下级时,传入参数diji
版权声明:本文为hanlongjielove原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。