package com.yeshi.buwan.controller.admin.api; import java.io.PrintWriter; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.yeshi.buwan.domain.Comment2; import com.yeshi.buwan.service.imp.CommentService; import com.yeshi.buwan.util.Constant; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.web.tag.PageEntity; import net.sf.json.JSONObject; @Controller @RequestMapping("admin/new/api/comment") public class CommentController { @Resource private CommentService commentService; /** * 关键字搜索列表 * * @return */ @RequestMapping(value = "/commentList", method = RequestMethod.POST) public void specialList(int pageIndex, String key, PrintWriter out) { if (pageIndex == 0) pageIndex = 1; key = StringUtil.isNullOrEmpty(key) ? "" : key; List list = commentService.getCommentList(key, pageIndex); long count = commentService.getCommentCount(key); PageEntity pe = new PageEntity(); pe.setPageIndex(pageIndex); pe.setPageSize(Constant.pageCount); Map map = new HashMap(); map.put("key", key); pe.setParams(map); pe.setTotalCount((int) count); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); JSONObject root = new JSONObject(); root.put("code", "0"); root.put("pageEntity", pe); root.put("commentList", gson.toJson(list)); System.out.println(root.toString()); out.print(root); return; } @RequestMapping(value = "/delComment", method = RequestMethod.POST) public void delSpecial(String ids, PrintWriter out) { if (ids != null && !"".equals(ids.trim())) { String[] idArr = ids.split(","); for (String id : idArr) { commentService.deleteComment(id); } out.print("yes"); } } }