java+servlet酒店管理系统

系统功能:系统管理员管理,客房管理,客户管理,特色菜品介绍,餐桌预定管理,餐饮消费管理。

技术栈:java+servlet+mysql+jdbc。

系统截图:

 

 

 

 源码展示:

package com.action;

import com.dao.DB;
import com.orm.TAdmin;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class admin_servlet extends HttpServlet {

   public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      String type = req.getParameter("type");
      if(type.endsWith("adminMana")) {
         this.adminMana(req, res);
      }

      if(type.endsWith("adminAdd")) {
         this.adminAdd(req, res);
      }

      if(type.endsWith("adminDel")) {
         this.adminDel(req, res);
      }

   }

   public void adminMana(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      ArrayList adminList = new ArrayList();
      String sql = "select * from t_admin";
      Object[] params = new Object[0];
      DB mydb = new DB();

      try {
         mydb.doPstm(sql, params);
         ResultSet e = mydb.getRs();

         while(e.next()) {
            TAdmin admin = new TAdmin();
            admin.setUserId(e.getInt("userId"));
            admin.setUserName(e.getString("userName"));
            admin.setUserPw(e.getString("userPw"));
            adminList.add(admin);
         }

         e.close();
      } catch (Exception var9) {
         var9.printStackTrace();
      }

      mydb.closed();
      req.setAttribute("adminList", adminList);
      req.getRequestDispatcher("admin/admin/adminMana.jsp").forward(req, res);
   }

   public void adminAdd(HttpServletRequest req, HttpServletResponse res) {
      String userName = req.getParameter("userName");
      String userPw = req.getParameter("userPw");
      String sql = "insert into t_admin(userName,userPw) values(?,?)";
      Object[] params = new Object[]{userName, userPw};
      DB mydb = new DB();
      mydb.doPstm(sql, params);
      mydb.closed();
      req.setAttribute("message", "操作成功");
      req.setAttribute("path", "admin?type=adminMana");
      String targetURL = "/common/success.jsp";
      this.dispatch(targetURL, req, res);
   }

   public void adminDel(HttpServletRequest req, HttpServletResponse res) {
      System.out.println(req.getParameter("userId") + "**");
      String sql = "delete from t_admin where userId=" + Integer.parseInt(req.getParameter("userId"));
      Object[] params = new Object[0];
      DB mydb = new DB();
      mydb.doPstm(sql, params);
      mydb.closed();
      req.setAttribute("message", "操作成功");
      req.setAttribute("path", "admin?type=adminMana");
      String targetURL = "/common/success.jsp";
      this.dispatch(targetURL, req, res);
   }

   public void dispatch(String targetURI, HttpServletRequest request, HttpServletResponse response) {
      RequestDispatcher dispatch = this.getServletContext().getRequestDispatcher(targetURI);

      try {
         dispatch.forward(request, response);
         return;
      } catch (ServletException var6) {
         var6.printStackTrace();
      } catch (IOException var7) {
         var7.printStackTrace();
      }

   }

   public void init(ServletConfig config) throws ServletException {
      super.init(config);
   }

   public void destroy() {}
}
package com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DB {

   private Connection con;
   private PreparedStatement pstm;
   private String user = "root";
   private String password = "123456";
   private String className = "com.mysql.jdbc.Driver";
   private String url = "jdbc:mysql://localhost:3306/db_jiudian?characterEncoding=utf-8";


   public DB() {
      try {
         Class.forName(this.className);
      } catch (ClassNotFoundException var2) {
         System.out.println("鍔犺浇鏁版嵁搴撻┍鍔ㄥけ璐ワ紒");
         var2.printStackTrace();
      }

   }

   public Connection getCon() {
      try {
         this.con = DriverManager.getConnection(this.url, this.user, this.password);
      } catch (SQLException var2) {
         System.out.println("鍒涘缓鏁版嵁搴撹繛鎺ュけ璐ワ紒");
         this.con = null;
         var2.printStackTrace();
      }

      return this.con;
   }

   public void doPstm(String sql, Object[] params) {
      if(sql != null && !sql.equals("")) {
         if(params == null) {
            params = new Object[0];
         }

         this.getCon();
         if(this.con != null) {
            try {
               System.out.println(sql);
               this.pstm = this.con.prepareStatement(sql, 1004, 1007);

               for(int e = 0; e < params.length; ++e) {
                  this.pstm.setObject(e + 1, params[e]);
                  for (Object param : params) {
                     System.out.println(param);
                  }
               }
               System.out.println(1);
               this.pstm.execute();
            } catch (SQLException var4) {
               System.out.println("doPstm()鏂规硶鍑洪敊锛�");
               var4.printStackTrace();
            }
         }
      }

   }

   public ResultSet getRs() throws SQLException {
      return this.pstm.getResultSet();
   }

   public int getCount() throws SQLException {
      return this.pstm.getUpdateCount();
   }

   public void closed() {
      try {
         if(this.pstm != null) {
            this.pstm.close();
         }
      } catch (SQLException var3) {
         System.out.println("鍏抽棴pstm瀵硅薄澶辫触锛�");
         var3.printStackTrace();
      }

      try {
         if(this.con != null) {
            this.con.close();
         }
      } catch (SQLException var2) {
         System.out.println("鍏抽棴con瀵硅薄澶辫触锛�");
         var2.printStackTrace();
      }

   }
}
package com.util;

