初步完成借阅信息查询

pull/1/head
you 5 years ago
parent b5c5508c69
commit d635a45a08

@ -81,6 +81,7 @@
<!-- 行操作 -->
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="borrow">查看借阅</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>
@ -129,9 +130,9 @@
}}
,{field: 'position', title: '位置', width: 110, sort: true}
,{field: 'status', title: '状态', width: 60, templet:'#statusTpl'}
,{field: 'description', title: '描述', width: 380}
,{field: 'description', title: '描述', width: 340}
//,{field: 'operate', title: '操作', width: 200, templet: 'titleTpl'}
,{fixed: 'right', title:'操作', width:150, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
,{fixed: 'right', title:'操作', width: 200, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
]]
,id: 'idTest'
});

@ -0,0 +1,127 @@
<%@ 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="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="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>
<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: '#cardTable'
,url:'./borrowList'
,toolbar: '#headBar'
,cols: [[
{field:'id', width:80, title: 'ID', sort: true}
,{field:'card_id', width:180, title: '借阅证号'}
,{field:'book_id', width:180, title: '书籍id', sort: true}
,{field:'borrow_date', width:180, title: '借阅时间'}
,{field:'end_date', title: '限定时间', minWidth: 150}
,{field:'return_date', width:180, title: '归还时间', sort: true}
,{field:'illegal', width:80, title: '违章信息', sort: true}
,{field:'manager_id', width:80, title: '处理人'}
,{fixed: 'right', title:'操作', toolbar: '#operateBar', align: 'center', width:150}
]]
,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>

@ -0,0 +1,68 @@
<%@ 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>
<div class="layui-form">
<table class="layui-table">
<colgroup>
<col width="150">
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>人物</th>
<th>民族</th>
<th>出场时间</th>
<th>格言</th>
</tr>
</thead>
<tbody>
<tr>
<td>贤心</td>
<td>汉族</td>
<td>1989-10-14</td>
<td>人生似修行</td>
</tr>
<tr>
<td>张爱玲</td>
<td>汉族</td>
<td>1920-09-30</td>
<td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
</tr>
<tr>
<td>Helen Keller</td>
<td>拉丁美裔</td>
<td>1880-06-27</td>
<td> Life is either a daring adventure or nothing.</td>
</tr>
<tr>
<td>岳飞</td>
<td>汉族</td>
<td>1103-北宋崇宁二年</td>
<td>教科书再滥改,也抹不去“民族英雄”的事实</td>
</tr>
<tr>
<td>孟子</td>
<td>华夏族(汉族)</td>
<td>公元前-372年</td>
<td>猿强,则国强。国强,则猿更强! </td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

@ -38,6 +38,7 @@
<!-- 表格侧边栏的操作 -->
<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>
@ -65,7 +66,7 @@
,{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:150}
,{fixed: 'right', title:'操作', toolbar: '#operateBar', align: 'center', width:250}
]]
,page: true
});
@ -160,6 +161,19 @@
})
})
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();
}
})
}
})
});

@ -52,6 +52,7 @@
<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="./managelist.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="./system.jsp" target="content"><i class="layui-icon layui-icon-windows" style="font-size: 16px; color: #1E9FFF;"> </i>系统管理</a></li>

@ -0,0 +1,115 @@
package servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mysql.jdbc.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 * from borrow_books ";
if(condition!=null && conditionValue != null && !condition.equals("") && !conditionValue.equals("")) {
where = " where "+ condition +" like '%" +conditionValue +"%' ";
sql += where;
}
sql += " limit ?,?";//1 10 (1-1)*10
pstmt = connection.prepareStatement(sql);
pstmt.setInt(1, (Integer.parseInt(page)-1) * Integer.parseInt(limit));
pstmt.setInt(2, Integer.parseInt(limit));
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
jsonData.put("id", resultSet.getString("id"));
jsonData.put("card_id", resultSet.getString("card_id"));
jsonData.put("book_id", resultSet.getString("book_id"));
jsonData.put("borrow_date", resultSet.getString("borrow_date"));
jsonData.put("end_date", resultSet.getString("end_date"));
jsonData.put("return_date", resultSet.getString("return_date"));
jsonData.put("illegal", resultSet.getString("illegal"));
jsonData.put("manager_id", resultSet.getString("manager_id"));
jsonArray.add(jsonData);
}
countSql = "select count(*) as count from borrow_books ";
countSql +=where;
countPstmt = connection.prepareStatement(countSql);
countSet = countPstmt.executeQuery();
if(countSet.next()) {
count = countSet.getInt("count");
}
if(!jsonArray.isEmpty()) {
code = 0;
msg = "查询成功";
}
} 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());
}
}

@ -100,7 +100,6 @@ public class CardList extends HttpServlet {
try {
Base.closeResource(connection, pstmt, resultSet);
} catch (SQLException e) {
// TODO Auto-generated catch block
msg = "关闭失败";
}
}

Loading…
Cancel
Save