获取最新得省市区得方法

用的是高德地图api

行政区域查询-API文档-开发指南-Web服务 API | 高德地图API

之后代码

@RequestMapping(value = "/setPro", method = RequestMethod.GET)
	 public void setPro(){
		 String json = HttpUtil.get("https://restapi.amap.com/v3/config/district?subdistrict=3&key=APIkey&extensions=base");
		 Result1 result = JSON.parseObject(json, Result1.class);
		 //省市区
		 List districts = result.getDistricts().get(0).getDistricts();
		 for (District1 district : districts) {
			 SysCategory sysCategory = new SysCategory();
			 sysCategory.setPid("0");
			 sysCategory.setCode(district.getAdcode());
			 sysCategory.setName(district.getName());
			 sysCategory.setHasChild(district.getDistricts().size()>0?district.getDistricts().size()+"":"");
			 sysCategoryService.addSysCategory(sysCategory);
			 insertChild(sysCategory,district);

		 }
	 }
private void insertChild(SysCategory sysCategory1,District1 district) {
		 List districts = district.getDistricts();
		 if(!CollectionUtils.isEmpty(districts)){
			 for (District1 district1 : districts) {
				 SysCategory sysCategory = new SysCategory();
				 sysCategory.setPid(sysCategory1.getId());
				 sysCategory.setCode(district1.getAdcode());
				 sysCategory.setName(district1.getName());
				 sysCategory.setHasChild(district1.getDistricts().size()>0?district1.getDistricts().size()+"":"");
				 sysCategoryService.addSysCategory(sysCategory);
				 insertChild(sysCategory,district1);
			 }
		 }
	 }
@Data
class Result1{
	private String status;
	private String info ;
	private List districts;
}

@Data
class District1{
	String adcode;
	String name;
	String level;
	List districts;
}
@Data
@TableName("sys_category")
public class SysCategory implements Serializable {
    private static final long serialVersionUID = 1L;

	/**主键*/
	@TableId(type = IdType.ID_WORKER_STR)
	private String id;
	/**父级节点*/
	@Excel(name = "父级节点", width = 15)
	private String pid;
	/**类型名称*/
	@Excel(name = "类型名称", width = 15)
	private String name;
	/**类型编码*/
	@Excel(name = "类型编码", width = 15)
	private String code;
	/**创建人*/
	@Excel(name = "创建人", width = 15)
	private String createBy;
	/**创建日期*/
	@Excel(name = "创建日期", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private java.util.Date createTime;
	/**更新人*/
	@Excel(name = "更新人", width = 15)
	private String updateBy;
	/**更新日期*/
	@Excel(name = "更新日期", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private java.util.Date updateTime;
	/**所属部门*/
	@Excel(name = "所属部门", width = 15)
	private String sysOrgCode;
	/**是否有子节点*/
	@Excel(name = "是否有子节点", width = 15)
	private String hasChild;
}

不需要得代码 自己去掉就行,结合自己得省市区表 可以对应插入

你可能感兴趣的:(jeecg)