package javabean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Admin {
/**
* 用户登录
*
* @param username
* @param password
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
@SuppressWarnings("null")
public String login(String username, String password) throws ClassNotFoundException, SQLException {
if (username == null || username.trim().equals("")) {
return "账号不能为空";
} else if (password == null || password.trim().equals("")) {
return "密码不能为空";
}
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
String sql = "select * from admin where username=? and password=? limit 1";
connection = Base.getConnection();
pstmt = (PreparedStatement) connection.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, Util.passMd5(password));
resultSet = pstmt.executeQuery();
try{
if (resultSet.next()) {
return "1";
}
}catch(Exception e) {
return "发生未知错误";
}finally {
if(Base.closeResource(connection, pstmt, resultSet) == false) {
return "关闭失败";
}
}
return "账号或密码错误";
}
/**
* 获取图书列表
* @param page
* @param limit
* @return String json字符串
* @throws ClassNotFoundException
* @throws SQLException
*/
public Map getBookList(String page, String limit, Map where) throws ClassNotFoundException, SQLException {
Map<String, Object> map = new HashMap<String, Object>();
String whereString = "";
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
connection = Base.getConnection();
int number = Integer.valueOf(page);
int size = Integer.valueOf(limit);
String sql = "select * from books ";
if(where!=null && !where.isEmpty()) {
whereString += " where "+where.get("condition") +" like '%" +where.get("conditionValue") +"%' ";
sql += whereString;
}
sql += "order by id desc limit ?,? ";
pstmt = (PreparedStatement) connection.prepareStatement(sql);
pstmt.setInt(1, (number-1) * size );
pstmt.setInt(2, size);
resultSet = pstmt.executeQuery();
JSONObject json = new JSONObject();
String result = "";
int i = 1;
// 获取行数据
while( resultSet.next() ) {
//System.out.println("????-------" +resultSet.getInt("count"));
json.put("id", resultSet.getInt("id"));
json.put("name", resultSet.getString("name"));
json.put("author", resultSet.getString("author"));
json.put("library_id", resultSet.getInt("library_id"));
json.put("sort_id", resultSet.getInt("sort_id"));
json.put("position", resultSet.getString("position"));
json.put("status", resultSet.getInt("status"));
json.put("description", resultSet.getString("description"));
if(i==1) {
result = json.toString();
}else {
result += "," +json.toString();
}
i++;
}
map.put("data", result);
// 获取总数count,重写sql
int count = 0;
sql = "select count(*) as count from books ";
if(where!=null && !where.isEmpty()) {
sql += whereString;
}
pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery();
if(resultSet.next()) {
count = resultSet.getInt("count");
}
map.put("count", count);
Base.closeResource(connection, pstmt, resultSet);
return map;
}
/**
* 通过id(String)获取分类名称
* @param id
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static String getSortName(String id) throws ClassNotFoundException, SQLException {
if(id==null || id.equals(""))
return "参数错误";
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
String sql = null;
String result = null;
connection = Base.getConnection();
sql = "select name from book_sort where id=?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, id);
resultSet = pstmt.executeQuery();
if(resultSet.next()) {
result = resultSet.getString("name");
}else {
result = "查询失败";
}
Base.closeResource(connection, pstmt, null);
return result;
}
/**
* 根据id获取书籍信息
* @param id
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static ResultSet getBookInfo(int id) throws ClassNotFoundException, SQLException {
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
String sql = "select * from books where id=? ";
connection = Base.getConnection();
pstmt = connection.prepareStatement(sql);
pstmt.setInt(1, id);
resultSet = pstmt.executeQuery();
//Base.closeResource(null, null, null);
connection.close();
if(resultSet.next()) {
return resultSet;
}
return null;
}
/* 没用 */
public static JSONArray getRules() throws ClassNotFoundException, SQLException {
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
String sql = "select * from rules";
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
String result = "";
connection = Base.getConnection();
pstmt = connection.prepareStatement(sql);
resultSet = pstmt.executeQuery();
while(resultSet.next()) {
jsonObject.put("id", resultSet.getString("id"));
jsonObject.put("borrow_num", resultSet.getString("borrow_num"));
jsonObject.put("borrow_library", resultSet.getString("borrow_library"));
jsonObject.put("overtime_fee", resultSet.getString("overtime_fee"));
jsonArray.add(jsonObject);
System.out.println(jsonArray.toString());
}
Base.closeResource(connection, pstmt, resultSet);
return jsonArray;
}
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//Common common = new Common();
//System.out.println(common.getCount("books"));
Admin admin = new Admin();
System.out.println(admin.getSortName("2"));
//Map map = admin.getBookList("1", "100");
//System.out.println( map.get("count"));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
使用jsp、layui、mysql完成的Web端图书管理系统
共287个文件
gif:78个
java:53个
jsp:52个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 52 浏览量
2023-11-13
15:23:54
上传
评论
收藏 6.88MB ZIP 举报
温馨提示
使用jsp、layui、mysql完成的Web端图书管理系统,包含用户图书借阅、图书管理员、系统管理员三大模块,功能很齐全。前台页面(即本书图书管理系统的首页)实现了公告的显示,图书查询,留言建议三大主要功能,有读者规则查看功能,师生们可以看到图书管理人员发布的最新公告信息,并可以查询自己感兴趣的图书,查看留言提议,用户登录后还有个人资料修改、个人借阅信息查询、个人违章信息查询等功能,也可以给学校的图书管理人员留言提议。后台的页面则集成了图书管理中所需的功能,分成图书管理人员和系统管理人员,平时管理人员的工作都是在后台中完成的
资源推荐
资源详情
资源评论
收起资源包目录
使用jsp、layui、mysql完成的Web端图书管理系统 (287个子文件)
bootstrap.css 143KB
bootstrap.min.css 118KB
animate.css 73KB
layui.css 73KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
layer.css 14KB
layer.css 14KB
layui.mobile.css 10KB
bootstrap-table.css 9KB
bootstrap-table.min.css 9KB
laydate.css 7KB
layer.css 5KB
message.css 4KB
component.css 3KB
default.css 2KB
code.css 1KB
login.css 1007B
table.css 37B
iconfont.eot 46KB
glyphicons-halflings-regular.eot 20KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
47.gif 2KB
36.gif 2KB
49.gif 2KB
58.gif 2KB
6.gif 2KB
54.gif 2KB
53.gif 2KB
56.gif 2KB
62.gif 2KB
31.gif 2KB
55.gif 2KB
35.gif 2KB
15.gif 2KB
loading-2.gif 2KB
loading-2.gif 2KB
37.gif 1KB
68.gif 1KB
52.gif 777B
loading-1.gif 701B
loading-1.gif 701B
.gitignore 47B
共 287 条
- 1
- 2
- 3
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6823
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功