系统功能:系统管理员管理,客房管理,客户管理,特色菜品介绍,餐桌预定管理,餐饮消费管理。
技术栈: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 + "条记录 每页<span style=\'color:#FF0000\'>" + this.pageSize + "</span>条 ");
displayInfo.append("第<span style=\'color:#FF0000\'>" + this.index + "</span>页/共" + this.getTotlePage() + "页 ");
if(this.index == 1) {
displayInfo.append("首页 ");
displayInfo.append("上一页 ");
} else {
displayInfo.append("<a href=\'" + this.path + "index=1\'>首页 </a>");
displayInfo.append("<a href=\'" + this.path + "index=" + (this.index - 1) + "\'>上一页 </a> ");
}
if(this.index >= this.getTotlePage()) {
displayInfo.append("下一页 ");
displayInfo.append("末页 ");
} else {
displayInfo.append("<a href=\'" + this.path + "index=" + (this.index + 1) + "\'>下一页 </a>");
displayInfo.append("<a href=\'" + this.path + "index=" + this.getTotlePage() + "\'>末页</a> ");
}
displayInfo.append("</div>");
} else {
displayInfo.append("没有分页的信息!");
}
return displayInfo.toString();
}
}
交流学习请评论区联系,有源码和部署指导。