Ejemplo n.º 1
0
  @ResponseBody
  @RequestMapping(value = "modify", method = RequestMethod.POST)
  public String modify(HttpServletRequest request, HttpServletResponse response) {
    JSONObject json = FormRequestUtil.parseData(request);

    Object _id = json.get("id");
    if (_id == null) {
      response.setStatus(HttpStatus.BAD_REQUEST.value());
      return "媒体Id不能为空";
    }

    int id = Integer.parseInt(_id.toString());
    Media media = service.getById(id);
    if (media != null) {
      String desc = (String) json.get("desc");
      String logourl = (String) json.get("logourl");
      String siteurl = (String) json.get("siteurl");
      if (StringUtils.isNotBlank(desc)) {
        media.setDesc(desc);
      }
      if (StringUtils.isNotBlank(logourl)) {
        media.setLogourl(logourl);
      }
      if (StringUtils.isNotBlank(siteurl)) {
        media.setSiteurl(siteurl);
      }

      return media.toJson().toJSONString();
    } else {
      response.setStatus(HttpStatus.NOT_FOUND.value());
      return "媒体[id=" + _id + "]不存在";
    }
  }
Ejemplo n.º 2
0
  @RequestMapping("list")
  public ModelAndView list() {
    List<Media> list = service.query(0);
    JSONArray array = new JSONArray();
    for (Media ch : list) {
      array.add(ch.toJson());
    }

    return ViewUtil.renderListView("_media.jsp", array.toJSONString());
  }
Ejemplo n.º 3
0
  @ResponseBody
  @RequestMapping(value = "delete", method = RequestMethod.POST)
  public String delete(HttpServletRequest request, HttpServletResponse response) {
    JSONObject json = FormRequestUtil.parseData(request);

    Object _id = json.get("id");
    if (_id == null) {
      response.setStatus(HttpStatus.BAD_REQUEST.value());
      return "媒体Id不能为空";
    }

    int id = Integer.parseInt(_id.toString());
    Media media = service.getById(id);
    if (media != null) {
      service.delete(id);
      return media.toJson().toJSONString();
    } else {
      response.setStatus(HttpStatus.NOT_FOUND.value());
      return "媒体[id=" + _id + "]不存在";
    }
  }
Ejemplo n.º 4
0
  @ResponseBody
  @RequestMapping(value = "create", method = RequestMethod.POST)
  public String add(HttpServletRequest request, HttpServletResponse response) {

    JSONObject json = FormRequestUtil.parseData(request);
    String name = (String) json.get("desc");
    if (name == null) {
      response.setStatus(HttpStatus.BAD_REQUEST.value());
      return "媒体名不能为空";
    }
    String siteUrl = (String) json.get("siteurl");
    String logoUrl = (String) json.get("logourl");

    Media media = new Media();
    media.setDesc(name);
    media.setSiteurl(siteUrl);
    media.setLogourl(logoUrl);
    service.insert(media);

    Media ret = service.findByName(name);
    return ret.toJson().toJSONString();
  }