行业、地区返回json数据

国家省市区三张表,给前台返回json是数组套数组形式 /** * 地区 * @param request * @param response * @param parentId * @param commonAreaDto * @return */

//查询出所有的省
//根据省的id查询所有的市,放到省下面
//根据市的id查询所有的区,放到区下面

@RequestMapping(value = "/allList")
public Result<List<RegionNationDto>> allList() {
	Result<List<RegionNationDto>> rs = new Result<List<RegionNationDto>>();
	//查询所有国家
	List<RegionNationDto> nation = nationService.findAll();
	for (int i = 0; i < nation.size(); i++) {
		RegionNationDto nationDto = nation.get(i);
		Long nationId = nationDto.getNationId();
		//查询所有省列表
		List<RegionProvinceDto> provinceDtos = provinceService.findById(nationId);
		nationDto.setProvinceDtos(provinceDtos);
		
		for (int j = 0; j < provinceDtos.size(); j++) {
			RegionProvinceDto provinceDto = provinceDtos.get(j);
			Long provinceId = provinceDto.getCodeId();
			//根据省Id查市列表
			List<RegionCityDto> cityDtos =cityService.findById(provinceId);
			provinceDto.setCityDtos(cityDtos);
			for (int k = 0; k < cityDtos.size(); k++) {
				RegionCityDto cityDto = cityDtos.get(k);
				Long cityId = cityDto.getCityId();
				//根据市id查区列表
				List<RegionAreaDto> areaDtos = areaService.findById(cityId);
				cityDto.setAreaDtos(areaDtos);
			}
		}
	}
	
	rs.setData(nation);
	return rs;
}

