package com.postmodule.servlet;
import com.postmodule.bean.TbPost;
import com.postmodule.dao.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;
public class TbPostServlet extends HttpServlet{
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method")==null?"":request.getParameter("method");
if("add".equals(method)){
String postName=request.getParameter("postName");
String postMemo=request.getParameter("postMemo");
String createTime=request.getParameter("createTime");
if(new TbPostDAO().add(new TbPost(postName,postMemo,createTime))){
request.getSession().setAttribute("result", "添加成功");
}else{
request.getSession().setAttribute("result", "添加失败");
}
request.getSession(true).setAttribute("tbPostList",new TbPostDAO().getTbPostAll());
response.sendRedirect("PostModule/TbPostList.jsp");
}
if("del".equals(method)){
if(UtilDAO.delin("Tb_Post", "PostId", request.getParameter("delIds"))){
request.getSession().setAttribute("result", "删除成功");
}else{
request.getSession().setAttribute("result", "删除失败");
}
request.getSession(true).setAttribute("tbPostList",new TbPostDAO().getTbPostAll());
response.sendRedirect("PostModule/TbPostList.jsp");
}
if("edit".equals(method)){
int postId=Integer.parseInt(request.getParameter("postId"));
String postName=request.getParameter("postName");
String postMemo=request.getParameter("postMemo");
String createTime=request.getParameter("createTime");
if(new TbPostDAO().add(new TbPost(postId,postName,postMemo,createTime))){
request.getSession().setAttribute("result", "修改成功");
}else{
request.getSession().setAttribute("result", "修改失败");
}
request.getSession(true).setAttribute("tbPostList",new TbPostDAO().getTbPostAll());
response.sendRedirect("PostModule/TbPostList.jsp");
}
if ("list".equals(method)) {
request.getSession(true).setAttribute("tbPostList",new TbPostDAO().getTbPostAll());
response.sendRedirect("PostModule/TbPostList.jsp");
}
if ("listById".equals(method)) {
request.getSession(true).setAttribute("tbPost",new TbPostDAO().getTbPostByPostId(Integer.parseInt(request.getParameter("postId"))));
response.sendRedirect("PostModule/TbPostOperate.jsp");
}
if("showadd".equals(method)){
response.sendRedirect("PostModule/TbPostOperate.jsp");
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest(request, response);
}// end method doGet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest(request, response);
}// end method doPost
}