@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 + "]不存在"; } }
@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(); }