コード例 #1
0
  // 删除
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  @ResponseBody
  public Object del(String ids) {
    Map map = new HashMap();
    int result = 0;
    Collection collection = new ArrayList();
    for (String id : ids.split("&")) {
      List<ControlBaseInfo> controlBaseInfos =
          controlBaseInfoService.selectByBaseMer(Long.valueOf(id));

      if (controlBaseInfos.size() == 0) {
        result = baseMerService.deleteByPrimaryKey(Long.valueOf(id));
      } else {
        collection.addAll(controlBaseInfos);
      }
    }

    map.put("state", result);
    if (!collection.isEmpty()) {
      map.put(
          "controlBaseInfos",
          BeanUtil.getCollection2JSON(collection, "controlBaseInfos", "controlmername", true));
    }

    return map;
  }
コード例 #2
0
  // 列表页中返回json数据
  @RequestMapping("/jsonList")
  public Object jsonList(HttpServletRequest request, HttpServletResponse response) {
    int currentPage =
        request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
    if (currentPage <= 0) {
      currentPage = 1;
    }

    int pageSize =
        request.getParameter("rows") == null ? 10 : Integer.parseInt(request.getParameter("rows"));

    Map filter = getFilterMap(request);

    int currentResult = (currentPage - 1) * pageSize;

    PageInfo pageInfo = new PageInfo();
    pageInfo.setShowCount(pageSize);
    pageInfo.setCurrentResult(currentResult);
    pageInfo.setFilter(filter);
    pageInfo.setSortField("id");
    pageInfo.setOrder("asc");

    List<BaseMer> baseMers = baseMerService.selectListPage(pageInfo);

    if (pageInfo.getTotalResult() > 0) {
      Json json = new Json();
      json.add("total", pageInfo.getTotalResult());

      for (BaseMer baseMer : baseMers) {
        Json json_a = new Json();
        try {
          json_a.getObjectValue(baseMer, json_a);
        } catch (Exception e) {
          e.printStackTrace();
        }
        json.add("rows", json_a);
      }

      response.setContentType("application/json;charset=UTF-8");
      response.setCharacterEncoding("UTF-8");
      PrintWriter pw = null;
      try {
        pw = response.getWriter();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      pw.write(json.toString());
      pw.flush();
    }

    return null;
  }
コード例 #3
0
  // 验证是否已存在
  @RequestMapping(value = "/verifyOnly", method = RequestMethod.POST)
  @ResponseBody
  public Object verifyOnly(Long id, String type) {

    BaseMer createBaseMer = null;
    BaseMer updateBaseMer = null;

    if (id != null) {
      Map updateFilter = new HashMap();
      updateFilter.put("id", id);
      updateFilter.put("type", type);
      updateBaseMer = baseMerService.verifyOnly(updateFilter);
      if (updateBaseMer == null) {
        updateFilter.remove("id");
        updateBaseMer = baseMerService.verifyOnly(updateFilter);
      }

    } else {
      Map createFilter = new HashMap();
      createFilter.put("type", type);
      createBaseMer = baseMerService.verifyOnly(createFilter);
    }

    Map result = new HashMap();

    if (createBaseMer != null) {
      result.put("state", 1);
    } else if (updateBaseMer != null) {
      result.put("state", 1);
      result.put("id", updateBaseMer.getId());
    } else {
      result.put("state", 0);
    }

    return result;
  }
コード例 #4
0
 // 修改
 @RequestMapping(value = "/update", method = RequestMethod.POST)
 @ResponseBody
 public Object update(BaseMer baseMer) {
   baseMerService.updateByPrimaryKeySelective(baseMer);
   return baseMer;
 }
コード例 #5
0
 // 保存
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 @ResponseBody
 public Object save(BaseMer baseMer) {
   baseMerService.insert(baseMer);
   return baseMer;
 }
コード例 #6
0
  // 返回生成树需要的json
  @RequestMapping("/baseMerJsonTree")
  public Object baseMerJsonTree(HttpServletRequest request, HttpServletResponse response) {

    Map filter = getFilterMap(request);
    PageInfo pageInfo = new PageInfo();
    pageInfo.setShowCount(100);
    pageInfo.setCurrentResult(0);
    pageInfo.setFilter(filter);
    pageInfo.setSortField("id");
    pageInfo.setOrder("asc");

    List<BaseMer> baseMers = baseMerService.selectListPage(pageInfo);

    if (pageInfo.getTotalResult() > 0) {

      StringBuffer sbf = new StringBuffer("[");

      Json json = new Json();
      json.add("id", 1);
      json.add("text", "基质");

      Json person = new Json();
      person.add("id", 11);
      person.add("text", "人源基质");

      Json noPerson = new Json();
      noPerson.add("id", 12);
      noPerson.add("text", "非人源基质");

      for (BaseMer baseMer : baseMers) {
        if (baseMer.getSource().equals("人源基质")) {
          Json json_a = new Json();
          json_a.add("id", String.valueOf(baseMer.getId()));
          json_a.add("text", baseMer.getType());
          person.add("children", json_a);
        } else {
          Json json_b = new Json();
          json_b.add("id", String.valueOf(baseMer.getId()));
          json_b.add("text", baseMer.getType());
          noPerson.add("children", json_b);
        }
      }

      json.add("children", person);
      json.add("children", noPerson);

      sbf.append(json.toString());
      sbf.append("]");

      response.setContentType("application/json;charset=UTF-8");
      response.setCharacterEncoding("UTF-8");
      PrintWriter pw = null;
      try {
        pw = response.getWriter();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      pw.write(sbf.toString());
      pw.flush();
    }

    return null;
  }