// 生成修改评论的评论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; }
// 生成删除评论的评论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; }
@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); }
@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); }