Пример #1
0
  /**
   * 获取内容列表. @Title: getArticleList @Description: TODO(这里用一句话描述这个方法的作用)
   *
   * @author Sophie
   * @param request
   * @param response
   * @return
   * @throws Exception
   * @throws
   */
  @RequestMapping({"getArticleList"})
  public ModelAndView getArticleList(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    response.setContentType("application/json;charset=utf-8");
    String msg = "";
    String isOK = "true";
    PrintWriter pw = response.getWriter();
    JsonResultVO jsonRes = new JsonResultVO();
    // String title = request.getParameter("title");//标题(模糊匹配)
    String codeModule = request.getParameter("codeModule"); // 模块
    // if(codeModule==null || "".equals(codeModule)){
    // codeModule="1000";
    // }
    TJewContent content = new TJewContent();
    if (codeModule != null && !"".equals(codeModule)) {
      content.setCodeModule(codeModule);
    }
    try {
      List<TJewContent> articleList = cmsService.getArticleList(content);

      jsonRes.setJsonData(articleList);
    } catch (Exception e) {
      isOK = "false";
      msg = "获取文章列表异常";
      logger.error("CmsController.getArticleList error", e);
      e.printStackTrace();
    }
    jsonRes.setIsOK(isOK);
    jsonRes.setMsg(msg);
    pw.write(JSON.toJSONString(jsonRes));
    return null;
  }
Пример #2
0
  /**
   * 添加(编辑)文章. @Title: addOrEditArticle @Description: TODO(这里用一句话描述这个方法的作用)
   *
   * @author Sophie
   * @param request
   * @param response
   * @return
   * @throws Exception
   * @throws
   */
  @RequestMapping({"addOrEditArticle"})
  public ModelAndView addOrEditArticle(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    response.setContentType("application/json;charset=utf-8");
    String msg = "";
    String isOK = "true";
    PrintWriter pw = response.getWriter();
    JsonResultVO jsonRes = new JsonResultVO();
    String idStr = request.getParameter("id");
    String title = request.getParameter("title"); // 标题(模糊匹配)
    String codeModule = request.getParameter("codeModule"); // 模块
    String content = request.getParameter("content"); // 编辑内容
    String preImg = request.getParameter("preImg"); // 预览图,用于产品模块
    String homeImg = request.getParameter("homeImg"); // 预览图,用于产品模块
    String smallImg = request.getParameter("smallImg");

    content = content.replaceAll("&lt;", "<");
    content = content.replaceAll("&gt;", ">");
    content = content.replaceAll("\n", "");
    content = content.replaceAll("&amp;", "&");
    content = content.replaceAll("&quot;", "\"");
    content = content.replaceAll("&nbsp;", " ");
    content = content.replaceAll("&copy;", "");

    TJewContent jewContent = new TJewContent();
    if (idStr != null && !"".equals(idStr)) {
      jewContent.setId(Integer.parseInt(idStr));
    }
    jewContent.setTitle(title);
    jewContent.setContent(content);
    jewContent.setCreateTime(new Date());
    jewContent.setCodeModule(codeModule);

    if (preImg != null && !"".equals(preImg)) {
      jewContent.setPreImg(preImg);
    }

    if (homeImg != null && !"".equals(homeImg)) {
      jewContent.setHomeImg(homeImg);
    }

    if (smallImg != null && !"".equals(smallImg)) {
      jewContent.setSmallImg(smallImg);
    }

    try {
      // 新增或添加
      cmsService.saveOrUpdate(jewContent);

    } catch (Exception e) {
      isOK = "false";
      msg = "添加或修改文章报错";
      logger.error("CmsController.addOrEditArticle error", e);
      e.printStackTrace();
    }
    jsonRes.setIsOK(isOK);
    jsonRes.setMsg(msg);
    pw.write(JSON.toJSONString(jsonRes));
    return null;
  }