package com.tbuserrolemiddlemodule.servlet;
import com.tbuserrolemiddlemodule.bean.TbUserRoleMiddle;
import com.tbuserrolemiddlemodule.dao.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;
public class TbUserRoleMiddleServlet 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)){
int userId=Integer.parseInt(request.getParameter("userId"));
int roleId=Integer.parseInt(request.getParameter("roleId"));
String createTime=request.getParameter("createTime");
if(new TbUserRoleMiddleDAO().add(new TbUserRoleMiddle(userId,roleId,createTime))){
request.getSession().setAttribute("result", "添加成功");
}else{
request.getSession().setAttribute("result", "添加失败");
}
request.getSession(true).setAttribute("tbUserRoleMiddleList",new TbUserRoleMiddleDAO().getTbUserRoleMiddleAll());
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleList.jsp");
}
if("del".equals(method)){
if(UtilDAO.delin("TbUserRoleMiddle", "UserRoleMiddleId", request.getParameter("delIds"))){
request.getSession().setAttribute("result", "删除成功");
}else{
request.getSession().setAttribute("result", "删除失败");
}
request.getSession(true).setAttribute("tbUserRoleMiddleList",new TbUserRoleMiddleDAO().getTbUserRoleMiddleAll());
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleList.jsp");
}
if("edit".equals(method)){
int userRoleMiddleId=Integer.parseInt(request.getParameter("userRoleMiddleId"));
int userId=Integer.parseInt(request.getParameter("userId"));
int roleId=Integer.parseInt(request.getParameter("roleId"));
String createTime=request.getParameter("createTime");
if(new TbUserRoleMiddleDAO().add(new TbUserRoleMiddle(userRoleMiddleId,userId,roleId,createTime))){
request.getSession().setAttribute("result", "修改成功");
}else{
request.getSession().setAttribute("result", "修改失败");
}
request.getSession(true).setAttribute("tbUserRoleMiddleList",new TbUserRoleMiddleDAO().getTbUserRoleMiddleAll());
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleList.jsp");
}
if ("list".equals(method)) {
request.getSession(true).setAttribute("tbUserRoleMiddleList",new TbUserRoleMiddleDAO().getTbUserRoleMiddleAll());
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleList.jsp");
}
if ("listById".equals(method)) {
request.getSession(true).setAttribute("tbUserRoleMiddle",new TbUserRoleMiddleDAO().getTbUserRoleMiddleByUserRoleMiddleId(Integer.parseInt(request.getParameter("userRoleMiddleId"))));
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleOperate.jsp");
}
if("showadd".equals(method)){
response.sendRedirect("TbuserrolemiddleModule/TbUserRoleMiddleOperate.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
}