/**
  * 查询相应的地区
  *
  * @param id
  * @return
  */
 @RequestMapping(value = "/{id}.json", method = RequestMethod.GET)
 @ResponseBody
 public JSONResult get(@PathVariable String id) {
   JSONResult result = new JSONResult();
   try {
     Area area = areaService.findEntityBykey(id);
     result.setResult(true);
     result.setData(area);
   } catch (Exception e) {
     result.setResult(false);
     result.setErrorDesc("出现异常:" + e.getMessage());
   }
   return result;
 }
 /**
  * 删除 地区
  *
  * @param id
  * @return
  */
 @RequestMapping(value = "/{id}.json", method = RequestMethod.DELETE)
 @ResponseBody
 public JSONResult delete(@PathVariable String id) {
   JSONResult result = new JSONResult();
   try {
     areaService.deleteEntityByKey(id);
     result.setResult(true);
     result.setData(null);
   } catch (Exception e) {
     result.setResult(false);
     result.setErrorDesc("出现异常:" + e.getMessage());
   }
   return result;
 }
 /**
  * 查询所有地区
  *
  * @return
  */
 @RequestMapping(value = "/list.json", method = RequestMethod.GET)
 @ResponseBody
 public JSONResult list() {
   JSONResult result = new JSONResult();
   try {
     List<Area> areas = areaService.getAllEntity();
     result.setResult(true);
     result.setData(areas);
   } catch (Exception e) {
     result.setResult(false);
     result.setErrorDesc("出现异常:" + e.getMessage());
   }
   return result;
 }
 /**
  * 添加或修改 地区
  *
  * @param id
  * @return
  */
 @RequestMapping(value = "/{id}.json", method = RequestMethod.POST)
 @ResponseBody
 public JSONResult addOrUpdate(@PathVariable String id, Area area) {
   JSONResult result = new JSONResult();
   try {
     area.setName(StringUtil.urlDecode(area.getName()));
     area.setCode(StringUtil.urlDecode(area.getCode()));
     area.setParentId(StringUtil.urlDecode(area.getParentId()));
     area.setRemark(StringUtil.decode(area.getRemark()));
     if (areaService.exists(id)) { // 数据库中已经存在
       areaService.updateEntity(area);
     } else {
       areaService.addEntity(area);
     }
     result.setResult(true);
     result.setData(area);
   } catch (Exception e) {
     result.setResult(false);
     result.setErrorDesc("出现异常:" + e.getMessage());
   }
   return result;
 }