diff --git a/WebContent/admin/bookadd.jsp b/WebContent/admin/bookadd.jsp index fe992d6..1446d3f 100644 --- a/WebContent/admin/bookadd.jsp +++ b/WebContent/admin/bookadd.jsp @@ -1,3 +1,5 @@ +<%@page import="java.sql.ResultSet"%> +<%@page import="javabean.JDBCBean"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> @@ -11,69 +13,86 @@ + -
+ <% + ResultSet librarySet = null; + ResultSet bookSortSet = null; + // 获取图书馆列表 + JDBCBean db2 = new JDBCBean(); + String librarySql = "select * from library"; + librarySet = db2.executeQuery( librarySql ); + // 获取书籍分类 + JDBCBean db3 = new JDBCBean(); + String bookSortSql = "select * from book_sort"; + bookSortSet = db3.executeQuery( bookSortSql ); + %> + +
- +
- +
+
- -
- + +
+
-
辅助文字
- +
- + + <% while( librarySet.next() ){ %> + + <%} %>
-
- +
+
- - - +
- +
- +
- +
- - +
可借
+
不可借
+
- +
- +
+
- +
@@ -81,15 +100,48 @@ diff --git a/WebContent/admin/bookborrowlist.jsp b/WebContent/admin/bookborrowlist.jsp new file mode 100644 index 0000000..6c35f24 --- /dev/null +++ b/WebContent/admin/bookborrowlist.jsp @@ -0,0 +1,83 @@ +<%@page import="javabean.Util"%> +<%@page import="javabean.Base"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="com.mysql.jdbc.Connection"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +书籍借阅历史 + + + + + +<% + String id = request.getParameter("id"); + String name = request.getParameter("name"); + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + String sql = "select * from borrow_books,borrow_card where book_id=? and card_id=borrow_card.id order by borrow_books.id desc"; + connection = (Connection)Base.getConnection(); + pstmt = connection.prepareStatement(sql); + pstmt.setString(1,id); + resultSet = pstmt.executeQuery(); +/* while(resultSet.next()){ + out.print(resultSet.getString("id")); + }*/ +%> +
+ + + + + + + + + + + + + + + + + + + + + + + + + <%while(resultSet.next()){ %> + + + + + + + + + + + + <%} %> + + + + + +
ID书籍ID书籍名借阅证借阅者借阅时间归还时间违规信息处理人
<%=resultSet.getString("id") %><%=id %><%=name %><%=resultSet.getString("borrow_card.id") %><%=resultSet.getString("reader") %><%=Util.getFormatDateTime(resultSet.getString("borrow_date")) %><%=resultSet.getString("return_date") != null? Util.getFormatDateTime(resultSet.getString("return_date")) : "" %><%=resultSet.getString("illegal") != null? resultSet.getString("illegal") : "" %><%=resultSet.getString("manager_id") != null? resultSet.getString("manager_id") : "" %>
+
+ + \ No newline at end of file diff --git a/WebContent/admin/bookedit.jsp b/WebContent/admin/bookedit.jsp index 4cd9cba..d37a8a7 100644 --- a/WebContent/admin/bookedit.jsp +++ b/WebContent/admin/bookedit.jsp @@ -7,7 +7,7 @@ - bookadd + bookedit @@ -15,7 +15,6 @@ @@ -31,6 +30,7 @@ resultSet = db.executeQuery(sql); resultSet.next(); String name = resultSet.getString("name"); + String author = resultSet.getString("author"); int library_id = resultSet.getInt("library_id"); int sort_id = resultSet.getInt("sort_id"); String position = resultSet.getString("position"); @@ -49,13 +49,25 @@ bookSortSet = db3.executeQuery( bookSortSql ); %> + + <%-- 隐藏id --%> + class="layui-hide"> +
required lay-verify="required" placeholder="请输入书名" autocomplete="off" class="layui-input">
+ +
+ +
+ required lay-verify="required" placeholder="请输入作者" autocomplete="off" class="layui-input"> +
+
+
@@ -68,23 +80,26 @@
+
+
required lay-verify="required" placeholder="请输入位置编号" autocomplete="off" class="layui-input">
+
@@ -92,18 +107,11 @@ >
-
- +
@@ -116,20 +124,47 @@ - + <% + + JDBCBean libraryDb = new JDBCBean(); + JDBCBean bookSortDb = new JDBCBean(); + ResultSet librarySet = null; + ResultSet bookSortSet = null; + // 准备sql + String librarySql = "select * from library"; + String bookSortSql = "select * from book_sort"; + // 进行查询 + librarySet = libraryDb.executeQuery( librarySql ); + bookSortSet = bookSortDb.executeQuery( bookSortSql ); + // 准备json + JSONObject libraryJson = new JSONObject(); + JSONObject bookSortJson = new JSONObject(); + + // 遍历set + // 获取图书馆json + while( librarySet.next() ){ + libraryJson.put(librarySet.getString("id") , librarySet.getString("name")); + } + // 获取分类json + while( bookSortSet.next() ){ + bookSortJson.put(bookSortSet.getString("id") , bookSortSet.getString("name")); + } + librarySet.close(); + libraryDb.close(); + + %> @@ -45,12 +80,30 @@ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/WebContent/admin/cardadd.jsp b/WebContent/admin/cardadd.jsp new file mode 100644 index 0000000..2d3ff0a --- /dev/null +++ b/WebContent/admin/cardadd.jsp @@ -0,0 +1,117 @@ +<%@page import="javabean.Base"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="com.mysql.jdbc.Connection"%> +<%@page import="net.sf.json.JSONObject"%> +<%@page import="net.sf.json.JSONArray"%> +<%@page import="javabean.Admin"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +图书证修改 + + + + + +<% + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet ruleSet = null; + String sql = "select * from rules"; + String result = ""; + connection = (Connection)Base.getConnection(); + pstmt = connection.prepareStatement(sql); + ruleSet = pstmt.executeQuery(); +%> +
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/WebContent/admin/cardborrow.jsp b/WebContent/admin/cardborrow.jsp new file mode 100644 index 0000000..ca00f39 --- /dev/null +++ b/WebContent/admin/cardborrow.jsp @@ -0,0 +1,83 @@ +<%@page import="javabean.Util"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="com.mysql.jdbc.Connection"%> +<%@page import="javabean.Base"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="javabean.JDBCBean"%> +<%@ 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 borrow_books,books where card_id=? and borrow_books.book_id = books.id"; + PreparedStatement pstmt = connection.prepareStatement(sql); + pstmt.setString(1, id); + ResultSet resultSet = null; + resultSet = pstmt.executeQuery(); + +%> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + <% + System.out.println(Util.getCurrentTimeString()); + %> + <% while(resultSet.next()){ %> + <%-- 图书超期 --%> + <%if(Util.getFormatDateTime(resultSet.getString("end_date")).compareTo(Util.getCurrentTimeString()) < 0 && resultSet.getString("return_date") == null){ %> + + <%} else{ %> + + <%} %> + + + + + + + + + + <%} %> + +
ID书籍ID书籍名借阅时间截止时间归还时间违规信息处理人
<%=resultSet.getString("card_id") %><%=resultSet.getString("id") %><%=resultSet.getString("books.name") %><%=Util.getFormatDateTime(resultSet.getString("borrow_date")) %><%=Util.getFormatDateTime(resultSet.getString("end_date"))%><%=resultSet.getString("return_date")!=null?Util.getFormatDateTime(resultSet.getString("return_date")) : "未归还" %><%=resultSet.getString("illegal")!=null?resultSet.getString("illegal"):""%><%=resultSet.getString("manager_id")!=null?resultSet.getString("manager_id"):"" %>
+
+ + \ No newline at end of file diff --git a/WebContent/admin/cardedit.jsp b/WebContent/admin/cardedit.jsp new file mode 100644 index 0000000..57c9e5c --- /dev/null +++ b/WebContent/admin/cardedit.jsp @@ -0,0 +1,157 @@ +<%@page import="javabean.Base"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="com.mysql.jdbc.Connection"%> +<%@page import="net.sf.json.JSONObject"%> +<%@page import="net.sf.json.JSONArray"%> +<%@page import="javabean.Admin"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +图书证修改 + + + + + +<% + // 获取借阅证信息 + String id = request.getParameter("id"); + + + // 获取rule + Connection connection = null; + PreparedStatement pstmt = null; + PreparedStatement infoPstmt = null; + ResultSet ruleSet = null; + ResultSet infoSet = null; + String sql = "select * from rules"; + String infoSql = "select * from borrow_card where id=?"; + String result = ""; + // 公用连接 + connection = (Connection)Base.getConnection(); + pstmt = connection.prepareStatement(sql); + infoPstmt = connection.prepareStatement(infoSql); + infoPstmt.setString(1,id); + infoSet = infoPstmt.executeQuery(); + infoSet.next(); + ruleSet = pstmt.executeQuery(); +%> +
+ + +
+ +
+ class="layui-input" disabled> +
+
+ + +
+ +
+ lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input"> +
+
+ + +
+ +
+ placeholder="请输入密码" autocomplete="off" class="layui-input" lay-verify="required"> +
+
+ + +
+ +
+ +
+
+ +
+ +
+ > + > +
+
+ +
+
+ + +
+
+
+ + + +<% + Base.closeResource(connection, pstmt, ruleSet); +%> + + \ No newline at end of file diff --git a/WebContent/admin/cardlist.jsp b/WebContent/admin/cardlist.jsp index b8639f2..2d17ed2 100644 --- a/WebContent/admin/cardlist.jsp +++ b/WebContent/admin/cardlist.jsp @@ -4,9 +4,179 @@ - + 借阅卡 + + + - card + +
+ + + + + + + + + + \ No newline at end of file diff --git a/WebContent/admin/data.json b/WebContent/admin/data.json index 845c588..32c65ee 100644 --- a/WebContent/admin/data.json +++ b/WebContent/admin/data.json @@ -1 +1 @@ -{"code":0,"msg":"","count":10,"data":[{"id":10000,"name":"夏洛特的烦恼","library_name":"南图","sort_id":"言情","position_id":"sdf","state":"借出","descript":"好看","operate":"234"},{"id":10000,"name":"夏洛特的烦恼","library_name":"南图","sort_id":"言情","position_id":"sdf","state":"借出","descript":"好看","operate":"234"},{"id":10000,"name":"夏洛特的烦恼","library_name":"南图","sort_id":"言情","position_id":"sdf","state":"借出","descript":"好看","operate":"234"},{"id":10010,"name":"夏洛特的烦恼","library_name":"南图","sort_id":"言情","position_id":"sdf","state":"借出","descript":"好看","operate":"234"}]} \ No newline at end of file +{"code":0,"msg":"","data":[{"id":10020,"username":"user-20","sex":"男","city":"城市-20","sign":"签名-20","experience":770,"logins":24,"wealth":92420248,"classify":"诗人","score":87},{"id":10021,"username":"user-21","sex":"男","city":"城市-21","sign":"签名-21","experience":184,"logins":131,"wealth":71566045,"classify":"词人","score":99},{"id":10022,"username":"user-22","sex":"男","city":"城市-22","sign":"签名-22","experience":739,"logins":152,"wealth":60907929,"classify":"作家","score":18},{"id":10023,"username":"user-23","sex":"女","city":"城市-23","sign":"签名-23","experience":127,"logins":82,"wealth":14765943,"classify":"作家","score":30},{"id":10024,"username":"user-24","sex":"女","city":"城市-24","sign":"签名-24","experience":212,"logins":133,"wealth":59011052,"classify":"词人","score":76},{"id":10025,"username":"user-25","sex":"女","city":"城市-25","sign":"签名-25","experience":938,"logins":182,"wealth":91183097,"classify":"作家","score":69},{"id":10026,"username":"user-26","sex":"男","city":"城市-26","sign":"签名-26","experience":978,"logins":7,"wealth":48008413,"classify":"作家","score":65},{"id":10027,"username":"user-27","sex":"女","city":"城市-27","sign":"签名-27","experience":371,"logins":44,"wealth":64419691,"classify":"诗人","score":60},{"id":10028,"username":"user-28","sex":"女","city":"城市-28","sign":"签名-28","experience":977,"logins":21,"wealth":75935022,"classify":"作家","score":37},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"签名-29","experience":647,"logins":107,"wealth":97450636,"classify":"酱油","score":27}]} \ No newline at end of file diff --git a/WebContent/admin/index.jsp b/WebContent/admin/index.jsp index 277fc56..90d4c88 100644 --- a/WebContent/admin/index.jsp +++ b/WebContent/admin/index.jsp @@ -15,15 +15,12 @@ @@ -50,10 +47,11 @@ 书籍管理
  • - 读书证管理 + 借阅证管理
  • +
  • 借阅信息查询
  • 借阅规则管理
  • -
  • 图书管理员管理
  • +
  • 图书管理员管理
  • 系统管理
  • 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 new file mode 100644 index 0000000..cc7f6e0 --- /dev/null +++ b/WebContent/admin/ruleadd.jsp @@ -0,0 +1,119 @@ +<%@page import="javabean.Common"%> +<%@page import="java.util.TreeMap"%> +<%@page import="java.util.HashMap"%> +<%@page import="java.util.Map"%> +<%@page import="java.util.ArrayList"%> +<%@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"%> + + + + +规则添加 + + + + + + +<% + // 获取图书馆map + Map libraryMap = Common.getLibraryMap(); +%> +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + <% + for(String key : libraryMap.keySet()){ + %> + title=<%=libraryMap.get(key) %> checked> + <% + } + %> + +
    +
    +
    + +
    + +
    +
    +
    +
    + + +
    +
    +
    + + + \ No newline at end of file diff --git a/WebContent/admin/ruleedit.jsp b/WebContent/admin/ruleedit.jsp new file mode 100644 index 0000000..125ed1a --- /dev/null +++ b/WebContent/admin/ruleedit.jsp @@ -0,0 +1,144 @@ +<%@page import="javabean.Common"%> +<%@page import="java.util.TreeMap"%> +<%@page import="java.util.HashMap"%> +<%@page import="java.util.Map"%> +<%@page import="java.util.ArrayList"%> +<%@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 = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + String sql = ""; + + connection = (Connection)Base.getConnection(); + sql = "select * from rules where id = ?"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, id); + resultSet = pstmt.executeQuery(); + resultSet.next(); + + String[] libraryList = resultSet.getString("borrow_library").split("、"); + // 获取图书馆map + Map libraryMap = Common.getLibraryMap(); +%> +
    + class="layui-hide"> +
    + +
    + required lay-verify="required" placeholder="请输入限制天数" autocomplete="off" class="layui-input"> +
    +
    + +
    + +
    + required lay-verify="required" placeholder="请输入限制数量" autocomplete="off" class="layui-input"> +
    +
    + +
    + +
    + <% + for(String key : libraryMap.keySet()){ + boolean flag = false; + %> + title=<%=libraryMap.get(key) %> + <% for(String key0 : libraryList){ + flag = false; + if(key0.equals(key)){ + flag = true; + } + if(flag == true) + out.print("checked"); + } + %>> + <% + } + %> + +
    +
    +
    + +
    + required lay-verify="required" placeholder="请输入逾期每天费用" autocomplete="off" class="layui-input"> +
    +
    +
    +
    + + +
    +
    +
    + + + \ No newline at end of file diff --git a/WebContent/admin/rulelist.jsp b/WebContent/admin/rulelist.jsp index 562c2f2..44c5b7f 100644 --- a/WebContent/admin/rulelist.jsp +++ b/WebContent/admin/rulelist.jsp @@ -1,3 +1,119 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -rulelist.html \ No newline at end of file + + + + + 规则列表 + + + + + + +
    + + + + + + + + + \ No newline at end of file diff --git a/build/classes/filter/AdminFilter.class b/build/classes/filter/AdminFilter.class index fdfb5a8..ed2913a 100644 Binary files a/build/classes/filter/AdminFilter.class and b/build/classes/filter/AdminFilter.class differ diff --git a/build/classes/javabean/Admin.class b/build/classes/javabean/Admin.class index d0f2b50..fc7433f 100644 Binary files a/build/classes/javabean/Admin.class and b/build/classes/javabean/Admin.class differ diff --git a/build/classes/servlet/ServletExample.class b/build/classes/servlet/ServletExample.class deleted file mode 100644 index d310a8d..0000000 Binary files a/build/classes/servlet/ServletExample.class and /dev/null differ diff --git a/src/filter/AdminFilter.java b/src/filter/AdminFilter.java index 624c6af..584b67a 100644 --- a/src/filter/AdminFilter.java +++ b/src/filter/AdminFilter.java @@ -1,6 +1,8 @@ package filter; import java.io.IOException; +import java.io.PrintWriter; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -18,17 +20,14 @@ import javax.servlet.http.HttpSession; */ public class AdminFilter implements Filter { - public void destroy() { - - } - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - //TODO HttpServletRequest req = (HttpServletRequest) request; HttpSession session = req.getSession(); if(session == null || session.getAttribute("admin") == null) { HttpServletResponse rep = (HttpServletResponse)response; - rep.sendRedirect(req.getContextPath() +"/adminLogin.html"); + PrintWriter out =response.getWriter(); + // iframe父页面直接跳转到登录界面 + out.print(""); } chain.doFilter(request, response); } diff --git a/src/javabean/Admin.java b/src/javabean/Admin.java index 50df1af..d8a703e 100644 --- a/src/javabean/Admin.java +++ b/src/javabean/Admin.java @@ -74,8 +74,7 @@ public class Admin { whereString += " where "+where.get("condition") +" like '%" +where.get("conditionValue") +"%' "; sql += whereString; } - sql += " limit ?,? "; - System.out.println("sql: " +sql); + sql += "order by id desc limit ?,? "; pstmt = (PreparedStatement) connection.prepareStatement(sql); pstmt.setInt(1, (number-1) * size ); pstmt.setInt(2, size); @@ -90,6 +89,7 @@ public class Admin { //System.out.println("????-------" +resultSet.getInt("count")); json.put("id", resultSet.getInt("id")); json.put("name", resultSet.getString("name")); + json.put("author", resultSet.getString("author")); json.put("library_id", resultSet.getInt("library_id")); json.put("sort_id", resultSet.getInt("sort_id")); json.put("position", resultSet.getString("position")); @@ -146,6 +146,7 @@ public class Admin { }else { result = "查询失败"; } + Base.closeResource(connection, pstmt, null); return result; } @@ -174,6 +175,31 @@ public class Admin { return null; } + /* 没用 */ + public static JSONArray getRules() throws ClassNotFoundException, SQLException { + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + String sql = "select * from rules"; + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + String result = ""; + connection = Base.getConnection(); + pstmt = connection.prepareStatement(sql); + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + jsonObject.put("id", resultSet.getString("id")); + jsonObject.put("borrow_num", resultSet.getString("borrow_num")); + jsonObject.put("borrow_library", resultSet.getString("borrow_library")); + jsonObject.put("overtime_fee", resultSet.getString("overtime_fee")); + jsonArray.add(jsonObject); + System.out.println(jsonArray.toString()); + } + Base.closeResource(connection, pstmt, resultSet); + return jsonArray; + + } + public static void main(String[] args) throws ClassNotFoundException, SQLException { //Common common = new Common(); //System.out.println(common.getCount("books")); diff --git a/src/javabean/Common.java b/src/javabean/Common.java index d5095ea..6f3669a 100644 --- a/src/javabean/Common.java +++ b/src/javabean/Common.java @@ -4,6 +4,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashMap; +import java.util.TreeMap; public class Common { /** @@ -32,4 +34,34 @@ public class Common { } } + + + public static TreeMap getLibraryMap() throws SQLException { + Connection connection = null; + PreparedStatement libraryPstmt = null; + ResultSet librarySet = null; + String librarySql = "select id,name from library"; + + TreeMap map = new TreeMap(); + // 获取图书馆 + try { + connection = (Connection) Base.getConnection(); + libraryPstmt = connection.prepareStatement(librarySql); + librarySet = libraryPstmt.executeQuery(); + while(librarySet.next()) { + map.put(librarySet.getString("id"), librarySet.getString("name")); + } + } catch (ClassNotFoundException e) { + return null; + } catch (SQLException e) { + return null; + } finally { + Base.closeResource(connection, libraryPstmt, librarySet); + } + return map; + } + + public static void main(String[] args) throws SQLException { + System.out.println(Common.getLibraryMap()); + } } diff --git a/src/javabean/TestConnection.java b/src/javabean/TestConnection.java new file mode 100644 index 0000000..5aaba76 --- /dev/null +++ b/src/javabean/TestConnection.java @@ -0,0 +1,48 @@ +package javabean; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import java.sql.Connection; + +public class TestConnection { + public static void main(String[] args) throws ClassNotFoundException, SQLException { + // 获取rule + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + String password = "1234"; + String reader = "1234"; + String rule_id = "1"; + String status = "1"; + connection = (Connection) Base.getConnection(); + String sql = "insert into borrow_card(password, reader, rule_id, status) values(?,?,?,?)"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, password); + pstmt.setString(2, reader); + pstmt.setString(3, rule_id); + pstmt.setString(4, status); + result = pstmt.executeUpdate(); + System.out.println(result); + //获取id + //connection1= (Connection) Base.getConnection(); + String findIdSql = "select id from borrow_card where password=? and reader=? and rule_id=? and status=? limit 1"; + pstmt = connection.prepareStatement(findIdSql); + pstmt.setString(1, password); + pstmt.setString(2, reader); + pstmt.setString(3, rule_id); + pstmt.setString(4, status); +// pstmt1 = connection.prepareStatement(findIdSql); +// pstmt1.setString(1, password); +// pstmt1.setString(2, reader); +// pstmt1.setString(3, rule_id); +// pstmt1.setString(4, status); + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + System.out.println(resultSet.getString("id")); + } + + } +} diff --git a/src/javabean/Util.java b/src/javabean/Util.java index 1afdf4e..1c1a7cd 100644 --- a/src/javabean/Util.java +++ b/src/javabean/Util.java @@ -1,5 +1,9 @@ package javabean; +import java.text.SimpleDateFormat; + +import net.sf.json.JSONObject; + public class Util { /** * 主要用来计算json字符串中对象的个数 @@ -11,7 +15,45 @@ public class Util { int count = ( str.length()-str.replace(contain, "").length() ) / contain.length(); return count; } + + /** + * 数据库取出来的datetime有 .0 ,用来去掉 + * @param dateTime + * @return + */ + public static String getFormatDateTime(String dateTime) { + if(dateTime != null && dateTime.indexOf(".0") != -1) { + return dateTime.substring(0, dateTime.length()-2); + }else if(dateTime != null) { + return dateTime; + } + return null; + } + + /** + * 获取当前时间 + * @return + */ + public static String getCurrentTimeString() { + java.util.Date date = new java.util.Date(); + SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + return dateFormat.format(date); + } + + public static String jsonResponse(int code, String msg, String data) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", code); + jsonObject.put("msg", msg); + if( data!=null ) { + jsonObject.put("data", data); + } + + return jsonObject.toString(); + } + public static void main(String[] args) { - System.out.println(Util.getCountString("234{sdf{sdf{", "{")); + java.util.Date date = new java.util.Date(); + SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + System.out.println(dateFormat.format(date)); } } diff --git a/src/servlet/ServletExample.java b/src/servlet/ServletExample.java deleted file mode 100644 index b15a662..0000000 --- a/src/servlet/ServletExample.java +++ /dev/null @@ -1,29 +0,0 @@ -package servlet; - -import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet implementation class ServletExample - */ - -public class ServletExample extends HttpServlet { - private static final long serialVersionUID = 1L; - - public ServletExample() { - - } - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.getWriter().append("Served at: ").append(request.getContextPath()); - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - doGet(request, response); - } - -} diff --git a/src/servlet/Test.java b/src/servlet/Test.java deleted file mode 100644 index c5e7f81..0000000 --- a/src/servlet/Test.java +++ /dev/null @@ -1,45 +0,0 @@ -package servlet; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet implementation class Test - */ - -public class Test extends HttpServlet { - private static final long serialVersionUID = 1L; - - /** - * @see HttpServlet#HttpServlet() - */ - public Test() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - // TODO Auto-generated method stub - response.getWriter().append("Served at:ddd ").append(request.getContextPath()); - } - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - // TODO Auto-generated method stub - doGet(request, response); - } - -} diff --git a/src/servlet/admin/BookAdd.java b/src/servlet/admin/BookAdd.java new file mode 100644 index 0000000..5468c25 --- /dev/null +++ b/src/servlet/admin/BookAdd.java @@ -0,0 +1,75 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONObject; + +/** + * Servlet implementation class BookAdd + */ +@WebServlet("/admin/bookAdd") +public class BookAdd 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 author = req.getParameter("author"); + String library_id = req.getParameter("library_id"); + String sort_id = req.getParameter("sort_id"); + String position = req.getParameter("position"); + String status = req.getParameter("status"); + String description = req.getParameter("description"); + System.out.println(description+"-------------"); //debug + JSONObject json = new JSONObject(); + Connection connection = null; + PreparedStatement pstmt = null; + //ResultSet resultSet = null; + int result = 0; + String sql = "insert into books(name, author, library_id, sort_id, position, status, description) values(?,?,?,?,?,?,?)"; + System.out.println(sql); + PrintWriter out = resp.getWriter(); + try { + connection = (Connection) Base.getConnection(); + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, name); + pstmt.setString(2, author); + pstmt.setString(3, library_id); + pstmt.setString(4, sort_id); + pstmt.setString(5, position); + pstmt.setString(6, status); + pstmt.setString(7, description); + result = pstmt.executeUpdate(); + } catch (SQLException e) { + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + }finally { + try { + Base.closeResource(connection, pstmt, null); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if(result==1) { + json.put("code", "0"); + json.put("msg", "success"); + }else { + json.put("code", "1"); + json.put("msg", "error"); + } + out.write(json.toString()); + } + +} diff --git a/src/servlet/admin/BookDel.java b/src/servlet/admin/BookDel.java new file mode 100644 index 0000000..8242a2f --- /dev/null +++ b/src/servlet/admin/BookDel.java @@ -0,0 +1,46 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; + +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 javabean.JDBCBean; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/bookDel") +public class BookDel extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + String id = req.getParameter("id"); + JSONObject json = new JSONObject(); + JDBCBean db = new JDBCBean(); + String sql = "delete from books where id = " +id; + int result = 0; + int code = 1; + String msg = ""; + if( id != null && !id.equals("") ) { + result = db.executeUpdate(sql); + } + if( result == 1 ) { + code = 0; + msg = "删除成功"; + }else { + code = 1; + msg = "删除失败"; + } + json.put("code", code); + json.put("msg", msg); + db.close(); + PrintWriter out = resp.getWriter(); + out.print( json.toString() ); + + } + +} diff --git a/src/servlet/admin/BookEdit.java b/src/servlet/admin/BookEdit.java new file mode 100644 index 0000000..b37fac1 --- /dev/null +++ b/src/servlet/admin/BookEdit.java @@ -0,0 +1,88 @@ +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/bookEdit") +public class BookEdit 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 author = req.getParameter("author"); + String library_id = req.getParameter("library_id"); + String sort_id = req.getParameter("sort_id"); + String position = req.getParameter("position"); + String status = req.getParameter("status"); + String description = req.getParameter("description"); + System.out.println(description+"-------------"); + JSONObject json = new JSONObject(); + //if(id == null || id.equals("")) + Connection connection = null; + PreparedStatement pstmt = null; + //ResultSet resultSet = null; + int result = 0; + String sql = "update books set name=? ,author=? ,library_id=? ,sort_id=? ,position=? ,status=?, description=? where id=?"; + PrintWriter out = resp.getWriter(); + try { + connection = (Connection) Base.getConnection(); + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, name); + pstmt.setString(2, author); + pstmt.setString(3, library_id); + pstmt.setString(4, sort_id); + pstmt.setString(5, position); + pstmt.setString(6, status); + pstmt.setString(7, description); + pstmt.setString(8, id); + result = pstmt.executeUpdate(); + } catch (SQLException e) { + + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + try { + Base.closeResource(connection, pstmt, null); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if(result==1) { + json.put("code", "0"); + json.put("msg", "success"); + }else { + json.put("code", "1"); + json.put("msg", "error"); + } + out.write(json.toString()); + + + + + //System.out.println(postData); + //JSONObject json = JSONObject.fromObject(); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doPost(req, resp); + } + +} diff --git a/src/servlet/admin/BookList.java b/src/servlet/admin/BookList.java index d2a000a..c521544 100644 --- a/src/servlet/admin/BookList.java +++ b/src/servlet/admin/BookList.java @@ -38,7 +38,7 @@ public class BookList extends HttpServlet { String condition = (String) req.getParameter("condition"); String conditionValue = (String) req.getParameter("conditionValue"); Map where = new HashMap(); - System.out.println(condition +"" +conditionValue); + //System.out.println(condition +"" +conditionValue); // 传输数据过滤 if(page == null) { page = "1"; @@ -68,7 +68,6 @@ public class BookList extends HttpServlet { json.put("code", 0); json.put("msg", "success"); json.put("count", map.get("count")); - System.out.println("count: " +map.get("count")); result = "[" +result +"]"; json.put("data", result); } diff --git a/src/servlet/admin/BorrowList.java b/src/servlet/admin/BorrowList.java new file mode 100644 index 0000000..342e2b1 --- /dev/null +++ b/src/servlet/admin/BorrowList.java @@ -0,0 +1,126 @@ +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/borrowList") +public class BorrowList extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 接收参数 + String limit = req.getParameter("limit"); + String page = req.getParameter("page"); + String condition = (String) req.getParameter("condition"); + String conditionValue = (String) req.getParameter("conditionValue"); + String where = ""; // 无限制条件 + if(page == null) { + page = "1"; + } + if(limit == null) { + limit = "10"; + } + // 准备查询 + Connection connection = null; + PreparedStatement pstmt = null; + PreparedStatement countPstmt = null; + ResultSet resultSet = null; + ResultSet countSet = null; + String sql = ""; + String countSql = ""; + // 准备返回参数 + int code = 1; + String msg = "error"; + int count = 0; + + JSONObject jsonData = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonResult = new JSONObject(); + // 进行查询 + try { + connection = (Connection) Base.getConnection(); + sql = "select id, card_id, book_id, " + + "DATE_FORMAT(borrow_date, '%Y-%m-%d %k:%i:%s') as borrow_date, " + + "DATE_FORMAT(return_date, '%Y-%m-%d %k:%i:%s') as return_date, " + + "DATE_FORMAT(end_date, '%Y-%m-%d %k:%i:%s') as end_date," + + "illegal, manager_id " + + "from borrow_books"; + if(condition!=null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) { + where = " where "+ condition +" like '%" +conditionValue +"%' "; + sql += where; + }else if(condition!=null && condition.equals("other")) { + where = " where return_date is null and curtime()>end_date "; + sql +=where; + } + sql += " limit ?,?";//1 10 (1-1)*10; + pstmt = connection.prepareStatement(sql); + pstmt.setInt(1, (Integer.parseInt(page)-1) * Integer.parseInt(limit)); + pstmt.setInt(2, Integer.parseInt(limit)); + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + jsonData.put("id", resultSet.getString("id")); + jsonData.put("card_id", resultSet.getString("card_id")); + jsonData.put("book_id", resultSet.getString("book_id")); + jsonData.put("borrow_date", resultSet.getString("borrow_date")); + jsonData.put("end_date", resultSet.getString("end_date")); + jsonData.put("return_date", resultSet.getString("return_date")); + jsonData.put("illegal", resultSet.getString("illegal")); + jsonData.put("manager_id", resultSet.getString("manager_id")); + jsonArray.add(jsonData); + } + countSql = "select count(*) as count from borrow_books "; + countSql +=where; + countPstmt = connection.prepareStatement(countSql); + countSet = countPstmt.executeQuery(); + if(countSet.next()) { + count = countSet.getInt("count"); + } + if(!jsonArray.isEmpty()) { + code = 0; + msg = "查询成功"; + }else { + code = 0; + msg = "没有数据"; + } + + } catch (ClassNotFoundException e) { + msg = "class没找到"; + } catch (SQLException e) { + msg = "sql错误"; + } finally { + try { + Base.closeResource(null, pstmt, resultSet); + Base.closeResource(connection, countPstmt, countSet); + } catch (SQLException e) { + msg = "关闭资源失败"; + } + + } + // 返回数据 + jsonResult.put("code", code); + jsonResult.put("count", count); + jsonResult.put("msg", msg); + jsonResult.put("data", jsonArray.toArray()); + PrintWriter out = resp.getWriter(); + out.print(jsonResult.toString()); + } + + + +} diff --git a/src/servlet/admin/CardAdd.java b/src/servlet/admin/CardAdd.java new file mode 100644 index 0000000..e7d4ac3 --- /dev/null +++ b/src/servlet/admin/CardAdd.java @@ -0,0 +1,102 @@ +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 java.sql.Connection; + +import javabean.Base; +import javabean.JDBCBean; +import net.sf.json.JSONObject; + +/** + * Servlet implementation class CardAdd + */ +@WebServlet("/admin/cardAdd") +public class CardAdd extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 获取参数 + String reader = req.getParameter("reader"); + String password = req.getParameter("password"); + String rule_id = req.getParameter("rule_id"); + String status = req.getParameter("status"); + // 准备资源 + String code = "1"; + String msg = "error"; + String data = ""; + JSONObject json = new JSONObject(); + JSONObject jsonData = new JSONObject(); + Connection connection = null; + Connection connection1 = null; + PreparedStatement pstmt = null; + PreparedStatement pstmt1 = null; + String sql = null; + int result = 0; + ResultSet dataSet = null; + // 参数不能为空 + if(reader == null || password == null || rule_id == null || rule_id == null || status == null) { + code = "1"; + msg = "值不能为空"; + }else { + try { + connection = (Connection) Base.getConnection(); + sql = "insert into borrow_card(password, reader, rule_id, status) values(?,?,?,?)"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, password); + pstmt.setString(2, reader); + pstmt.setString(3, rule_id); + pstmt.setString(4, status); + result = pstmt.executeUpdate(); + + //获取id + connection1= (Connection) Base.getConnection(); + String findIdSql = "select id from borrow_card where password=? and reader=? and rule_id=? and status=? limit 1"; + pstmt1 = connection1.prepareStatement(findIdSql); + pstmt1.setString(1, password); + pstmt1.setString(2, reader); + pstmt1.setString(3, rule_id); + pstmt1.setString(4, status); + dataSet = pstmt1.executeQuery(); + if(dataSet.next()) { + jsonData.put("id", dataSet.getString("id")); + } + } catch (ClassNotFoundException e) { + msg = "发生异常"; + } catch (SQLException e) { + msg = "sql错误"; + System.out.println("sql失败"); + } + try { + Base.closeResource(connection, pstmt, null); + Base.closeResource(connection1, pstmt1, dataSet); + } catch (SQLException e) { + msg = "关闭资源失败"; + } + if(result == 1 && !jsonData.isNullObject() && !jsonData.isEmpty()) { + System.out.println(jsonData.toString()); //debug + code = "0"; + msg = "添加成功"; + }else { + code = "1"; + msg = "执行失败"; + } + } + json.put("code", code); + json.put("msg", msg); + json.put("data", jsonData.toString()); + PrintWriter out = resp.getWriter(); + out.print(json.toString()); + } + +} diff --git a/src/servlet/admin/CardDel.java b/src/servlet/admin/CardDel.java new file mode 100644 index 0000000..2954b77 --- /dev/null +++ b/src/servlet/admin/CardDel.java @@ -0,0 +1,82 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +@WebServlet("/admin/cardDel") +public class CardDel extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset=utf8"); + // 接收数据 + String id = req.getParameter("id"); + // 处理数据 + Connection connection = null; + PreparedStatement delCardPstmt = null; + PreparedStatement delHistoryPstmt = null; + String delCardSql = null; + String delHistorySql = null; + int delCardResult = 0; + int delHistoryResult = 0; + // 返回数据 + String code = "1"; + String msg = "error"; + JSONObject jsonObject = new JSONObject(); + JSONObject jsonData = new JSONObject(); + // 开始处理 + if(id != null && !id.equals("")) { + try { + // 公共连接 + connection = (Connection) Base.getConnection(); + // 删除借书记录 + delHistorySql = "delete from borrow_books where card_id=?"; + delHistoryPstmt = connection.prepareStatement(delHistorySql); + delHistoryPstmt.setString(1, id); + delHistoryResult = delHistoryPstmt.executeUpdate(); + // 返回删除记录条数 + jsonData.put("num", delHistoryResult); + // 删除阅读证 + delCardSql = "delete from borrow_card where id=? limit 1"; + delCardPstmt = connection.prepareStatement(delCardSql); + delCardPstmt.setString(1, id); + delCardResult = delCardPstmt.executeUpdate(); + + } catch (ClassNotFoundException e) { + msg = "连接失败"; + } catch (SQLException e) { + msg = "sql错误"; + } finally { + try { + delCardPstmt.close(); + Base.closeResource(connection, delCardPstmt, null); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + } + PrintWriter out = resp.getWriter(); + if(delCardResult == 1) { + code = "0"; + msg = "删除借阅证成功"; + } + jsonObject.put("code", code); + jsonObject.put("msg", msg); + jsonObject.put("data", jsonData); + out.print(jsonObject.toString()); + } + +} diff --git a/src/servlet/admin/CardEdit.java b/src/servlet/admin/CardEdit.java new file mode 100644 index 0000000..be7329b --- /dev/null +++ b/src/servlet/admin/CardEdit.java @@ -0,0 +1,80 @@ +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/cardEdit") +public class CardEdit 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 password = req.getParameter("password"); + String reader = req.getParameter("reader"); + String rule_id = req.getParameter("rule_id"); + String status = req.getParameter("status"); + // 准备资源 + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + String sql = null; + // 返回数据 + String code = "1"; + String msg = "error"; + JSONObject json = new JSONObject(); + PrintWriter out = resp.getWriter(); + // 判断数据 + if(id == null || password == null || reader == null || reader == null || status == null || + id.equals("") || password.equals("") || reader.equals("") || rule_id.equals("") || status.equals("")) { + code = "1"; + msg = "参数不能为空"; + }else { + sql = "update borrow_card set password=?, reader=?, rule_id=?, status=? where id=?"; + try { + connection = (Connection) Base.getConnection(); + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, password); + pstmt.setString(2, reader); + pstmt.setString(3, rule_id); + pstmt.setString(4, status); + pstmt.setString(5, id); + result = pstmt.executeUpdate(); + } catch (ClassNotFoundException e1) { + msg = "错误"; + } catch (SQLException e) { + msg = "sql错误"; + } finally { + try { + Base.closeResource(connection, pstmt, resultSet); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + if(result == 1) { + code = "0"; + msg = "修改成功"; + } + json.put("code", code); + json.put("msg", msg); + out.print(json.toString()); + } + } + +} diff --git a/src/servlet/admin/CardList.java b/src/servlet/admin/CardList.java new file mode 100644 index 0000000..592094f --- /dev/null +++ b/src/servlet/admin/CardList.java @@ -0,0 +1,115 @@ +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 java.sql.Connection; + +import javabean.Base; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Servlet implementation class CardList + */ +@WebServlet("/admin/cardList") +public class CardList extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json; charset:utf8"); + // 接收参数 + String limit = req.getParameter("limit"); + String page = req.getParameter("page"); + String condition = (String) req.getParameter("condition"); + String conditionValue = (String) req.getParameter("conditionValue"); + String where = null; // 无限制条件 + if(page == null) { + page = "1"; + } + if(limit == null) { + limit = "10"; + } + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int code = 1; + String msg = "error"; + int count = 0; + String sql = ""; + //String countSql = "" + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonResult = new JSONObject(); + try { + // 获取数据 + connection = (Connection) Base.getConnection(); + sql = "select id,password,reader,rule_id,status from borrow_card"; + // where + if(condition != null && conditionValue != null && !condition.isEmpty() && !conditionValue.isEmpty()) { + where = " where "+ condition +" like '%" +conditionValue +"%'"; + sql = sql+where; + } + // 分页 + sql +=" order by id desc limit ?,?"; + pstmt = connection.prepareStatement(sql); + try { + pstmt.setInt(1, (Integer.parseInt(page)-1) * Integer.parseInt(limit) ); + pstmt.setInt(2, Integer.parseInt(limit)); + } catch (NumberFormatException | SQLException e1) { + } + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + jsonObject.put("id", resultSet.getString("id")); + jsonObject.put("password", resultSet.getString("password")); + jsonObject.put("reader", resultSet.getString("reader")); + jsonObject.put("rule_id", resultSet.getString("rule_id")); + jsonObject.put("status", resultSet.getString("status")); + jsonArray.add(jsonObject); + } + // 获取总数 + sql = "select count(*) as count from borrow_card "; + // 有限制 + if(where!=null) { + sql = sql+where; + } + pstmt = connection.prepareStatement(sql); + resultSet = pstmt.executeQuery(); + if(resultSet.next()) { + count = resultSet.getInt("count"); + } + + if(!jsonArray.isEmpty()) { + code = 0; + msg = "成功"; + } + } catch (ClassNotFoundException e) { + msg = "没找到"; + e.printStackTrace(); + } catch (SQLException e) { + msg = "sql错误"; + }finally { + try { + Base.closeResource(connection, pstmt, resultSet); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + jsonResult.put("code", code); + jsonResult.put("count", count); + jsonResult.put("msg", msg); + jsonResult.put("data", jsonArray.toString()); + PrintWriter out = resp.getWriter(); + out.print(jsonResult.toString()); + //out.print("{\"code\":0,\"msg\":\"\",\"count\":\"234\",\"data\":[{\"id\":\"1\",\"password\":\"23442\",\"reader\":\"minm\",\"rule_id\":\"1\",\"status\":\"2\"}]}"); + } + +} diff --git a/src/servlet/admin/ManagerAdd.java b/src/servlet/admin/ManagerAdd.java new file mode 100644 index 0000000..0375ade --- /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 java.sql.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..9a46cc3 --- /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 java.sql.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..04bf661 --- /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 java.sql.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..f1729e4 --- /dev/null +++ b/src/servlet/admin/ManagerList.java @@ -0,0 +1,65 @@ +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 java.sql.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 new file mode 100644 index 0000000..4f78945 --- /dev/null +++ b/src/servlet/admin/RuleAdd.java @@ -0,0 +1,95 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +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 java.sql.Connection; + +import javabean.Base; +import javabean.Common; +import javabean.Util; + + +@WebServlet("/admin/ruleAdd") +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; + ResultSet resultSet = null; + int result = 0; + String sql = ""; + String borrow_library = ""; + + // 准备返回数据 + int code = 1; + String msg = ""; + + // 获取数据 + // 获取限定图书馆1、2、3 + int num = 0; + try { + Map libraryMap = Common.getLibraryMap(); + System.out.println(libraryMap); + for(String key : libraryMap.keySet()) { + if(req.getParameter("borrow_library[" +key +"]") != null) { + if(num == 0) { + borrow_library += key; + num++; + }else { + borrow_library += "、"+key; + } + } + } + if(borrow_library.isEmpty()) { + msg = "允许图书馆不能为空"; + } + } catch (SQLException e) { + msg = "获取图书馆失败"; + } + String borrow_num = req.getParameter("borrow_num"); + String limit_day = req.getParameter("limit_day"); + String overtime_fee = req.getParameter("overtime_fee"); + try { + connection = (Connection) Base.getConnection(); + sql = "insert into rules(borrow_num, limit_day, borrow_library, overtime_fee) values(?,?,?,?)"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, borrow_num); + pstmt.setString(2, limit_day); + pstmt.setString(3, borrow_library); + pstmt.setString(4, overtime_fee); + result = pstmt.executeUpdate(); + if(result == 1) { + code = 0; + msg = "success"; + } + } catch (ClassNotFoundException e) { + msg = "classnotfound"; + } catch (SQLException e) { + msg = "SQL错误"; + } finally { + try { + Base.closeResource(connection, pstmt, null); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + + PrintWriter out = resp.getWriter(); + out.print(Util.jsonResponse(code, msg, null)); + + } + +} diff --git a/src/servlet/admin/RuleDel.java b/src/servlet/admin/RuleDel.java new file mode 100644 index 0000000..40244a6 --- /dev/null +++ b/src/servlet/admin/RuleDel.java @@ -0,0 +1,59 @@ +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 java.sql.Connection; + +import javabean.Base; +import javabean.Util; + + +@WebServlet("/admin/ruleDel") +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"); + // 准备数据 + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet resultSet = null; + int result = 0; + String sql = ""; + // 返回数据 + int code = 1; + String msg = "error"; + PrintWriter out = resp.getWriter(); + // 进行查询 + try { + connection = (Connection) Base.getConnection(); + sql = "delete from rules 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没找到"; + } catch (SQLException e) { + msg = "sql错误"; + } + out.print(Util.jsonResponse(code, msg, null)); + } + +} diff --git a/src/servlet/admin/RuleEdit.java b/src/servlet/admin/RuleEdit.java new file mode 100644 index 0000000..8e31815 --- /dev/null +++ b/src/servlet/admin/RuleEdit.java @@ -0,0 +1,101 @@ +package servlet.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +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 java.sql.Connection; + +import javabean.Base; +import javabean.Common; +import javabean.Util; + +/** + * Servlet implementation class RuleEdit + */ +@WebServlet("/admin/ruleEdit") +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; + ResultSet resultSet = null; + int result = 0; + String sql = ""; + String borrow_library = ""; + + // 准备返回数据 + int code = 1; + String msg = ""; + + // 获取数据 + // 获取限定图书馆1、2、3 + int num = 0; + try { + Map libraryMap = Common.getLibraryMap(); + System.out.println(libraryMap); + for(String key : libraryMap.keySet()) { + if(req.getParameter("borrow_library[" +key +"]") != null) { + if(num == 0) { + borrow_library += key; + num++; + }else { + borrow_library += "、"+key; + } + } + } + if(borrow_library.isEmpty()) { + msg = "允许图书馆不能为空"; + } + } catch (SQLException e) { + msg = "获取图书馆失败"; + } + String borrow_num = req.getParameter("borrow_num"); + String limit_day = req.getParameter("limit_day"); + String overtime_fee = req.getParameter("overtime_fee"); + String id = req.getParameter("id"); + try { + connection = (Connection) Base.getConnection(); + sql = "update rules set borrow_num=?, limit_day=?, borrow_library=?,overtime_fee=? where id=?"; + pstmt = connection.prepareStatement(sql); + pstmt.setString(1, borrow_num); + pstmt.setString(2, limit_day); + pstmt.setString(3, borrow_library); + pstmt.setString(4, overtime_fee); + pstmt.setString(5, id); + result = pstmt.executeUpdate(); + if(result == 1) { + code = 0; + msg = "success"; + } + } catch (ClassNotFoundException e) { + msg = "classnotfound"; + } catch (SQLException e) { + msg = "SQL错误"; + } finally { + try { + Base.closeResource(connection, pstmt, null); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + + PrintWriter out = resp.getWriter(); + out.print(Util.jsonResponse(code, msg, null)); + + + + } + +} diff --git a/src/servlet/admin/RuleList.java b/src/servlet/admin/RuleList.java new file mode 100644 index 0000000..35dc2db --- /dev/null +++ b/src/servlet/admin/RuleList.java @@ -0,0 +1,73 @@ +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 java.sql.Connection; + +import javabean.Base; +import javabean.Util; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + + +@WebServlet("/admin/ruleList") +public class RuleList 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; + ResultSet resultSet = null; + String sql = ""; + // 准备返回参数 + int code = 1; + String msg = "error"; + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + try { + connection = (Connection) Base.getConnection(); + sql = "select * from rules"; + pstmt = connection.prepareStatement(sql); + resultSet = pstmt.executeQuery(); + while(resultSet.next()) { + jsonObject.put("id", resultSet.getString("id")); + jsonObject.put("limit_day", resultSet.getString("limit_day")); + jsonObject.put("borrow_num", resultSet.getString("borrow_num")); + jsonObject.put("borrow_library", resultSet.getString("borrow_library")); + jsonObject.put("overtime_fee", resultSet.getString("overtime_fee")); + jsonArray.add(jsonObject); + } + code = 0; + if(!jsonArray.isEmpty()) { + msg = "查询成功"; + }else { + msg = "没有数据"; + } + } catch (SQLException e) { + msg = "sql错误"; + } catch (ClassNotFoundException e) { + msg = "class没找到"; + } finally { + try { + Base.closeResource(connection, pstmt, resultSet); + } catch (SQLException e) { + msg = "关闭失败"; + } + } + + PrintWriter out = resp.getWriter(); + out.print( Util.jsonResponse(code, msg, jsonArray.toString()) ); + } + +}