You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Library/Radmin.md

3867 lines
113 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
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 javax.servlet.http.HttpSession;
import javabean.Admin;
import net.sf.json.JSONObject;
/**
* 管理员登录
*
* @author Mingyue
*
*/
@WebServlet("/adminLogin")
public class AdminLogin extends HttpServlet {
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 {
// 设置头文件
response.setContentType("application/json; charset=utf8");
PrintWriter out = response.getWriter();
// 获取账号密码
String username = request.getParameter("username");
String password = request.getParameter("password");
// 设置响应map
HashMap<String, Object> hashMap = new HashMap<String, Object>();
Admin admin = new Admin();
String result = null;
try {
result = admin.login(username, password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
if (result != null && result.equals("1")) {
HttpSession session = request.getSession();
session.setAttribute("admin", username);
hashMap.put("code", 0);
hashMap.put("msg", "登录成功");
hashMap.put("url", request.getContextPath() +"/admin/index.jsp");
}else {
hashMap.put("code", 1);
hashMap.put("msg", result);
}
JSONObject json = JSONObject.fromObject(hashMap);
out.write(json.toString());
}
}
//bookadd
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());
}
}
//bookdel
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() );
}
}
//bookedit
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);
}
}
//booklist
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
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 javabean.Admin;
import javabean.Common;
import javabean.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* Servlet implementation class BookList
*/
@WebServlet("/admin/bookList")
public class BookList extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json; charset=utf8");
JSONObject json = new JSONObject();
String result = null;
Map<String, Object> map = null;
int code = 1;
String msg = "";
String data = "";
String page = (String) req.getParameter("page");
String limit = (String) req.getParameter("limit");
String condition = (String) req.getParameter("condition");
String conditionValue = (String) req.getParameter("conditionValue");
Map where = new HashMap<String, String>();
// 传输数据过滤
if(page == null) {
page = "1";
}
if(limit == null) {
limit = "10";
}
if(condition == null || conditionValue == null || condition.isEmpty() || conditionValue.isEmpty()) {
condition = null;
conditionValue = null;
}else {
where.put("condition", condition);
where.put("conditionValue", conditionValue);
}
Admin admin = new Admin();
try {
map = admin.getBookList(page, limit, where);
result = (String) map.get("data");
} catch (ClassNotFoundException | SQLException e) {
msg = "数据库获取信息失败";
}
if(result == null || result.isEmpty() || result.equals("1")) {
json.put("code", 1);
json.put("msg", "数据为空");
} else {
json.put("code", 0);
json.put("msg", "success");
json.put("count", map.get("count"));
result = "[" +result +"]";
json.put("data", result);
}
PrintWriter out = resp.getWriter();
out.print(json.toString());
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
//borrowlist
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 ?,?";
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());
}
}
//cardadd
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());
}
}
//carddel
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());
}
}
//cardedit
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());
}
}
}
//cardlist
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 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\"}]}");
}
}
//librarydata
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javabean.Base;
import javabean.DateTime;
import javabean.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@WebServlet("/admin/libraryData")
public class LibraryData extends HttpServlet {
private static final long serialVersionUID = 1L;
@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 = "";
JSONObject jsonObject = new JSONObject();
JSONArray jsonData = new JSONArray();
JSONArray jsonDays = new JSONArray();
// 返回参数
int code = 1;
String msg = "error";
int count = 0;
PrintWriter out = resp.getWriter();
// 开始查询
try {
connection = Base.getConnection();
int i = 30;
// 获取30天
while(i!=0) {
i--;
sql = "select count(*) as count from borrow_books where date_format(borrow_date,'%Y-%m-%d')=? order by id desc";
String date = DateTime.showDate(-i); // 设置日期
String md = DateTime.showMD(-i);
pstmt = connection.prepareStatement(sql);
pstmt.setString(1,date);
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
jsonData.add(resultSet.getString("count"));
jsonDays.add(md);
}
}
jsonObject.put("data", jsonData);
jsonObject.put("days", jsonDays);
if(!jsonObject.isEmpty()) {
code = 0;
msg = "查询成功";
}else {
msg = "数据为空";
}
} catch (ClassNotFoundException e) {
msg = "没找到";
e.printStackTrace();
} catch (SQLException e) {
msg = "sql错误";
}finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
out.print( Util.jsonResponse(code, msg, jsonObject.toString()) );
}
}
//loginout
package servlet.admin;
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;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class LoginOut
*/
@WebServlet("/admin/logOut")
public class LoginOut extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = req.getSession();
if(session.getAttribute("admin") != null) {
session.removeAttribute("admin");
}
resp.sendRedirect(req.getContextPath() +"/adminLogin.html");
}
}
//manageradd
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));
}
}
}
//managerdel
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 {
resp.setContentType("application/json; charset=utf8");
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));
}
}
//manageredit
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));
}
}
}
//managerlist
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()));
}
}
//ruleadd
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<String, String> libraryMap = Common.getLibraryMap();
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));
}
}
//ruledel
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));
}
}
//ruleedit
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<String, String> libraryMap = Common.getLibraryMap();
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));
}
}
//rulelist
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()) );
}
}
//sortadd
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javabean.Base;
import javabean.Common;
import javabean.Util;
@WebServlet("/admin/sortAdd")
public class SortAdd 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 description = req.getParameter("description");
// 准备数据
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
int result = 0;
String sql = "";
int count = 0 ;
// 准备返回数据
int code = 1;
String msg = "";
try {
connection = (Connection) Base.getConnection();
// 查询重复name
sql = "select count(*) as count from book_sort where name=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
resultSet = pstmt.executeQuery();
if(resultSet.next()) {
// 有重复
if(resultSet.getInt("count") > 0) {
msg = "分类名不能重复";
}else {
// 进行插入
sql = "insert into book_sort(name, description) values(?,?)";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, description);
result = pstmt.executeUpdate();
if(result == 1) {
code = 0;
msg = "添加成功";
}else {
msg = "添加失败";
}
}
}
} catch (ClassNotFoundException e) {
msg = "classnotfound";
} catch (SQLException e) {
msg = "SQL错误";
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
PrintWriter out = resp.getWriter();
out.print(Util.jsonResponse(code, msg, null));
}
}
//sortdel
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javabean.Base;
import javabean.Util;
@WebServlet("/admin/sortDel")
public class SortDel extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 默认1为未分类
String defaultId = "1";
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 = "";
try {
// 不能删除未分类
if(defaultId.equals(id)) {
msg = "不能删除未分类";
}else {
connection = (Connection) Base.getConnection();
// 分类下的文章修改
sql = "update books set sort_id=? where sort_id=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, defaultId);
pstmt.setString(2, id);
result = pstmt.executeUpdate();
// 进行删除
sql = "delete from book_sort 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 = "classnotfound";
} catch (SQLException e) {
msg = "SQL错误";
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
PrintWriter out = resp.getWriter();
out.print(Util.jsonResponse(code, msg, null));
}
}
//sortedit
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javabean.Base;
import javabean.Util;
@WebServlet("/admin/sortEdit")
public class SortEdit 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 description = req.getParameter("description");
// 准备数据
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
int result = 0;
String sql = "";
int count = 0 ;
// 准备返回数据
int code = 1;
String msg = "";
try {
connection = (Connection) Base.getConnection();
// 查询重复name
sql = "select count(*) as count from book_sort where name=? and id != ?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, id);
resultSet = pstmt.executeQuery();
if(resultSet.next()) {
// 有重复
if(resultSet.getInt("count") > 0) {
msg = "分类名不能重复";
}else {
// 进行插入
sql = "update book_sort set name=?, description=? where id=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, description);
pstmt.setString(3, id);
result = pstmt.executeUpdate();
if(result == 1) {
code = 0;
msg = "修改成功";
}else {
msg = "修改失败";
}
}
}
} catch (ClassNotFoundException e) {
msg = "classnotfound";
} catch (SQLException e) {
msg = "SQL错误";
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
PrintWriter out = resp.getWriter();
out.print(Util.jsonResponse(code, msg, null));
}
}
//sortlist
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javabean.Base;
import javabean.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@WebServlet("/admin/sortList")
public class SortList 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;
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
// 返回参数
int code = 1;
String msg = "error";
int count = 0;
String sql = "";
PrintWriter out = resp.getWriter();
// 开始查询
try {
connection = Base.getConnection();
sql = "select * from book_sort";
pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery();
while (resultSet.next()) {
jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("name", resultSet.getString("name"));
jsonObject.put("description", resultSet.getString("description"));
jsonArray.add(jsonObject.toString());
}
if (!jsonArray.isEmpty()) {
code = 0;
msg = "查询成功";
} else {
msg = "数据为空";
}
} catch (ClassNotFoundException e) {
msg = "没找到";
e.printStackTrace();
} catch (SQLException e) {
msg = "sql错误";
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
out.print(Util.jsonResponse(code, msg, jsonArray.toString()));
}
}
//updatepassword
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javax.servlet.http.HttpSession;
import javabean.Base;
import javabean.Util;
import net.sf.json.JSONObject;
@WebServlet("/admin/updatePassword")
public class UpdatePassword extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json; charset=utf8");
// 接受数据
String oldPassword = req.getParameter("oldPassword");
String newPassword = req.getParameter("newPassword");
String conPassword = req.getParameter("conPassword");
HttpSession session = req.getSession();
String username = (String) session.getAttribute("admin");
// 准备资源
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
int result = 0;
String sql = null;
int count = 0;
// 返回数据
int code = 1;
String msg = "error";
JSONObject json = new JSONObject();
PrintWriter out = resp.getWriter();
// 可靠性
if(conPassword.equals(newPassword)) {
// 查询
try {
connection = Base.getConnection();
// 验证账号密码
sql = "select count(*) as count from admin where username=? and password=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, Util.passMd5(oldPassword));
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
count = resultSet.getInt("count");
}
// 修改密码
// 密码正确
if(count >= 1) {
sql = "update admin set password=? where username=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, Util.passMd5(newPassword));
pstmt.setString(2, username);
result = pstmt.executeUpdate();
if(result == 1) {
code = 0;
msg = "修改成功";
}else {
msg = "修改失败";
}
}else {
msg = "密码错误";
}
} catch (ClassNotFoundException e) {
msg = "class notfound";
} catch (SQLException e) {
msg = "sql错误";
} finally {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
msg = "关闭失败";
}
}
}else {
msg = "两次密码不一致";
}
out.print(Util.jsonResponse(code, msg, null));
}
}
//JS部分
//bookadd
<%@page import="java.sql.ResultSet"%>
<%@page import="javabean.JDBCBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>bookadd</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</style>
</head>
<body>
<%
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 );
%>
<form class="layui-form layui-form-pane" action="">
<input type="id" name="id" value="3" class="layui-hide">
<div class="layui-form-item">
<label class="layui-form-label">书名</label>
<div class="layui-input-block">
<input type="text" name="name" required="" lay-verify="required" placeholder="请输入书名" autocomplete="off" class="layui-input">
</div>
</div>
<!-- 作者 -->
<div class="layui-form-item">
<label class="layui-form-label">作者</label>
<div class="layui-input-block">
<input type="text" name="author" required lay-verify="required" placeholder="请输入作者" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">图书馆</label>
<div class="layui-input-block">
<select name="library_id" lay-verify="required">
<option value=""></option>
<% while( librarySet.next() ){ %>
<option value=<%=librarySet.getString("id") %> ><%=librarySet.getString("name") %></option>
<%} %>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-block">
<select name="sort_id" lay-verify="required">
<option value=""></option>
<% while(bookSortSet.next()){ %>
<option value=<%=bookSortSet.getInt("id") %> ><%=bookSortSet.getString("name") %></option>
<%} %>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">位置</label>
<div class="layui-input-block">
<input type="text" name="position" required="" lay-verify="required" placeholder="请输入位置编号" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="1" title="可借" checked="checked"><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>可借</div></div>
<input type="radio" name="status" value="0" title="不可借"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>不可借</div></div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">书籍简介</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="description" lay-verify="content" id="LAY_demo_editor"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="bookForm">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'layedit', 'jquery'], function(){
//layer.closeAll();
$ = layui.jquery;
var form = layui.form
,layer = layui.layer
,layedit = layui.layedit;
/**
* 因为富文本存在xss注入以下代码不用了如果需要可以开启
*/
/*
var editIndex = layedit.build('LAY_demo_editor');
// 自定义验证规则
form.verify({
// 解决富文本异步传输问题
content: function(value){
return layedit.sync(editIndex);
}
})
*/
//监听提交
form.on('submit(bookForm)', function(data){
$.ajax({
url: './bookAdd',
method: 'post',
data: data.field, //JSON.stringify(data.field),
dataType: 'JSON',
success: function(data){
if(data.code == "0"){
parent.layer.msg("添加成功",{
icon: 6,
time: 500
});
setTimeout(function(){
//parent.location.reload();
var index = parent.layer.getFrameIndex(window.name); //操作父页面
parent.layer.close(index);
}, 500);
}else{
leyer.msg("添加失败");
}
}
})
return false;
});
});
</script>
</body>
</html>
//borrowlist
<%@page import="javabean.Util"%>
<%@page import="javabean.Base"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>书籍借阅历史</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<script src="../public/layui/layui.js" charset="utf-8"></script>
<style>
.layui-table, .layui-table-view{
margin-top: 0px;
}
</style>
</head>
<body>
<%
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"));
}*/
%>
<div class="layui-form">
<table class="layui-table">
<colgroup>
<col width="150">
<col width="150">
<col width="200">
<col width="200">
<col width="200">
<col width="200">
<col width="220">
<col width="200">
<col width="200">
</colgroup>
<thead>
<tr>
<th>ID</th>
<th>书籍ID</th>
<th>书籍名</th>
<th>借阅证</th>
<th>借阅者</th>
<th>借阅时间</th>
<th>归还时间</th>
<th>违规信息</th>
<th>处理人</th>
</tr>
<%while(resultSet.next()){ %>
<tr>
<td><%=resultSet.getString("id") %></td>
<td><%=id %></td>
<td><%=name %></td>
<td><%=resultSet.getString("borrow_card.id") %></td>
<td><%=resultSet.getString("reader") %></td>
<td><%=Util.getFormatDateTime(resultSet.getString("borrow_date")) %></td>
<td><%=resultSet.getString("return_date") != null? Util.getFormatDateTime(resultSet.getString("return_date")) : "" %></td>
<td><%=resultSet.getString("illegal") != null? resultSet.getString("illegal") : "" %></td>
<td><%=resultSet.getString("manager_id") != null? resultSet.getString("manager_id") : "" %></td>
</tr>
<%} %>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
</body>
</html>
//edit
<%@page import="javabean.JDBCBean"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="javabean.Admin"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>bookedit</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</head>
<body>
<%
JDBCBean db = new JDBCBean();
int id = Integer.parseInt(request.getParameter("id"));
ResultSet resultSet = null;
ResultSet librarySet = null;
ResultSet bookSortSet = null;
String sql = "select * from books where id=" +id ;
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");
int status = resultSet.getInt("status");
String description = resultSet.getString("description");
db.close();
// 获取图书馆列表
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 );
%>
<form class="layui-form layui-form-pane" action="">
<%-- 隐藏id --%>
<input type="id" name="id" value=<%=id %> class="layui-hide">
<!-- 书名 -->
<div class="layui-form-item">
<label class="layui-form-label">书名</label>
<div class="layui-input-block">
<input type="text" name="name" value=<%=name %> required lay-verify="required" placeholder="请输入书名" autocomplete="off" class="layui-input">
</div>
</div>
<!-- 作者 -->
<div class="layui-form-item">
<label class="layui-form-label">作者</label>
<div class="layui-input-block">
<input type="text" name="author" value=<%=author %> required lay-verify="required" placeholder="请输入作者" autocomplete="off" class="layui-input">
</div>
</div>
<!-- 图书馆 -->
<div class="layui-form-item">
<label class="layui-form-label">图书馆</label>
<div class="layui-input-block">
<select name="library_id" lay-verify="required">
<option value=""></option>
<% while( librarySet.next() ){ %>
<%-- 选中原来的 图书馆--%>
<option value=<%=librarySet.getString("id") %> <%if(Integer.parseInt(librarySet.getString("id")) == library_id){ out.print("selected"); } %> ><%=librarySet.getString("name") %></option>
<%} %>
</select>
</div>
</div>
<!-- 分类 -->
<div class="layui-form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-block">
<select name="sort_id" lay-verify="required">
<option value=""></option>
<% while(bookSortSet.next()){ %>
<option value=<%=bookSortSet.getInt("id") %> <% if(bookSortSet.getInt("id") == sort_id) out.print("selected"); %>><%=bookSortSet.getString("name") %></option>
<%} %>
</select>
</div>
</div>
<!-- 位置 -->
<div class="layui-form-item">
<label class="layui-form-label">位置</label>
<div class="layui-input-block">
<input type="text" name="position" value=<%=position %> required lay-verify="required" placeholder="请输入位置编号" autocomplete="off" class="layui-input">
</div>
</div>
<!-- 位置 -->
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="1" title="可借" <%if(status==1) out.print("checked"); %>>
<input type="radio" name="status" value="0" title="不可借" <%if(status==0) out.print("checked"); %> >
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">书籍简介</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="description" lay-verify="content" id="LAY_demo_editor"><%=description %></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'layedit', 'jquery'], function(){
//layer.closeAll();
$ = layui.jquery;
var form = layui.form
,layer = layui.layer
,layedit = layui.layedit;
/**
* 因为富文本存在xss注入以下代码不用了如果需要可以开启
*/
/*
var editIndex = layedit.build('LAY_demo_editor');
// 自定义验证规则
form.verify({
// 解决异步传输问题
content: function(value){
return layedit.sync(editIndex);
}
})
*/
//监听提交
form.on('submit(formDemo)', function(data){
$.ajax({
url: './bookEdit',
method: 'post',
data: data.field, //JSON.stringify(data.field),
dataType: 'json',
success: function(data){
if(data.code == "0"){
parent.layer.msg("修改成功",{
icon: 6,
time: 500
});
setTimeout(function(){
var index = parent.layer.getFrameIndex(window.name); //操作父页面
parent.layer.close(index);
}, 500);
}else{
leyer.msg("修改失败");
}
}
})
return false;
});
});
</script>
<%
// 关闭资源
bookSortSet.close();
librarySet.close();
resultSet.close();
db.close();
%>
</body>
</html>
//list
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="javabean.JDBCBean"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-table, .layui-table-view{
margin-top: 0px;
}
</style>
</head>
<body>
<%
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();
%>
<!-- 搜索框 -->
<script type="text/html" id="search">
<div class="demoTable">
条件搜索
<div class="layui-inline">
<select id="condition" name="condition" lay-verify="required">
<option value=""></option>
<option value="id">ID</option>
<option value="name">书名</option>
<option value="author">作者</option>
<option value="library_id">图书馆</option>
<option value="position">位置</option>
<option value="status">状态</option>
<option value="description">描述</option>
</select>
</div>
<div class="layui-inline">
<input class="layui-input" name="conditionValue" id="conditionValue" autocomplete="off" placeholder="请输入搜索内容">
</div>
<button class="layui-btn" data-type="reload" lay-event="search">搜索</button>
<button type="button" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">添加书籍</i></button>
</div>
</script>
<!-- 表单 -->
<table id="demo" lay-filter="form">
</table>
<!-- 行操作 -->
<script type="text/html" id="operateBar">
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="bookBorrowList">查看借阅</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
// 图书馆json
var libraryJson = <%=libraryJson %>
// 图书分类json
var bookSortJson = <%=bookSortJson %>
</script>
<!-- 状态模板 -->
<script type="text/html" id="statusTpl">
{{# if(d.status == 1){ }}
<span style="color:#5FB878;">可借</span>
{{# } else { }}
借出
{{# } }}
</script>
<script>
layui.use(['table', 'jquery'],function(){
$ = layui.jquery;
var table = layui.table;
var tableIns = table.render({
elem: '#demo'
,height: 600
,url: './bookList'
,title: '数据表单'
,toolbar: '#search'
,page: true
,cols: [[
{type: 'numbers', width:50, fixed:'left'}
,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
,{field: 'name', title: '书名', width:170, sort: true}
,{field: 'author', title: '作者', width: 140, sort: true}
,{field: 'library_id', title: '图书馆†', width:80, edit: true //,templet: '#libraryTemp'}
,templet: function(d){
return libraryJson[d.library_id];
}}
,{field: 'sort_id', title: '分类', width: 80, sort: true, edit:true
,templet: function(d){
return bookSortJson[d.sort_id];
}}
,{field: 'position', title: '位置', width: 110, sort: true}
,{field: 'status', title: '状态', width: 60, templet:'#statusTpl'}
,{field: 'description', title: '描述', width: 340}
,{fixed: 'right', title:'操作', width: 200, align:'center', toolbar: '#operateBar'} //这里的toolbar值是模板元素的选择器
]]
});
// 直接编辑
table.on('edit(form)', function(obj){ //注edit是固定事件名test是table原始容器的属性 lay-filter="对应的值"
console.log(obj.value); //得到修改后的值
console.log(obj.field); //当前编辑的字段名
console.log(obj.data); //所在行的所有相关数据
});
// 监听侧边工具条 编辑,删除
table.on('tool(form)', function(obj){ //注tool 是工具条事件名test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的 DOM 对象(如果有的话)
var id = data.id;
var name = data.name;
if(layEvent === 'del'){ //删除
layer.confirm('真的删除行么', function(index){
layer.close(index);
//向服务端发送删除指令
$.ajax({
url: './bookDel',
method: 'get',
dataType: 'JSON',
data: "id=" +id,
success: function(data){
if(data.code == 0){
layer.msg(data.msg);
$('.layui-laypage-btn').click();
}else{
layer.msg(data.msg);
}
}
})
});
} else if(layEvent === 'edit'){ //编辑
// 页面编辑
layer.open({
type: 2,
title: "更改信息",
area: ['800px', '600px'],
maxmin: true, //开启最大化最小化按钮
shadeClose: true,
content: "bookedit.jsp?id="+ id,
end: function(){
$(".layui-laypage-btn").click();
}
});
}else if(layEvent === 'bookBorrowList') { //查看该书籍借阅历史
layer.open({
title: '书籍借阅历史',
type: 2,
area: ['800px', '600px'],
maxmin: true,
shadeClose: true,
content: "bookborrowlist.jsp?id=" +id +"&name="+name
})
}
});
// 顶部工具栏事件
table.on('toolbar(form)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
var data = obj.data;
switch(obj.event){
// 条件查找
case 'search':
var conditionValue = $('#conditionValue');
var condition = $('#condition');
//这里以搜索为例
tableIns.reload({
where: { //设定异步数据接口的额外参数,任意设
"condition": condition.val(),
"conditionValue": conditionValue.val()
}
,page: {
curr: 1 //重新从第 1 页开始
}
});
break;
// 添加书籍
case 'add':
var addBookLayer = layer.open({
type: 2,
title: "添加书籍",
area: ['800px', '600px'],
maxmin: true, //开启最大化最小化按钮
shadeClose: true,
content: "bookadd.jsp",
end: function () {
console.log("finish add");
$(".layui-laypage-btn").click();
}
});
layer.full(addBookLayer);
break;
};
});
});
</script>
</body>
</html>
//list1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-table{
margin-top: 0px;
}
</style>
</head>
<body>
<table id="demo" lay-filter="test">
</table>
<script type="text/html" id="operate">
<button type="button" class="layui-btn layui-btn-warm">修改</button>
<button type="button" class="layui-btn layui-btn-danger">删除</button>
</script>
<script>
layui.use('table', function(){
var table = layui.table;‹
table.render({
elem: '#demo'
,height: 600
//,url: './data.json'
,url: './bookList'
,title: '数据表单'
,toolbar: true
,page: true
,size: 'lg'
,cols: [[
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
,{field: 'name', title: '姓名', width:120}
,{field: 'library_name', title: '图书馆†', width:80}
,{field: 'sort_id', title: '分类', width: 177}
,{field: 'position_id', title: '位置', width: 80, sort: true}
,{field: 'state', title: '状态', width: 80, sort: true}
,{field: 'descript', title: '描述', width: 80}
,{field: 'operate', title: '操作', width: 200, templet: '#operate'}
]]
});
});
</script>
</table>
</body>
</html>
//borrowlist
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅记录</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<style>
.layui-table,.layui-table-view{
margin: 0 0px;
}
</style>
</head>
<body>
<script src="../public/layui/layui.js" charset="utf-8"></script>
<!-- 表单 -->
<table class="layui-hide" id="history" lay-filter="formFilter"></table>
<!-- 头部工具栏 -->
<script type="text/html" id="headBar">
条件搜索
<div class="layui-inline">
<select id="condition" name="condition" lay-verify="required">
<option value=""></option>
<option value="other">超期未还</option>
<option value="id">ID</option>
<option value="card_id">借阅证号</option>
<option value="book_id">书籍ID</option>
<option value="borrow_date">借阅日期</option>
<option value="end_date">限制日期</option>
<option value="return_date">返还日期</option>
<option value="illegal">违章信息</option>
<option value="manager_id">处理人</option>
</select>
</div>
<div class="layui-inline">
<input class="layui-input" id="conditionValue" name="conditionValue" id="demoReload" autocomplete="off">
</div>
<button class="layui-btn" name="condition" data-type="reload" lay-event="search">搜索</button>
</script>
<script>
layui.use(['table','jquery'], function(){
$ = layui.jquery;
var table = layui.table;
// 进行渲染
var tableIns = table.render({
elem: '#history'
,url:'./borrowList'
,toolbar: '#headBar'
,cols: [[
{field:'id', width:80, title: 'ID', sort: true}
,{field:'card_id', width:180, title: '借阅证号'}
,{field:'book_id', width:100, title: '书籍ID', sort: true}
,{field:'borrow_date', width:180, title: '借阅时间'}
,{field:'end_date', title: '限定时间', width: 180}
,{field:'return_date', width:180, title: '归还时间', sort: true}
,{field:'illegal', minWidth:280, title: '违章信息', sort: true}
,{field:'manager_id', width:80, title: '处理人'}
]]
,page: true
});
// 头部工具栏事件
table.on('toolbar(formFilter)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
// 条件查找图书证
case 'search':
var conditionValue = $('#conditionValue');
var condition = $('#condition');
// 进行搜索,重新渲染
tableIns.reload({
where: { //设定异步数据接口的额外参数,任意设
"condition": condition.val(),
"conditionValue": conditionValue.val()
}
,page: {
curr: 1 //重新从第 1 页开始
}
});
break;
};
});
});
</script>
</body>
</html>
//cardadd
<%@page import="javabean.Base"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书证修改</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<script src="../public/layui/layui.js" charset="utf-8"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</head>
<body>
<%
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();
%>
<form class="layui-form layui-form-pane" action="" lay-filter="cardFilter">
<!-- 姓名 -->
<div class="layui-form-item">
<label class="layui-form-label">姓名</label>
<div class="layui-input-block">
<input type="text" name="reader" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
</div>
</div>
<!-- 密码 -->
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input" lay-verify="required">
</div>
</div>
<!-- 借阅规则 -->
<div class="layui-form-item">
<label class="layui-form-label">规则</label>
<div class="layui-input-block">
<select name="rule_id" lay-filter="rule_id" lay-verify="required">
<% while(ruleSet.next()){ %>
<option value=<%=ruleSet.getString("id") %>><%=ruleSet.getString("id") %></option>
<%} %>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="1" title="可用" checked="">
<input type="radio" name="status" value="0" title="挂失">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="submitForm">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'jquery'], function(){
var form = layui.form
,layer = layui.layer;
$ = layui.jquery;
// 提交表单
form.on('submit(submitForm)', function(data){
$.ajax({
url: './cardAdd',
method: 'post',
data: data.field,
dataType: 'json',
success: function(data){
if(data.code == "0"){
parent.layer.open({
title: '注册账号为',
content: data.data['id'],
end: function(){
//parent.location.reload();
var index = parent.layer.getFrameIndex(window.name); //操作父页面
parent.layer.close(index);
}
});
/*setTimeout(function(){
}, 500);*/
}else{
leyer.msg("添加失败");
}
}
});
return false;
})
});
</script>
</body>
</html>
//borrow
<%@page import="javabean.Util"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>借阅证借阅记录</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<script src="../public/layui/layui.js" charset="utf-8"></script>
<style>
.layui-table,.layui-table-view{
margin: 0 0px;
}
</style>
</head>
<body>
<%
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();
%>
<div class="layui-form">
<table class="layui-table">
<colgroup>
<col width="150">
<col width="150">
<col width="200">
<col width="200">
<col width="200">
<col width="200">
<col width="220">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>ID</th>
<th>书籍ID</th>
<th>书籍名</th>
<th>借阅时间</th>
<th>截止时间</th>
<th>归还时间</th>
<th>违规信息</th>
<th>处理人</th>
</tr>
</thead>
<tbody>
<%
System.out.println(Util.getCurrentTimeString());
%>
<% while(resultSet.next()){ %>
<%-- 图书超期 --%>
<%if(Util.getFormatDateTime(resultSet.getString("end_date")).compareTo(Util.getCurrentTimeString()) < 0 && resultSet.getString("return_date") == null){ %>
<tr style="color:#FF5722;">
<%} else{ %>
<tr>
<%} %>
<td><%=resultSet.getString("card_id") %></td>
<td><%=resultSet.getString("book_id") %></td>
<td><%=resultSet.getString("books.name") %></td>
<td><%=Util.getFormatDateTime(resultSet.getString("borrow_date")) %></td>
<td><%=Util.getFormatDateTime(resultSet.getString("end_date"))%></td>
<td><%=resultSet.getString("return_date")!=null?Util.getFormatDateTime(resultSet.getString("return_date")) : "未归还" %></td>
<td><%=resultSet.getString("illegal")!=null?resultSet.getString("illegal"):""%></td>
<td><%=resultSet.getString("manager_id")!=null?resultSet.getString("manager_id"):"" %></td>
</tr>
<%} %>
</tbody>
</table>
</div>
</body>
</html>
//edit
<%@page import="javabean.Base"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书证修改</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<script src="../public/layui/layui.js" charset="utf-8"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</head>
<body>
<%
// 获取借阅证信息
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();
%>
<form class="layui-form layui-form-pane" action="" lay-filter="cardFilter">
<!-- 账号 -->
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" name="id" value=<%=id %> class="layui-input" disabled>
</div>
</div>
<!-- 姓名 -->
<div class="layui-form-item">
<label class="layui-form-label">姓名</label>
<div class="layui-input-block">
<input type="text" name="reader" value=<%=infoSet.getString("reader") %> lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
</div>
</div>
<!-- 密码 -->
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" value=<%=infoSet.getString("password") %> placeholder="请输入密码" autocomplete="off" class="layui-input" lay-verify="required">
</div>
</div>
<!-- 借阅规则 -->
<div class="layui-form-item">
<label class="layui-form-label">规则</label>
<div class="layui-input-block">
<select name="rule_id" lay-filter="rule_id" lay-verify="required">
<% while(ruleSet.next()){ %>
<option value=<%=ruleSet.getString("id") %> <%if(ruleSet.getString("id").equals(infoSet.getString("rule_id"))) out.print("selected"); %>><%=ruleSet.getString("id") %></option>
<%} %>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="1" title="可用" <%if(infoSet.getString("status").equals("1")) out.print("checked"); %>>
<input type="radio" name="status" value="0" title="挂失" <%if(infoSet.getString("status").equals("0")) out.print("checked"); %>>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="submitForm">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'jquery'], function(){
var form = layui.form
,layer = layui.layer;
$ = layui.jquery;
// 提交表单
form.on('submit(submitForm)', function(data){
$.ajax({
url: './cardEdit',
type: 'post',
data: data.field,
dataType: 'json',
timeout : 3000,
success: function(data){
if(data.code == "0"){
layer.msg("修改成功", {
icon: 6,
anim: 5,
time: 500,
});
setTimeout(function(){
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
parent.layer.close(index); //再执行关闭
}, 500)
}else{
leyer.msg("修改失败");
}
},
error: function(){
layer.msg("获取超时");
}
});
return false;
})
});
</script>
<%
Base.closeResource(connection, pstmt, ruleSet);
%>
</body>
</html>
//list
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅卡</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<style>
.layui-table,.layui-table-view{
margin: 0 0px;
}
</style>
</head>
<body>
<!-- 表单 -->
<table class="layui-hide" id="cardTable" lay-filter="formFilter"></table>
<script src="../public/layui/layui.js" charset="utf-8"></script>
<!-- 头部工具栏 -->
<script type="text/html" id="headBar">
条件搜索
<div class="layui-inline">
<select id="condition" name="condition" lay-verify="required">
<option value=""></option>
<option value="id">ID</option>
<option value="reader">姓名</option>
<option value="rule_id">借阅规则</option>
<option value="status">状态</option>
</select>
</div>
<div class="layui-inline">
<input class="layui-input" id="conditionValue" name="conditionValue" id="demoReload" autocomplete="off" placeholder="请输入搜索内容">
</div>
<button class="layui-btn" name="condition" data-type="reload" lay-event="search">搜索</button>
<button type="button" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">添加借阅证</i></button>
</script>
<!-- 表格侧边栏的操作 -->
<script type="text/html" id="operateBar">
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="cardBorrow">查看借阅</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 状态模板 -->
<script type="text/html" id="statusTpl">
{{# if(d.status == 0){ }}
<span style="color:red">挂失<span>
{{# } else { }}
可用
{{# } }}
</script>
<script>
layui.use(['table','jquery'], function(){
$ = layui.jquery;
var table = layui.table;
// 进行渲染
var tableIns = table.render({
elem: '#cardTable'
,url:'./cardList'
,toolbar: '#headBar'
,height: 600
,cols: [[
{field:'id', width:180, title: 'ID', sort: true}
,{field:'reader', width:180, title: '用户名', sort: true}
,{field:'rule_id', width:180, title: '借阅规则', sort: true}
,{field:'status', width:180, title: '状态', templet: '#statusTpl'}
,{fixed: 'right', title:'操作', toolbar: '#operateBar', align: 'center', width:250}
]]
,page: true
});
// 头部工具栏事件
table.on('toolbar(formFilter)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
// 条件查找图书证
case 'search':
var conditionValue = $('#conditionValue');
var condition = $('#condition');
// 进行搜索,重新渲染
tableIns.reload({
where: { //设定异步数据接口的额外参数,任意设
"condition": condition.val(),
"conditionValue": conditionValue.val()
}
,page: {
curr: 1 //重新从第 1 页开始
}
});
break;
// 添加借书证
case 'add':
var addCardLayer = layer.open({
type: 2,
title: '添加借书证',
area: ['800px', '500px'],
maxmin: true,
shadeClose: true,
content: 'cardadd.jsp',
end: function(){
$('.layui-laypage-btn').click();
}
});
//layer.full(addCardLayer);
};
});
// 侧边工具栏事件
table.on(('tool(formFilter)'), function(obj){
var data = obj.data;
var layEvent = obj.event;
var tr = obj.tr;
var id = data.id;
switch(obj.event){
case 'edit':
layer.open({
type: 2,
title: '更改信息',
area: ['800px', '600px'],
maxmin: true,
shadeClose: true,
content: 'cardedit.jsp?id=' +id,
end: function(){
$(".layui-laypage-btn").click();
}
})
break;
case 'del':
layer.confirm('确认删除么?<br><span style="color:red;">这将删除该借阅证的所有记录</span>',function(index){
layer.close(index);
$.ajax({
url: './cardDel',
type: 'get',
data: 'id=' +id,
dataType: 'json',
timeout: 3000,
success: function(data){
if(data.code == 0){
console.log(data);
layer.msg(data.msg,{
icon: 6,
time: 1500
})
// 还是本页数据
$(".layui-laypage-btn").click();
}else{
layer.open({
title: '失败',
content: data.msg
})
}
},
error: function(){
layer.msg("连接超时");
}
})
})
break;
case 'cardBorrow':
layer.open({
type: 2,
title: '借阅历史',
area: ['800px', '600px'],
maxmin: true,
shadeClose: true,
content: 'cardborrow.jsp?id=' +id,
end: function(){
//$(".layui-laypage-btn").click();
}
})
}
})
});
</script>
</body>
</html>
//index
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>系统管理员</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
<div class="layui-header">
<div class="layui-logo">系统管理员</div>
<!-- 头部区域可配合layui已有的水平导航 -->
<ul class="layui-nav layui-layout-left">
<li class="layui-nav-item"><a href="">首页</a></li>
<li class="layui-nav-item">
<a href="javascript:;">其它系统</a>
<dl class="layui-nav-child">
<dd><a href="../reader/04readerFrame.jsp">图书馆首页</a></dd>
<dd><a href="../loginManager.html">图书管理员</a></dd>
</dl>
</li>
</ul>
<ul class="layui-nav layui-layout-right">
<li class="layui-nav-item">
<a href="javascript:;">
<img src="http://t.cn/RCzsdCq" class="layui-nav-img">
系统管理员
</a>
<dl class="layui-nav-child">
<dd id="updatePassword"><a href="javascript:;">修改密码</a></dd>
</dl>
</li>
<li class="layui-nav-item"><a href="./logOut">退出</a></li>
</ul>
</div>
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<!-- 左侧导航区域可配合layui已有的垂直导航 -->
<ul class="layui-nav layui-nav-tree" lay-filter="test">
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="./booklist.jsp" target="content"><i class="layui-icon layui-icon-read" style="font-size: 16px; color: #1E9FFF;"></i> 书籍管理</a>
</li>
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="./sortlist.jsp" target="content"><i class="layui-icon layui-icon-tabs" style="font-size: 16px; color: #1E9FFF;"></i> 书籍类型</a>
</li>
<li class="layui-nav-item">
<a href="./cardlist.jsp" target="content"><i class="layui-icon layui-icon-template-1" style="font-size: 16px; color: #1E9FFF;"> </i>借阅证管理</a>
</li>
<li class="layui-nav-item"><a href="./borrowlist.jsp" target="content"><i class="layui-icon layui-icon-chart-screen" style="font-size: 16px; color: #1E9FFF;"></i> 借阅信息查询</a></li>
<li class="layui-nav-item"><a href="./rulelist.jsp" target="content"><i class="layui-icon layui-icon-file-b" style="font-size: 16px; color: #1E9FFF;"> </i>借阅规则管理</a></li>
<li class="layui-nav-item"><a href="./managerlist.jsp" target="content"><i class="layui-icon layui-icon-group" style="font-size: 16px; color: #1E9FFF;"></i>图书管理员管理</a></li>
<li class="layui-nav-item"><a href="./librarydata.jsp" target="content"><i class="layui-icon layui-icon-windows" style="font-size: 16px; color: #1E9FFF;"> </i>系统管理</a></li>
</ul>
</div>
</div>
<div class="layui-body">
<!-- 内容主体区域 -->
<iframe src="librarydata.jsp" name="content" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
</div>
<div class="layui-footer">
<!-- 底部固定区域 -->
© 图书管理系统
</div>
</div>
<script>
//JavaScript代码区域
layui.use(['element', 'jquery', 'layer'], function(){
$ = layui.jquery;
var element = layui.element
$ = layui.jquery;
var form = layui.form
,layer = layui.layer;
$("#updatePassword").click(function(){
layer.open({
title: '修改密码',
type: 2,
area: ['300px', '300px'],
maxmin: true,
shadeClose: true,
content: 'updatePassword.jsp'
})
})
});
</script>
</body>
</html>
//librarydata
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="../public/js/echarts.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小宽高的Dom -->
<div id="main" style="width:1200px;height:500px;"></div>
<script type="text/javascript">
// 基于准备好的dom初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
myChart.setOption({
title: {
text: '借书情况'
},
tooltip: {},
legend: {
data:['借书量']
},
xAxis: {
data: []
},
yAxis: {},
series: [{
name: '借书量',
type: 'line',
data: []
}]
});
// 使用刚指定的配置项和数据显示图表。
//myChart.setOption(option);
// 异步加载数据
$.get('./libraryData').done(function (data) {
if(data.code == 0){
// 填入数据
myChart.setOption({
xAxis: {
data: data.data.days
},
series: [{
// 根据名字对应到相应的系列
name: '借书量',
data: data.data.data,
type: 'line'
}]
});
}else{
$('body').append($("<div style='color:red;'>调用接口失败</div>"));
}
});
</script>
</body>
</html>
//manageradd
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员添加</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</head>
</head>
<body>
<form class="layui-form layui-form-pane" action="" lay-filter="formFilter">
<div class="layui-form-item">
<label class="layui-form-label">姓名</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" name="account" lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">邮箱</label>
<div class="layui-input-block">
<input type="text" name="email" lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="submit" class="layui-btn" lay-submit="" lay-filter="submitButton">立即提交</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'jquery'], function(){
$ = layui.jquery;
var form = layui.form
,layer = layui.layer
//监听提交
form.on('submit(submitButton)', function(data){
$.ajax({
url: './managerAdd',
method: 'post',
data: data.field,
dataType: 'json',
success: function(data){
if(data.code == "0"){
parent.layer.msg("添加成功",{
icon: 6,
time: 500
});
setTimeout(function(){
parent.location.reload();
}, 500);
}else{
layer.msg(data.msg);
}
}
})
return false;
});
});
</script>
</body>
</html>
//edit
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javabean.Base"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员修改</title>
<!-- layui -->
<link rel="stylesheet" href="../public/layui/css/layui.css">
<script src="../public/layui/layui.js"></script>
<style>
.layui-form{
margin: 10px 20px;
}
</style>
</head>
</head>
<body>
<%
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();
%>
<form class="layui-form layui-form-pane" action="" lay-filter="formFilter">
<input type="text" name="id" value=<%=id %> lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input layui-hide">
<div class="layui-form-item">
<label class="layui-form-label">姓名</label>
<div class="layui-input-block">
<input type="text" name="name" value=<%=resultSet.getString("name") %> lay-verify="required" required autocomplete="off" placeholder="请输入姓名" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" name="account" value=<%=resultSet.getString("account") %> disabled lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" value=<%=resultSet.getString("password") %> lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">邮箱</label>
<div class="layui-input-block">
<input type="text" name="email" value=<%=resultSet.getString("email") %> lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="submit" class="layui-btn" lay-submit="" lay-filter="submitButton">立即提交</button>
</div>
</div>
</form>
<script>
layui.use(['form', 'jquery'], function(){
$ = layui.jquery;
var form = layui.form
,layer = layui.layer
//监听提交
form.on('submit(submitButton)', function(data){
$.ajax({
url: './managerEdit',
method: 'post',
data: data.field,
dataType: 'json',
success: function(data){
if(data.code == "0"){
parent.layer.msg("添加成功",{
icon: 6,
time: 500
});
setTimeout(function(){
parent.location.reload();
}, 500);
}else{
layer.msg(data.msg);
}
}
})
return false;
});
});
</script>
</body>
</html>
//list
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅卡</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<style>
.layui-table,.layui-table-view{
margin: 0 0px;
}
</style>
</head>
<body>
<!-- 表单 -->
<table class="layui-hide" id="managerTable" lay-filter="formFilter"></table>
<script src="../public/layui/layui.js" charset="utf-8"></script>
<!-- 头部工具栏 -->
<script type="text/html" id="headBar">
<button type="button" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">添加管理员</i></button>
</script>
<!-- 表格侧边栏 -->
<script type="text/html" id="operateBar">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['table','jquery'], function(){
$ = layui.jquery;
var table = layui.table;
// 进行渲染
var tableIns = table.render({
elem: '#managerTable'
,url:'./managerList'
,toolbar: '#headBar'
,height: 600
,cols: [[
{field:'id', width:80, title: 'ID', sort: true}
,{field:'account', width:80, title: '账号', sort: true}
,{field:'name', width:80, title: '姓名'}
,{field:'email', title: '邮箱', minWidth: 150}
,{fixed: 'right', title:'操作', toolbar: '#operateBar', align: 'center', width:150}
]]
});
// 头部工具栏事件
table.on('toolbar(formFilter)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
// 添加管理员
case 'add':
var addCardLayer = layer.open({
type: 2,
title: '添加管理员',
area: ['800px', '500px'],
maxmin: true,
shadeClose: true,
content: 'manageradd.jsp',
});
//layer.full(addCardLayer);
};
});
// 侧边工具栏事件
table.on(('tool(formFilter)'), function(obj){
var data = obj.data;
var layEvent = obj.event;
var id = data.id;
var tr = obj.tr;
switch(obj.event){
case 'edit':
layer.open({
type: 2,
title: '更改信息',
area: ['800px', '600px'],
maxmin: true,
shadeClose: true,
content: 'manageredit.jsp?id=' +id,
})
break;
case 'del':
layer.confirm('确定要删除么?',function(){
layer.msg("ok");
$.ajax({
url: './managerDel',
data: 'id=' +id,
type: 'get',
dataType: 'json',
timeout: 3000,
success: function(data){
layer.msg("???");
if(data.code == 0){
layer.msg(data.msg,{
icon: 6,
anim: 5,
time: 500
});
setTimeout(function(){
parent.location.reload();
},500);
}else{
layer.msg(data.code);
}
},
error: function(){
layer.msg("连接超时");
}
})
})
}
})
});
</script>
</body>
</html>