@RequestMapping public ModelAndView findAllCities(String proId) { ModelAndView mv = new ModelAndView("area/city_list"); Province province = areaService.findProvince(new ObjectId(proId)); mv.addObject("province", province); mv.addObject("cityList", province.getCities()); return mv; }
@RequestMapping @ResponseBody public List<Province> findProvinces() { List<Province> provinces = areaService.findAllProvince(); for (Province p : provinces) { p.setCities(null); } return provinces; }
@Override public Province createProvince(String name) { if (StringUtil.isEmpty(name)) { return null; } Province province = new Province(); province.setName(name); dao.save(province); return province; }
@ResponseBody @RequestMapping public List<City> findCities(String proId) { Province province = areaService.findProvince(new ObjectId(proId)); List<City> cities = new ArrayList<City>(); for (City city : province.getCities()) { city.setProvince(null); city.setAreas(null); cities.add(city); } return cities; }
@Override public City createCity(ObjectId proId, String name) { if (proId == null || StringUtil.isEmpty(name)) { return null; } Province province = findProvince(proId); if (province == null) { return null; } City city = new City(); city.setName(name); city.setProvince(province); dao.save(city); province.getCities().add(city); dao.save(province); return city; }