效果: { "code": 1, "data": [ { "nationId": 0, "nationName": "中国", "provinceDtos": [ { "cityDtos": [ { "areaDtos": [ { "areaId": 110101, "areaName": "东城区", "cityId": 1101 } ], "cityId": 1101, "cityName": "北京市辖", "provinceId": 11 }, { "areaDtos": [ { "areaId": 110224, "areaName": "大兴县", "cityId": 1102 } ], "cityId": 1102, "cityName": "北京县辖", "provinceId": 11 } ], "codeId": 11, "nationId": 0, "provinceName": "北京" } } ] }

行业和国家一样: /**

  • 行业接口

  • @author Arvin.liu

  • @date 2018年6月13日 */ @RestController @RequestMapping(value = "/app/industry") public class AppIndustryController { private Logger logger = LoggerFactory.getLogger(getClass());

    @Resource private IndustryService industryService; @Resource private IndustryTwoService industryTwoService; /**

    • 查询所有行业
    • @param userId
    • @param pageNum
    • @param pageSize
    • @return */ @RequestMapping(value = "/industryList") public Result<List<IndustryAllDto>> industryList() { Result<List<IndustryAllDto>> rs = new Result<List<IndustryAllDto>>(); ArrayList<IndustryAllDto> newlist = new ArrayList<IndustryAllDto>(); List<IndustryDto> onedto = industryService.findAll(); for (int i = 0; i < onedto.size(); i++) { IndustryAllDto allDto = new IndustryAllDto(); IndustryDto industryDto = onedto.get(i); Long oneId = industryDto.getId(); List<IndustryTwoDto> twodto =industryTwoService.findById(oneId); allDto.setId(oneId); allDto.setName(industryDto.getName()); allDto.setIndustryTwoDto(twodto); newlist.add(allDto); } rs.setData(newlist); return rs; } } 效果: { "code": 1, "data": [ { "id": 1, "industryTwoDto": [ { "detailName": "互联网/电子商务", "id": 1, "industry": 1 }, { "detailName": "计算机软件", "id": 2, "industry": 1 }, { "detailName": "IT服务(系统/数据/维护)", "id": 3, "industry": 1 }, { "detailName": "电子技术/半导体/集成电路", "id": 4, "industry": 1 }, { "detailName": "计算机硬件", "id": 5, "industry": 1 }, { "detailName": "通信/电信/网路设备", "id": 6, "industry": 1 }, { "detailName": "通信/电信运营、增值服务", "id": 7, "industry": 1 }, { "detailName": "网络游戏", "id": 8, "industry": 1 } ], "name": "IT|通信电子|互联网" }, { "id": 2, "industryTwoDto": [ { "detailName": "基金/证券/期货/投资", "id": 9, "industry": 2 }, { "detailName": "保险", "id": 10, "industry": 2 }, { "detailName": "银行", "id": 11, "industry": 2 }, { "detailName": "信托/担保/拍卖/典当", "id": 12, "industry": 2 } ], "name": "金融业" }, { "id": 3, "industryTwoDto": [ { "detailName": "房地产/建筑/建材/工程", "id": 13, "industry": 3 }, { "detailName": "家居/室内设计/装饰装潢", "id": 14, "industry": 3 }, { "detailName": "物业管理/商业中心", "id": 15, "industry": 3 } ], "name": "房地产|建筑业" }, { "id": 4, "industryTwoDto": [ { "detailName": "专业服务/咨询", "id": 16, "industry": 4 }, { "detailName": "广告/会展/公关", "id": 17, "industry": 4 }, { "detailName": "中介服务", "id": 18, "industry": 4 }, { "detailName": "检验/检测/认证", "id": 19, "industry": 4 }, { "detailName": "外包服务", "id": 20, "industry": 4 } ], "name": "商业服务" }, { "id": 5, "industryTwoDto": [ { "detailName": "快速消费品", "id": 21, "industry": 5 }, { "detailName": "耐用消费品", "id": 22, "industry": 5 }, { "detailName": "贸易/进出口", "id": 23, "industry": 5 }, { "detailName": "零售/批发", "id": 24, "industry": 5 }, { "detailName": "租赁服务", "id": 25, "industry": 5 } ], "name": "贸易|批发|零售|租赁业" }, { "id": 6, "industryTwoDto": [ { "detailName": "教育/培训/院校", "id": 26, "industry": 6 }, { "detailName": "礼品/工艺美术/奢饰品", "id": 27, "industry": 6 } ], "name": "文体教育|工艺美术" }, { "id": 7, "industryTwoDto": [ { "detailName": "汽车/摩托车", "id": 28, "industry": 7 }, { "detailName": "大型设备/机电设备/重工业", "id": 29, "industry": 7 }, { "detailName": "加工制造(原料加工/模具)", "id": 30, "industry": 7 }, { "detailName": "仪器仪表及工业自动化", "id": 31, "industry": 7 }, { "detailName": "印刷/包装/造纸", "id": 32, "industry": 7 }, { "detailName": "办公用品及设备", "id": 33, "industry": 7 }, { "detailName": "医药/生物工程", "id": 34, "industry": 7 }, { "detailName": "医疗设备/器械", "id": 35, "industry": 7 }, { "detailName": "航空/航天研究与制造", "id": 36, "industry": 7 } ], "name": "生产|加工|制造" }, { "id": 8, "industryTwoDto": [ { "detailName": "交通/运输", "id": 37, "industry": 8 }, { "detailName": "物流/仓储", "id": 38, "industry": 8 } ], "name": "交通|运输|物流|仓储" }, { "id": 9, "industryTwoDto": [ { "detailName": "医疗/护理/美容/保健/卫生", "id": 39, "industry": 9 }, { "detailName": "酒店/餐饮", "id": 40, "industry": 9 }, { "detailName": "旅游/度假", "id": 41, "industry": 9 } ], "name": "服务业" }, { "id": 10, "industryTwoDto": [ { "detailName": "媒体/出版/影视/文化传播", "id": 42, "industry": 10 }, { "detailName": "娱乐/体育/休闲", "id": 43, "industry": 10 } ], "name": "文化|传媒|娱乐|体育" }, { "id": 11, "industryTwoDto": [ { "detailName": "能源/矿产/采掘/冶炼", "id": 44, "industry": 11 }, { "detailName": "石油/石化/化工", "id": 45, "industry": 11 }, { "detailName": "电气/电力/水力", "id": 46, "industry": 11 }, { "detailName": "环保", "id": 47, "industry": 11 } ], "name": "能源|矿产|环保" }, { "id": 12, "industryTwoDto": [ { "detailName": "政府/公共事业/非盈利机构", "id": 48, "industry": 12 }, { "detailName": "学术/科研", "id": 49, "industry": 12 } ], "name": "政府|非盈利机构" }, { "id": 13, "industryTwoDto": [ { "detailName": "农/林/牧/渔", "id": 50, "industry": 13 }, { "detailName": "跨领域经营", "id": 51, "industry": 13 }, { "detailName": "其他", "id": 52, "industry": 13 } ], "name": "农|林牧|渔|其他" } ] }

转载于:https://my.oschina.net/u/3727427/blog/1842291

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值