Esempio n. 1
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);
  }
Esempio n. 2
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);
  }