parent
e831fdcad9
commit
441e92d731
@ -0,0 +1,79 @@
|
||||
<%@ 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 layui-form-text">
|
||||
<label class="layui-form-label">分类描述</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="description" placeholder="请输入内容" class="layui-textarea" style="height:300px"></textarea>
|
||||
</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: './sortAdd',
|
||||
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>
|
@ -0,0 +1,101 @@
|
||||
<%@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>
|
||||
<!-- 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>
|
||||
<%
|
||||
String id = request.getParameter("id");
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
String sql = "";
|
||||
|
||||
connection = (Connection)Base.getConnection();
|
||||
sql = "select * from book_sort where id = ?";
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, id);
|
||||
resultSet = pstmt.executeQuery();
|
||||
resultSet.next();
|
||||
%>
|
||||
<body>
|
||||
<form class="layui-form layui-form-pane" action="" lay-filter="formFilter">
|
||||
<input type="text" name="id" value=<%=id %> lay-verify="required" required autocomplete="off" 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 layui-form-text">
|
||||
<label class="layui-form-label">分类描述</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="description" placeholder="请输入内容" class="layui-textarea" style="height:300px"><%=resultSet.getString("description") != null ? resultSet.getString("description") : "" %></textarea>
|
||||
</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: './sortEdit',
|
||||
method: 'post',
|
||||
data: data.field,
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if(data.code == "0"){
|
||||
parent.layer.msg(data.msg,{
|
||||
icon: 6,
|
||||
time: 500
|
||||
});
|
||||
setTimeout(function(){
|
||||
parent.location.reload();
|
||||
}, 500);
|
||||
}else{
|
||||
layer.msg(data.msg);
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<%
|
||||
Base.closeResource(connection, pstmt, resultSet);
|
||||
%>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,108 @@
|
||||
<%@ 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">
|
||||
<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:'./sortList'
|
||||
,toolbar: '#headBar'
|
||||
,height: 600
|
||||
,cols: [[
|
||||
{field:'id', width:80, title: 'ID', sort: true}
|
||||
,{field:'name', width:180, title: '分类名', sort: true}
|
||||
,{field:'description', width:480, title: '描述', sort: true}
|
||||
,{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: 'sortadd.jsp',
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
// 侧边工具栏事件
|
||||
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: 'sortedit.jsp?id=' +id,
|
||||
})
|
||||
break;
|
||||
case 'del':
|
||||
layer.confirm('确认删除么?<br><span style="color:red;">这将会将该分类下的书籍归为未分类</span>', function(){
|
||||
$.ajax({
|
||||
url: './sortDel',
|
||||
type: 'get',
|
||||
data: 'id=' +id,
|
||||
success: function(data){
|
||||
if(data.code == 0){
|
||||
parent.layer.msg(data.msg,{
|
||||
icon: 6,
|
||||
time: 500
|
||||
});
|
||||
setTimeout(function(){
|
||||
parent.location.reload();
|
||||
}, 500);
|
||||
}else{
|
||||
layer.msg(data.msg);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,83 @@
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
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()) );
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue