From 949855facc5b6ff0d17dc4e945523487bd3c0198 Mon Sep 17 00:00:00 2001 From: you <284908631@qq.com> Date: Mon, 8 Jun 2020 18:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=9A=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebContent/admin/borrowlist.jsp | 2 +- WebContent/admin/index.jsp | 11 +-- WebContent/admin/managelist.jsp | 3 - WebContent/admin/manageradd.jsp | 90 ++++++++++++++++++++++ WebContent/admin/manageredit.jsp | 103 +++++++++++++++++++++++++ WebContent/admin/managerlist.jsp | 118 +++++++++++++++++++++++++++++ WebContent/admin/ruleadd.jsp | 7 +- src/servlet/admin/ManagerAdd.java | 93 +++++++++++++++++++++++ src/servlet/admin/ManagerDel.java | 57 ++++++++++++++ src/servlet/admin/ManagerEdit.java | 84 ++++++++++++++++++++ src/servlet/admin/ManagerList.java | 66 ++++++++++++++++ src/servlet/admin/RuleAdd.java | 1 + src/servlet/admin/RuleDel.java | 1 + src/servlet/admin/RuleEdit.java | 2 +- 14 files changed, 622 insertions(+), 16 deletions(-) delete mode 100644 WebContent/admin/managelist.jsp create mode 100644 WebContent/admin/manageradd.jsp create mode 100644 WebContent/admin/manageredit.jsp create mode 100644 WebContent/admin/managerlist.jsp create mode 100644 src/servlet/admin/ManagerAdd.java create mode 100644 src/servlet/admin/ManagerDel.java create mode 100644 src/servlet/admin/ManagerEdit.java create mode 100644 src/servlet/admin/ManagerList.java diff --git a/WebContent/admin/borrowlist.jsp b/WebContent/admin/borrowlist.jsp index 8c0ef74..c1c6dbe 100644 --- a/WebContent/admin/borrowlist.jsp +++ b/WebContent/admin/borrowlist.jsp @@ -56,7 +56,7 @@ ,{field:'borrow_date', width:180, title: '借阅时间'} ,{field:'end_date', title: '限定时间', width: 180} ,{field:'return_date', width:180, title: '归还时间', sort: true} - ,{field:'illegal', width:280, title: '违章信息', sort: true} + ,{field:'illegal', minWidth:280, title: '违章信息', sort: true} ,{field:'manager_id', width:80, title: '处理人'} ]] ,page: true diff --git a/WebContent/admin/index.jsp b/WebContent/admin/index.jsp index d18f6b2..90d4c88 100644 --- a/WebContent/admin/index.jsp +++ b/WebContent/admin/index.jsp @@ -15,15 +15,12 @@ @@ -54,7 +51,7 @@
  • 借阅信息查询
  • 借阅规则管理
  • -
  • 图书管理员管理
  • +
  • 图书管理员管理
  • 系统管理
  • diff --git a/WebContent/admin/managelist.jsp b/WebContent/admin/managelist.jsp deleted file mode 100644 index ba7f881..0000000 --- a/WebContent/admin/managelist.jsp +++ /dev/null @@ -1,3 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> -managelist.html \ No newline at end of file diff --git a/WebContent/admin/manageradd.jsp b/WebContent/admin/manageradd.jsp new file mode 100644 index 0000000..9f190c3 --- /dev/null +++ b/WebContent/admin/manageradd.jsp @@ -0,0 +1,90 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +管理员添加 + + + + + + + +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    +
    + +
    +
    +
    + + + \ No newline at end of file diff --git a/WebContent/admin/manageredit.jsp b/WebContent/admin/manageredit.jsp new file mode 100644 index 0000000..e9201c0 --- /dev/null +++ b/WebContent/admin/manageredit.jsp @@ -0,0 +1,103 @@ +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="com.mysql.jdbc.Connection"%> +<%@page import="javabean.Base"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +管理员修改 + + + + + + + +<% + String id = request.getParameter("id"); + Connection connection = (Connection)Base.getConnection(); + String sql = "select * from manager where id=?"; + PreparedStatement pstmt = connection.prepareCall(sql); + pstmt.setString(1,id); + ResultSet resultSet = pstmt.executeQuery(); + resultSet.next(); + +%> +
    + lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input layui-hide"> +
    + +
    + lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input"> +
    +
    +
    + +
    + disabled lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input"> +
    +
    +
    + +
    + lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input"> +
    +
    +
    + +
    + lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input"> +
    +
    + +
    +
    + +
    +
    +
    + + + \ No newline at end of file diff --git a/WebContent/admin/managerlist.jsp b/WebContent/admin/managerlist.jsp new file mode 100644 index 0000000..25093b0 --- /dev/null +++ b/WebContent/admin/managerlist.jsp @@ -0,0 +1,118 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + + 借阅卡 + + + + + + +
    + + + + + + + + + \ No newline at end of file diff --git a/WebContent/admin/ruleadd.jsp b/WebContent/admin/ruleadd.jsp index f7e274a..cc7f6e0 100644 --- a/WebContent/admin/ruleadd.jsp +++ b/WebContent/admin/ruleadd.jsp @@ -40,7 +40,7 @@
    - +
    @@ -72,7 +72,7 @@
    - +
    @@ -81,12 +81,11 @@ layui.use(['form', 'jquery'], function(){ - //layer.closeAll(); $ = layui.jquery; var form = layui.form ,layer = layui.layer //监听提交 - form.on('submit(bookForm)', function(data){ + form.on('submit(submitButton)', function(data){ $.ajax({ url: './ruleAdd', method: 'post', diff --git a/src/servlet/admin/ManagerAdd.java b/src/servlet/admin/ManagerAdd.java new file mode 100644 index 0000000..8b78b5f --- /dev/null +++ b/src/servlet/admin/ManagerAdd.java @@ -0,0 +1,93 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.mysql.jdbc.Connection; + +import javabean.Base; +import javabean.Util; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/managerAdd") +public class ManagerAdd extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 接收参数 + String name = req.getParameter("name"); + String account = req.getParameter("account"); + String password = req.getParameter("password"); + String email = req.getParameter("email"); + // 准备参数 + String sql = ""; + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + int count = 0; + // 返回参数 + int code = 1; + String msg = ""; + PrintWriter out = resp.getWriter(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + // 进行查询 + if(name==null || name.equals("") || account==null || account.equals("") || password==null || password.equals("") || email==null || email.equals("")) { + msg = "参数不能为空"; + out.print(Util.jsonResponse(code, msg, null)); + }else { + try { + connection = (Connection) Base.getConnection(); + // 验证账号 + sql = "select count(*) as count from manager where account=?"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, account); + resultSet = pstmt.executeQuery(); + resultSet.next(); + count = resultSet.getInt("count"); + // 添加管理员 + if(count == 0) { + sql = "insert into manager(name, account, password, email) values(?,?,?,?)"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, name); + pstmt.setString(2, account); + pstmt.setString(3, password); + pstmt.setString(4, email); + result = pstmt.executeUpdate(); + } + // 返回数据 + if(result == 1 && count == 0) { + code = 0; + msg = "添加成功"; + }else if(count > 0){ + msg = "账号重复"; + }else { + msg = "添加失败"; + } + } catch (ClassNotFoundException e) { + msg = "class not found"; + } catch (SQLException e) { + msg = "sql错误"; + } finally { + try { + Base.closeResource(connection, pstmt, resultSet); + } catch (SQLException e) { + e.printStackTrace(); + } + } + out.print(Util.jsonResponse(code, msg, null)); + } + } +} diff --git a/src/servlet/admin/ManagerDel.java b/src/servlet/admin/ManagerDel.java new file mode 100644 index 0000000..c087c56 --- /dev/null +++ b/src/servlet/admin/ManagerDel.java @@ -0,0 +1,57 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.mysql.jdbc.Connection; + +import javabean.Base; +import javabean.Util; + + +@WebServlet("/admin/managerDel") +public class ManagerDel extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String id = req.getParameter("id"); + // 准备参数 + String sql = ""; + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + // 返回参数 + int code = 1; + String msg = ""; + PrintWriter out = resp.getWriter(); + try { + connection = (Connection) Base.getConnection(); + sql = "delete from manager where id=?"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, id); + result = pstmt.executeUpdate(); + if(result == 1) { + code = 0; + msg = "删除成功"; + }else { + msg = "删除失败"; + } + } catch (ClassNotFoundException e) { + msg = "class not found"; + } catch (SQLException e) { + msg = "sql错误"; + } + out.print(Util.jsonResponse(code, msg, null)); + + } + +} diff --git a/src/servlet/admin/ManagerEdit.java b/src/servlet/admin/ManagerEdit.java new file mode 100644 index 0000000..0115dfa --- /dev/null +++ b/src/servlet/admin/ManagerEdit.java @@ -0,0 +1,84 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.mysql.jdbc.Connection; + +import javabean.Base; +import javabean.Util; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/managerEdit") +public class ManagerEdit extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 接收参数 + String id = req.getParameter("id"); + String name = req.getParameter("name"); + String password = req.getParameter("password"); + String email = req.getParameter("email"); + // 准备参数 + String sql = ""; + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + // 返回参数 + int code = 1; + String msg = ""; + PrintWriter out = resp.getWriter(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + // 进行查询 + if(name==null || name.equals("")|| password==null || password.equals("") || email==null || email.equals("")) { + msg = "参数不能为空"; + out.print(Util.jsonResponse(code, msg, null)); + }else { + try { + connection = (Connection) Base.getConnection(); + // 添加管理员 + sql = "update manager set name=?, password=?, email=? where id=?"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, name); + pstmt.setString(2, password); + pstmt.setString(3, email); + pstmt.setString(4, id); + result = pstmt.executeUpdate(); + + // 返回数据 + if(result == 1 ){ + code = 0; + msg = "修改成功"; + }else { + msg = "修改失败"; + } + } catch (ClassNotFoundException e) { + msg = "class not found"; + } catch (SQLException e) { + msg = "sql错误"; + } finally { + try { + Base.closeResource(connection, pstmt, resultSet); + } catch (SQLException e) { + e.printStackTrace(); + } + } + out.print(Util.jsonResponse(code, msg, null)); + } + + } + +} diff --git a/src/servlet/admin/ManagerList.java b/src/servlet/admin/ManagerList.java new file mode 100644 index 0000000..9a4ff1e --- /dev/null +++ b/src/servlet/admin/ManagerList.java @@ -0,0 +1,66 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.mysql.jdbc.Connection; + +import javabean.Base; +import javabean.Util; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/managerList") +public class ManagerList extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 准备数据 + Connection connection = null; + PreparedStatement pstmt = null; + String sql = ""; + ResultSet resultSet = null; + // 返回数据 + int code = 1; + String msg = "error"; + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + PrintWriter out = resp.getWriter(); + try { + connection = (Connection) Base.getConnection(); + sql = "select * from manager"; + pstmt = connection.prepareStatement(sql); + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + jsonObject.put("id", resultSet.getString("id")); + jsonObject.put("name", resultSet.getString("name")); + jsonObject.put("account", resultSet.getString("account")); + jsonObject.put("password", resultSet.getString("password")); + jsonObject.put("email", resultSet.getString("email")); + jsonArray.add(jsonObject); + } + if(!jsonArray.isEmpty()) { + code = 0; + msg = "查询成功"; + }else { + msg = "数据为空"; + } + } catch (ClassNotFoundException e) { + msg = "class找不到"; + } catch (SQLException e) { + msg = "sql错误"; + } + out.print( Util.jsonResponse(code, msg, jsonArray.toString()) ); + } + +} diff --git a/src/servlet/admin/RuleAdd.java b/src/servlet/admin/RuleAdd.java index d3e0da0..bcb5a81 100644 --- a/src/servlet/admin/RuleAdd.java +++ b/src/servlet/admin/RuleAdd.java @@ -24,6 +24,7 @@ import javabean.Util; public class RuleAdd extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); // 准备数据 Connection connection = null; PreparedStatement pstmt = null; diff --git a/src/servlet/admin/RuleDel.java b/src/servlet/admin/RuleDel.java index 7ce65a9..35f91a6 100644 --- a/src/servlet/admin/RuleDel.java +++ b/src/servlet/admin/RuleDel.java @@ -22,6 +22,7 @@ import javabean.Util; public class RuleDel extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); // 接受数据 String id = req.getParameter("id"); // 准备数据 diff --git a/src/servlet/admin/RuleEdit.java b/src/servlet/admin/RuleEdit.java index e2766a2..499533f 100644 --- a/src/servlet/admin/RuleEdit.java +++ b/src/servlet/admin/RuleEdit.java @@ -26,6 +26,7 @@ import javabean.Util; public class RuleEdit extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); // 准备数据 Connection connection = null; PreparedStatement pstmt = null; @@ -73,7 +74,6 @@ public class RuleEdit extends HttpServlet { pstmt.setString(3, borrow_library); pstmt.setString(4, overtime_fee); pstmt.setString(5, id); - System.out.println(overtime_fee); result = pstmt.executeUpdate(); if(result == 1) { code = 0;