首页>代码>SSM仿制Tenda路由器公司官方网站>/Tenda/src/controller/CommentsController.java
package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pojo.Comments;
import service.CommentsService;

@Controller
public class CommentsController {

	@Resource
	public CommentsService commentsService;
	
	//评论请求
	@RequestMapping("/commentsMan.html")
	public String commentsMan() {
		return "admin/comments_table";
	}
	
	//获取所有的评论
	@RequestMapping("/comments/getAllComments.html")
	public void getAllComments(@RequestParam(value="rows",required=false)Integer rows,
			@RequestParam(value="page",required=false)Integer page,
			HttpServletRequest request,
			@RequestParam(value="commentsName",required=false)String commentsName,
			@RequestParam(value="commentsProName",required=false)String commentsProName,
			HttpServletResponse response
			) throws Exception {
		response.setCharacterEncoding("utf-8");
		//传入map
		Map<String,Object> map = new HashMap<String,Object>();
		List<Comments> list = commentsService.getAllComments((page-1)*rows,rows,commentsName,commentsProName);
		map.put("total", commentsService.getAllCommentsTotal(commentsName,commentsProName));
		map.put("rows", list);
		String jsonString = tools.JSONTools.JSONMap(map);
		PrintWriter out = response.getWriter();
		out.write(jsonString);
		out.flush();
		out.close();
		
	}
	
	//评论的删除
	@RequestMapping("/deleteComments.html")
	public void deleteStudent(HttpServletRequest request,@RequestParam(value="pks",required=false)String pks[], HttpServletResponse response) throws Exception{
		//这里判断一下,传来的数组是空的,则返回删除错误,不为空则遍历开始删除
		response.setCharacterEncoding("utf-8");
		String data ="删除失败";
		if(pks.length!=0){
			int numSuccess =0;
			int numFail=0;
			for (String commentsId : pks) {
				boolean delete = commentsService.deleteComments(commentsId);
				if(delete) {
					numSuccess+=1;
				}else {
					numFail+=1;
				}
			}
			data="您选择了"+pks.length+"条数据。"+"删除成功:"+numSuccess+"条"+",失败:"+numFail;
		}
		PrintWriter out = response.getWriter();
		out.write(data);
		out.flush();
		out.close();
	}
}
最近下载更多
jskdbf  LV7 2022年6月11日
lilong007  LV20 2021年12月22日
success1011  LV8 2021年12月15日
双方各何必呢  LV13 2021年12月10日
桐姥爷无敌呀  LV4 2021年11月15日
dxadsaf  LV6 2021年10月7日
15167672991  LV6 2021年6月29日
凉筱123  LV2 2021年5月29日
xiaoxiexie  LV13 2021年4月26日
wangtao1111111111  LV15 2021年2月3日
最近浏览更多
1134116035 2月28日
暂无贡献等级
heshao  LV2 2月7日
PSSDZH  LV3 2023年12月26日
zhaozhiqi  LV5 2023年10月10日
yeyuuu  LV6 2023年5月18日
箜canasd  LV5 2023年4月3日
微信网友_6248713511227392  LV11 2022年12月5日
邬松桥  LV11 2022年11月16日
abcdljw  LV20 2022年11月16日
1792461859  LV2 2022年11月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友