commit
						059b99b103
					
				@ -0,0 +1,115 @@
 | 
				
			||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
 | 
				
			||||
    pageEncoding="UTF-8"%>
 | 
				
			||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 | 
				
			||||
<html>
 | 
				
			||||
<head>
 | 
				
			||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 | 
				
			||||
<title>Insert title here</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>
 | 
				
			||||
 | 
				
			||||
	<!-- 表单 -->
 | 
				
			||||
	<table class="layui-hide" id="cardTable" 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="card_id">借阅证号</option>
 | 
				
			||||
			<option value="book_id">图书编号</option>
 | 
				
			||||
        	<option value="borrow_date">借阅日期</option>
 | 
				
			||||
        	<option value="end_date">截止日期</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: '#cardTable'
 | 
				
			||||
	    ,url:'./returnTable'
 | 
				
			||||
	    ,toolbar: '#headBar'
 | 
				
			||||
	    ,cols: [[
 | 
				
			||||
	       {field:'card_id', width:180, title: '借阅证号', sort: true}
 | 
				
			||||
	      ,{field:'book_id', width:130, title: '图书编号', sort: true}
 | 
				
			||||
	      ,{field:'borrow_date', width:250, title: '借阅日期', sort: true}
 | 
				
			||||
	      ,{field:'end_date', title: '截止日期',width: 250, sort: true}
 | 
				
			||||
 | 
				
			||||
	    ]]
 | 
				
			||||
	    ,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');
 | 
				
			||||
	    	  layer.msg(condition.val());
 | 
				
			||||
	    	  // 进行搜索,重新渲染
 | 
				
			||||
	    	  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',
 | 
				
			||||
		    	});
 | 
				
			||||
		    	//layer.full(addCardLayer);
 | 
				
			||||
		  };
 | 
				
			||||
		});
 | 
				
			||||
	 
 | 
				
			||||
	  // 侧边工具栏事件
 | 
				
			||||
	  table.on(('tool(formFilter)'), function(obj){
 | 
				
			||||
	  	var data = obj.data;
 | 
				
			||||
	  	var layEvent = obj.event;
 | 
				
			||||
	  	var tr = obj.tr;
 | 
				
			||||
	  	switch(obj.event){
 | 
				
			||||
	  	  case 'edit':
 | 
				
			||||
	  	  	  layer.open({
 | 
				
			||||
	  	  	  	type: 2,
 | 
				
			||||
	  	  	  	title: '更改信息',
 | 
				
			||||
	  	  	  	area: ['800px', '600px'],
 | 
				
			||||
	  	  	  	maxmin: true,
 | 
				
			||||
	  	  	  	shadeClose: true,
 | 
				
			||||
	  	  	  	content: '',
 | 
				
			||||
	  	  	  })
 | 
				
			||||
	  	  	break;
 | 
				
			||||
	  	}
 | 
				
			||||
	  })
 | 
				
			||||
	});
 | 
				
			||||
	</script>
 | 
				
			||||
</body>
 | 
				
			||||
</html>
 | 
				
			||||
											
												Binary file not shown.
											
										
									
								@ -1,31 +1,40 @@
 | 
				
			||||
package filter;
 | 
				
			||||
 | 
				
			||||
import java.io.IOException;
 | 
				
			||||
 | 
				
			||||
import javax.servlet.Filter;
 | 
				
			||||
import javax.servlet.FilterChain;
 | 
				
			||||
import javax.servlet.FilterConfig;
 | 
				
			||||
import javax.servlet.ServletException;
 | 
				
			||||
import javax.servlet.ServletRequest;
 | 
				
			||||
import javax.servlet.ServletResponse;
 | 
				
			||||
import javax.servlet.annotation.WebFilter;
 | 
				
			||||
import javax.servlet.http.HttpServletRequest;
 | 
				
			||||
import javax.servlet.http.HttpServletResponse;
 | 
				
			||||
import javax.servlet.http.HttpSession;
 | 
				
			||||
 | 
				
			||||
/**
 | 
				
			||||
 * 图书管理员过滤
 | 
				
			||||
 */
 | 
				
			||||
public class ManagerFilter implements Filter {
 | 
				
			||||
 | 
				
