public String multiDel() { String[] ids = getRequest().getParameterValues("ids"); if (ids != null) { for (String id : ids) { NewsComment delComment = (NewsComment) this.newsCommentService.get(new Long(id)); News news = delComment.getNews(); if (news.getReplyCounts().intValue() > 1) { news.setReplyCounts(Integer.valueOf(news.getReplyCounts().intValue() - 1)); } this.newsService.save(news); this.newsCommentService.remove(new Long(id)); } } this.jsonString = "{success:true}"; return "success"; }
public String list() { QueryFilter filter = new QueryFilter(getRequest()); String start = getRequest().getParameter("start"); List<NewsComment> list = this.newsCommentService.getAll(filter); Gson gson = new Gson(); SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); StringBuffer buff = new StringBuffer("{success:true,'totalCounts':") .append(filter.getPagingBean().getTotalItems()) .append(",result:["); for (NewsComment newsComment : list) { buff.append("{commentId:'") .append(newsComment.getCommentId()) .append("',subject:") .append(gson.toJson(newsComment.getNews().getSubject())) .append(",content:") .append(gson.toJson(newsComment.getContent())) .append(",createtime:'") .append(simpleDate.format(newsComment.getCreatetime())) .append("',fullname:'") .append(newsComment.getFullname()) .append("',start:'") .append(start) .append("'},"); } if (list.size() > 0) { buff.deleteCharAt(buff.length() - 1); } buff.append("]}"); this.jsonString = buff.toString(); return "success"; }