1:下载对应的json
2 声明实体类去接收
3编写Controller方法 (也可以导入json文件 这种需要转化一下 具体百度)
5.具体代码如下
private JSONObjectaddAddress(@Valid @RequestBody List<Addre> list) {
long startTime = System.currentTimeMillis();
list.forEach(addre ->{
Address address =new Address();
address.setAddressName(addre.getName());
address.setAddressCode(addre.getCode());
address.setAddressParentCode("0");
address.setLevel("1");
addressService.addAddress(address);
//判断是否有二级
for (Addre child : addre.getChildren()) {
Address aa =new Address();
aa.setAddressName(child.getName());
aa.setAddressCode(child.getCode());
aa.setAddressParentCode(addre.getCode());
aa.setLevel("2");
addressService.addAddress(aa);
for (Addre child1 : child.getChildren()) {
Address aaa =new Address();
aaa.setAddressName(child1.getName());
aaa.setAddressCode(child1.getCode());
aaa.setAddressParentCode(child.getCode());
aaa.setLevel("3");
addressService.addAddress(aaa);
for (Addre child2 : child1.getChildren()) {
Address aa4 =new Address();
aa4.setAddressName(child2.getName());
aa4.setAddressCode(child2.getCode());
aa4.setAddressParentCode(child1.getCode());
aa4.setLevel("4");
addressService.addAddress(aa4);
}
}
}
});
System.out.println("查询耗时:" +(System.currentTimeMillis() - startTime) +"");
return ResponseStatus.success();
}
注: 土豪可以调第三方接口(付费的),
免费下载json文件直通车:链接:https://pan.baidu.com/s/1D5xUvwZnYz2xggF2LnsArQ 提取码:l340