			||||
    public void destroy() {
 | 
				
			||||
		
 | 
				
			||||
	public void destroy() {
 | 
				
			||||
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
 | 
				
			||||
		
 | 
				
			||||
		//TODO
 | 
				
			||||
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
 | 
				
			||||
			throws IOException, ServletException {
 | 
				
			||||
 | 
				
			||||
		HttpServletRequest req = (HttpServletRequest) request;
 | 
				
			||||
		HttpSession session = req.getSession();
 | 
				
			||||
		if (session == null || session.getAttribute("manager") == null) {
 | 
				
			||||
			HttpServletResponse rep = (HttpServletResponse) response;
 | 
				
			||||
			rep.sendRedirect(req.getContextPath() + "/loginManager.html");
 | 
				
			||||
		}
 | 
				
			||||
		chain.doFilter(request, response);
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
	public void init(FilterConfig fConfig) throws ServletException {
 | 
				
			||||
		
 | 
				
			||||
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
@ -0,0 +1,29 @@
 | 
				
			||||
package servlet.manager;
 | 
				
			||||
 | 
				
			||||
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 Quit
 | 
				
			||||
 */
 | 
				
			||||
@WebServlet("/manager/quit")
 | 
				
			||||
public class Quit 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("manager") != null) {
 | 
				
			||||
			session.removeAttribute("manager");
 | 
				
			||||
		}
 | 
				
			||||
		resp.sendRedirect(req.getContextPath() + "/loginManager.html");
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,122 @@
 | 
				
			||||
package servlet.manager;
 | 
				
			||||
 | 
				
			||||
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 ReturnTable
 | 
				
			||||
 */
 | 
				
			||||
@WebServlet("/manager/returnTable")
 | 
				
			||||
public class ReturnTable 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 * from borrow_books where manager_id is null";
 | 
				
			||||
			if (condition != null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) {
 | 
				
			||||
				where = " and " + condition + " like '%" + conditionValue + "%' ";
 | 
				
			||||
				sql += where;
 | 
				
			||||
			}
 | 
				
			||||
			sql += " limit ?,?";// 1 10 (1-1)*10
 | 
				
			||||
			System.out.println("???" + sql);
 | 
				
			||||
			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"));
 | 
				
			||||
 | 
				
			||||
				jsonArray.add(jsonData);
 | 
				
			||||
			}
 | 
				
			||||
			countSql = "select count(*) as count from borrow_books where manager_id is null";
 | 
				
			||||
			countSql += where;
 | 
				
			||||
			countPstmt = connection.prepareStatement(countSql);
 | 
				
			||||
			countSet = countPstmt.executeQuery();
 | 
				
			||||
			if (countSet.next()) {
 | 
				
			||||
				count = countSet.getInt("count");
 | 
				
			||||
			}
 | 
				
			||||
			if (!jsonArray.isEmpty()) {
 | 
				
			||||
				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());
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
	/**
 | 
				
			||||
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 | 
				
			||||
	 *      response)
 | 
				
			||||
	 */
 | 
				
			||||
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
 | 
				
			||||
			throws ServletException, IOException {
 | 
				
			||||
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,115 @@
 | 
				
			||||
package servlet.reader;
 | 
				
			||||
 | 
				
			||||
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 Book
 | 
				
			||||
 */
 | 
				
			||||
@WebServlet("/reader/book")
 | 
				
			||||
public class Book 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 * from books ";
 | 
				
			||||
			if (condition != null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) {
 | 
				
			||||
				where = " where " + condition + " like '%" + conditionValue + "%' ";
 | 
				
			||||
				sql += where;
 | 
				
			||||
			}
 | 
				
			||||
			sql += " limit ?,?";// 1 10 (1-1)*10
 | 
				
			||||
			System.out.println("???" + sql);
 | 
				
			||||
			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("name", resultSet.getString("name"));
 | 
				
			||||
				jsonData.put("author", resultSet.getString("author"));
 | 
				
			||||
				jsonData.put("library_id", resultSet.getString("library_id"));
 | 
				
			||||
				jsonData.put("sort_id", resultSet.getString("sort_id"));
 | 
				
			||||
				jsonData.put("position", resultSet.getString("position"));
 | 
				
			||||
				jsonData.put("status", resultSet.getString("status"));
 | 
				
			||||
				jsonData.put("description", resultSet.getString("description"));
 | 
				
			||||
				jsonArray.add(jsonData);
 | 
				
			||||
			}
 | 
				
			||||
			countSql = "select count(*) as count from books ";
 | 
				
			||||
			countSql += where;
 | 
				
			||||
			countPstmt = connection.prepareStatement(countSql);
 | 
				
			||||
			countSet = countPstmt.executeQuery();
 | 
				
			||||
			if (countSet.next()) {
 | 
				
			||||
				count = countSet.getInt("count");
 | 
				
			||||
			}
 | 
				
			||||
			if (!jsonArray.isEmpty()) {
 | 
				
			||||
				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());
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,117 @@
 | 
				
			||||
package servlet.reader;
 | 
				
			||||
 | 
				
			||||
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 net.sf.json.JSONArray;
 | 
				
			||||
import net.sf.json.JSONObject;
 | 
				
			||||
 | 
				
			||||
/**
 | 
				
			||||
 * Servlet implementation class Borrow
 | 
				
			||||
 */
 | 
				
			||||
@WebServlet("/reader/borrow")
 | 
				
			||||
public class Borrow 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;
 | 
				
			||||
 | 
				
			||||
		HttpSession session = req.getSession();
 | 
				
			||||
 | 
				
			||||
		JSONObject jsonData = new JSONObject();
 | 
				
			||||
		JSONArray jsonArray = new JSONArray();
 | 
				
			||||
		JSONObject jsonResult = new JSONObject();
 | 
				
			||||
		// 进行查询
 | 
				
			||||
		try {
 | 
				
			||||
			connection = (Connection) Base.getConnection();
 | 
				
			||||
			sql = "select * from borrow_books where card_id = " + session.getAttribute("reader");
 | 
				
			||||
			if (condition != null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) {
 | 
				
			||||
				where = " and " + condition + " like '%" + conditionValue + "%' ";
 | 
				
			||||
				sql += where;
 | 
				
			||||
			}
 | 
				
			||||
			sql += " limit ?,?";// 1 10 (1-1)*10
 | 
				
			||||
			System.out.println("???" + sql);
 | 
				
			||||
			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"));
 | 
				
			||||
				jsonArray.add(jsonData);
 | 
				
			||||
			}
 | 
				
			||||
			countSql = "select count(*) as count from borrow_books where card_id = "
 | 
				
			||||
					+ req.getSession().getAttribute("reader");
 | 
				
			||||
			countSql += where;
 | 
				
			||||
			countPstmt = connection.prepareStatement(countSql);
 | 
				
			||||
			countSet = countPstmt.executeQuery();
 | 
				
			||||
			if (countSet.next()) {
 | 
				
			||||
				count = countSet.getInt("count");
 | 
				
			||||
			}
 | 
				
			||||
			if (!jsonArray.isEmpty()) {
 | 
				
			||||
				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());
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,119 @@
 | 
				
			||||
package servlet.reader;
 | 
				
			||||
 | 
				
			||||
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 net.sf.json.JSONArray;
 | 
				
			||||
import net.sf.json.JSONObject;
 | 
				
			||||
 | 
				
			||||
/**
 | 
				
			||||
 * Servlet implementation class Illegal
 | 
				
			||||
 */
 | 
				
			||||
@WebServlet("/reader/illegal")
 | 
				
			||||
public class Illegal 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;
 | 
				
			||||
		HttpSession session = req.getSession();
 | 
				
			||||
 | 
				
			||||
		JSONObject jsonData = new JSONObject();
 | 
				
			||||
		JSONArray jsonArray = new JSONArray();
 | 
				
			||||
		JSONObject jsonResult = new JSONObject();
 | 
				
			||||
		// 进行查询
 | 
				
			||||
		try {
 | 
				
			||||
			connection = (Connection) Base.getConnection();
 | 
				
			||||
			sql = "select * from borrow_books where ILLEGAL is not null and length(trim(illegal))>0 AND CARD_ID = "
 | 
				
			||||
					+ session.getAttribute("reader");
 | 
				
			||||
			if (condition != null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) {
 | 
				
			||||
				where = " and " + condition + " like '%" + conditionValue + "%' ";
 | 
				
			||||
				sql += where;
 | 
				
			||||
			}
 | 
				
			||||
			sql += " limit ?,?";// 1 10 (1-1)*10
 | 
				
			||||
			System.out.println("???" + sql);
 | 
				
			||||
			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 where ILLEGAL is not null and length(trim(illegal))>0 AND CARD_ID = "
 | 
				
			||||
					+ session.getAttribute("reader");
 | 
				
			||||
			countSql += where;
 | 
				
			||||
			countPstmt = connection.prepareStatement(countSql);
 | 
				
			||||
			countSet = countPstmt.executeQuery();
 | 
				
			||||
			if (countSet.next()) {
 | 
				
			||||
				count = countSet.getInt("count");
 | 
				
			||||
			}
 | 
				
			||||
			if (!jsonArray.isEmpty()) {
 | 
				
			||||
				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());
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue