Пример #1
0
  @RequestMapping(value = "/getCommentList")
  public void getCommentList(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    int page = Integer.parseInt(request.getParameter("page"));
    List<TComment> comments = commentService.getComment(page, 10);

    JSONArray commentJsonArray = new JSONArray();
    for (int i = 0; i < comments.size(); i++) {
      JSONObject commentJson = new JSONObject();
      TComment comment = comments.get(i);
      commentJson.put("Comment_ID", comment.getComment_ID());
      commentJson.put("Comment_Person_Name", comment.getComment_Person_Name());
      commentJson.put("Comment_Content", comment.getComment_Content());
      commentJson.put("Comment_ArticleTitle", comment.getComment_ArticleTitle());

      commentJsonArray.add(commentJson);
    }

    // 3.返回添加状态信息
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("success", "1");
    jsonObject.put("msg", "获取评论列表成功");
    jsonObject.put("data", commentJsonArray);

    response.setContentType("text/html;charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print(jsonObject);
  }
Пример #2
0
  // 生成修改评论的评论html代码
  public String generateAdminCommentUpdateHtml(List<TComment> comments) {
    String listHtml = "";
    int size = comments.size();
    for (int i = 0; i < size; i++) {
      TComment comment = comments.get(i);
      String content = comment.getComment_Content();
      if (content.length() > 20) {
        content = content.substring(0, 16) + "...";
      }
      String item = "";

      item += "<tr id='" + comment.getComment_ID() + "' class='noteItem'>";
      item += "	<td>" + comment.getComment_ID() + "</td>";
      item += "	<td>" + comment.getComment_Person_Name() + "</td>";
      item += "	<td title=" + comment.getComment_Content() + ">" + content + "</td>";
      item += "	<td>" + comment.getComment_ArticleTitle() + "</td>";
      item += "	<td>";
      item +=
          "		<a class='delete' onclick='update("
              + comment.getComment_ID()
              + ")' href='javascript:void(0)'>修改</a>";
      item += "	</td>";
      item += "</tr>";

      listHtml += item;
    }
    return listHtml;
  }
Пример #3
0
  // 生成删除评论的评论html代码
  public String generateAdminCommentDelHtml(List<TComment> comments) {
    String listHtml = "";
    int size = comments.size();
    for (int i = 0; i < size; i++) {
      TComment comment = comments.get(i);
      String content = comment.getComment_Content();
      if (content.length() > 20) {
        content = content.substring(0, 13) + "...";
      }
      String item = "";

      item += "<tr id='" + comment.getComment_ID() + "' class='noteItem'>";
      item += "	<td>";
      item += "		<div class='checker'>";
      item += "			<span>";
      item += "				<input class='checkboxes' type='checkbox' value='1'>";
      item += "			</span>";
      item += "		</div>";
      item += "	</td>";
      item += "	<td>" + comment.getComment_ID() + "</td>";
      item += "	<td>" + comment.getComment_Person_Name() + "</td>";
      item += "	<td title=" + comment.getComment_Content() + ">" + content + "</td>";
      item += "	<td>" + comment.getComment_ArticleTitle() + "</td>";
      item += "	<td>";
      item +=
          "		<a class='delete' onclick='oneDel("
              + comment.getComment_ID()
              + ")' href='javascript:void(0)'>删除</a>";
      item += "	</td>";
      item += "</tr>";

      listHtml += item;
    }
    return listHtml;
  }
Пример #4
0
 // 生成评论列表html代码
 public String generateNewCommentHtml(List<TComment> comments) {
   String sortHtml = "";
   if (comments == null) {
     return sortHtml;
   }
   int size = comments.size();
   for (int i = 0; i < size; i++) {
     TComment comment = comments.get(i);
     // 如果是对关于我页面发表的评论,链接地址要更改
     if (comment.getComment_ArticleID() == 999999) {
       String item = "";
       item += "<p>";
       item += "	<span>" + comment.getComment_Person_Name() + "</span><br/>";
       item +=
           "	<span>对 : </span><a href='/doit/me' target='_blank'>"
               + comment.getComment_ArticleTitle()
               + "</a><br/>";
       item +=
           "	<span>评论 : </span><a href='/doit/show' target='_blank'>"
               + comment.getComment_Content()
               + "</a>";
       item += "</p>";
       sortHtml += item;
     } else {
       String item = "";
       item += "<p>";
       item += "	<span>" + comment.getComment_Person_Name() + "</span><br/>";
       item +=
           "	<span>对 : </span><a href='/doit/show/"
               + comment.getComment_ArticleID()
               + "' target='_blank'>"
               + comment.getComment_ArticleTitle()
               + "</a><br/>";
       item +=
           "	<span>评论 : </span><a href='/doit/show/"
               + comment.getComment_ArticleID()
               + "' target='_blank'>"
               + comment.getComment_Content()
               + "</a>";
       item += "</p>";
       sortHtml += item;
     }
   }
   return sortHtml;
 }
Пример #5
0
  @RequestMapping(value = "/delComment")
  public void delComment(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    String selectId = request.getParameter("selectId");

    for (int i = 0; i < selectId.split(";").length; i++) {
      TComment comment = new TComment();
      comment.setComment_ID(Integer.parseInt(selectId.split(";")[i]));
      commentService.delete(comment);
    }

    // 3.返回添加状态信息
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("success", "1");
    jsonObject.put("msg", "删除评论成功");

    response.setContentType("text/html;charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print(jsonObject);
  }
Пример #6
0
  @RequestMapping(value = "/getComment")
  public void getComment(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    int selectId = Integer.parseInt(request.getParameter("selectId"));

    // 1.根据评论id获取评论内容
    TComment comment = commentService.getCommentByID(selectId);
    String userName = comment.getComment_Person_Name();
    String content = comment.getComment_Content();

    // 3.返回添加状态信息
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("success", "1");
    jsonObject.put("msg", "获取评论成功");
    jsonObject.put("id", selectId);
    jsonObject.put("userName", userName);
    jsonObject.put("content", content);

    response.setContentType("text/html;charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print(jsonObject);
  }
Пример #7
0
  @RequestMapping(value = "/updateComment")
  public void updateComment(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    int id = Integer.parseInt(request.getParameter("id"));
    String userName =
        URLDecoder.decode(URLDecoder.decode(request.getParameter("userName"), "utf-8"), "utf-8");
    String email = "";
    String content =
        URLDecoder.decode(URLDecoder.decode(request.getParameter("content"), "utf-8"), "utf-8");
    String date = "";
    int articleID = 0;
    String articleTitle = "";
    int parentId = 0;

    // 首先取回需要修改的评论的数据
    TComment priComment = commentService.getCommentByID(id);
    email = priComment.getComment_Person_Email();
    date = priComment.getComment_Time();
    articleID = priComment.getComment_ArticleID();
    articleTitle = priComment.getComment_ArticleTitle();
    parentId = priComment.getParent_CommentID();

    // 1.修改评论数据
    TComment comment = new TComment();
    comment.setComment_ID(id);
    comment.setComment_Person_Name(userName);
    comment.setComment_Person_Email(email);
    comment.setComment_Content(content);
    comment.setComment_Time(date);
    comment.setComment_ArticleID(articleID);
    comment.setComment_ArticleTitle(articleTitle);
    comment.setParent_CommentID(parentId);
    commentService.update(comment);

    // 2.返回添加状态信息
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("success", "1");
    jsonObject.put("msg", "修改评论成功");

    response.setContentType("text/html;charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print(jsonObject);
  }
Пример #8
0
  @RequestMapping(value = "/addComment")
  public void addComment(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    String name =
        URLDecoder.decode(URLDecoder.decode(request.getParameter("name"), "utf-8"), "utf-8");
    String email =
        URLDecoder.decode(URLDecoder.decode(request.getParameter("email"), "utf-8"), "utf-8");
    String content =
        URLDecoder.decode(URLDecoder.decode(request.getParameter("content"), "utf-8"), "utf-8");
    String date = "";
    int articleID = Integer.parseInt(request.getParameter("articleID"));
    String articleTitle =
        URLDecoder.decode(
            URLDecoder.decode(request.getParameter("articleTitle"), "utf-8"), "utf-8");
    int fCommentID = Integer.parseInt(request.getParameter("fCommentID"));

    // 处理时间
    SimpleDateFormat pSMDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    date = pSMDate.format(new Date());

    // 1.添加评论数据
    TComment comment = new TComment();
    comment.setComment_Person_Name(name);
    comment.setComment_Person_Email(email);
    comment.setComment_Content(content);
    comment.setComment_Time(date);
    comment.setComment_ArticleID(articleID);
    comment.setComment_ArticleTitle(articleTitle);
    comment.setParent_CommentID(fCommentID);
    commentService.create(comment);

    // 2.获取当前添加评论的id
    int nowCommentID = 0;
    String nowCommentName = "";
    String nowCommentContent = "";
    String nowCommentTime = "";
    List<TComment> comments = commentService.getComment(0, 1);
    int size = comments.size();
    for (int i = 0; i < size; i++) {
      TComment nowComment = comments.get(i);
      nowCommentID = nowComment.getComment_ID();
      nowCommentName = nowComment.getComment_Person_Name();
      nowCommentContent = nowComment.getComment_Content();
      nowCommentTime = nowComment.getComment_Time();
    }

    // 3.返回添加状态信息
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("success", "1");
    jsonObject.put("nowCommentID", nowCommentID);
    jsonObject.put("nowCommentName", nowCommentName);
    jsonObject.put("nowCommentContent", nowCommentContent);
    jsonObject.put("nowCommentTime", nowCommentTime);
    jsonObject.put("msg", "添加评论成功");

    response.setContentType("text/html;charset=utf-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print(jsonObject);
  }