import java.util.List;

public class Pagination {

   private int totle;
   private int pageSize;
   private int totlePage;
   private int index;
   private List data;
   private String path;


   public void setTotle(int totle) {
      this.totle = totle;
   }

   public void setPageSize(int pageSize) {
      this.pageSize = pageSize;
   }

   public void setIndex(int index) {
      this.index = index;
   }

   public void setPath(String path) {
      this.path = path;
   }

   public int getTotle() {
      return this.totle;
   }

   public int getPageSize() {
      return this.pageSize;
   }

   public int getTotlePage() {
      return (this.totle + this.pageSize - 1) / this.pageSize;
   }

   public int getIndex() {
      return this.index;
   }

   public List getData() {
      return this.data;
   }

   public void setData(List data) {
      this.data = data;
   }

   public String getPageDisplay() {
      StringBuffer displayInfo = new StringBuffer();
      if(this.index != 0 && this.pageSize != 0) {
         displayInfo.append("<div>");
         displayInfo.append("共" + this.totle + "条记录&nbsp;&nbsp;&nbsp;&nbsp;每页<span style=\'color:#FF0000\'>" + this.pageSize + "</span>条&nbsp;&nbsp;&nbsp;&nbsp;");
         displayInfo.append("第<span style=\'color:#FF0000\'>" + this.index + "</span>页/共" + this.getTotlePage() + "页&nbsp;&nbsp;&nbsp;&nbsp;");
         if(this.index == 1) {
            displayInfo.append("首页&nbsp;&nbsp;&nbsp;&nbsp;");
            displayInfo.append("上一页&nbsp;&nbsp;&nbsp;&nbsp;");
         } else {
            displayInfo.append("<a href=\'" + this.path + "index=1\'>首页&nbsp;&nbsp;&nbsp;&nbsp;</a>");
            displayInfo.append("<a href=\'" + this.path + "index=" + (this.index - 1) + "\'>上一页&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;");
         }

         if(this.index >= this.getTotlePage()) {
            displayInfo.append("下一页&nbsp;&nbsp;&nbsp;&nbsp;");
            displayInfo.append("末页&nbsp;&nbsp;&nbsp;&nbsp;");
         } else {
            displayInfo.append("<a href=\'" + this.path + "index=" + (this.index + 1) + "\'>下一页&nbsp;&nbsp;&nbsp;&nbsp;</a>");
            displayInfo.append("<a href=\'" + this.path + "index=" + this.getTotlePage() + "\'>末页</a>&nbsp;&nbsp;&nbsp;&nbsp;");
         }

         displayInfo.append("</div>");
      } else {
         displayInfo.append("没有分页的信息!");
      }

      return displayInfo.toString();
   }
}

交流学习请评论区联系,有源码和部署指导。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值