|  |  | @ -11,52 +11,62 @@ import net.sf.json.JSONArray; | 
			
		
	
		
		
			
				
					
					|  |  |  | import net.sf.json.JSONObject; |  |  |  | import net.sf.json.JSONObject; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | public class Admin { |  |  |  | public class Admin { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	/** |  |  |  | 	/** | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * 用户登录 |  |  |  | 	 * 用户登录方法 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	 * |  |  |  | 	 * | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param username |  |  |  | 	 * @param username 用户名 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param password |  |  |  | 	 * @param password 密码 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @return |  |  |  | 	 * @return 登录结果的字符串 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws ClassNotFoundException |  |  |  | 	 * @throws ClassNotFoundException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws SQLException |  |  |  | 	 * @throws SQLException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 */ |  |  |  | 	 */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 	@SuppressWarnings("null") |  |  |  | 	@SuppressWarnings("null") | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public String login(String username, String password) throws ClassNotFoundException, SQLException { |  |  |  | 	public String login(String username, String password) throws ClassNotFoundException, SQLException { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		// 参数校验
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if (username == null || username.trim().equals("")) { |  |  |  | 		if (username == null || username.trim().equals("")) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			return "账号不能为空"; |  |  |  | 			return "账号不能为空"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} else if (password == null || password.trim().equals("")) { |  |  |  | 		} else if (password == null || password.trim().equals("")) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			return "密码不能为空"; |  |  |  | 			return "密码不能为空"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Connection connection = null; |  |  |  | 		Connection connection = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		PreparedStatement pstmt = null; |  |  |  | 		PreparedStatement pstmt = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ResultSet resultSet = null; |  |  |  | 		ResultSet resultSet = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		// SQL查询语句,验证用户和密码
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String sql = "select * from admin where username=? and password=? limit 1"; |  |  |  | 		String sql = "select * from admin where username=? and password=? limit 1"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		connection = Base.getConnection(); |  |  |  | 		connection = Base.getConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = (PreparedStatement) connection.prepareStatement(sql); |  |  |  | 		pstmt = (PreparedStatement) connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setString(1, username); |  |  |  | 		pstmt.setString(1, username); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setString(2, Util.passMd5(password)); |  |  |  | 		pstmt.setString(2, Util.passMd5(password));  // 假设Util.passMd5()是对密码的加密方法
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		try{ |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			if (resultSet.next()) { |  |  |  | 		try { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			if (resultSet.next()) {  // 如果有记录,说明登录成功
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 				return "1"; |  |  |  | 				return "1"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		}catch(Exception e) { |  |  |  | 		} catch (Exception e) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			return "发生未知错误"; |  |  |  | 			return "发生未知错误"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		}finally { |  |  |  | 		} finally { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			if(Base.closeResource(connection, pstmt, resultSet) == false) { |  |  |  | 			// 关闭数据库连接资源
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			if (Base.closeResource(connection, pstmt, resultSet) == false) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				return "关闭失败"; |  |  |  | 				return "关闭失败"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		// 如果没有记录,账号或密码错误
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return "账号或密码错误"; |  |  |  | 		return "账号或密码错误"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	/** |  |  |  | 	/** | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * 获取图书列表 |  |  |  | 	 * 获取图书列表方法,带分页查询功能 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param page |  |  |  | 	 * | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param limit |  |  |  | 	 * @param page 当前页 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @return String json字符串 |  |  |  | 	 * @param limit 每页显示条数 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @param where 查询条件 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @return 返回包含数据和总条数的Map | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws ClassNotFoundException |  |  |  | 	 * @throws ClassNotFoundException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws SQLException |  |  |  | 	 * @throws SQLException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 */ |  |  |  | 	 */ | 
			
		
	
	
		
		
			
				
					|  |  | @ -66,27 +76,30 @@ public class Admin { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Connection connection = null; |  |  |  | 		Connection connection = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		PreparedStatement pstmt = null; |  |  |  | 		PreparedStatement pstmt = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ResultSet resultSet = null; |  |  |  | 		ResultSet resultSet = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		connection = Base.getConnection(); |  |  |  | 		connection = Base.getConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		int number = Integer.valueOf(page); |  |  |  | 		int number = Integer.valueOf(page);  // 页码
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		int size = Integer.valueOf(limit);  |  |  |  | 		int size = Integer.valueOf(limit);  // 每页条数
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		// 构建查询语句
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String sql = "select * from books "; |  |  |  | 		String sql = "select * from books "; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(where!=null && !where.isEmpty()) { |  |  |  | 		if (where != null && !where.isEmpty()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			whereString += " where "+where.get("condition") +" like '%" +where.get("conditionValue") +"%' "; |  |  |  | 			whereString += " where " + where.get("condition") + " like '%" + where.get("conditionValue") + "%' "; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			sql += whereString; |  |  |  | 			sql += whereString;  // 根据条件拼接查询语句
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		sql += "order by id desc limit ?,? "; |  |  |  | 		sql += "order by id desc limit ?,? ";  // 分页查询
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = (PreparedStatement) connection.prepareStatement(sql); |  |  |  | 		pstmt = (PreparedStatement) connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setInt(1, (number-1) * size ); |  |  |  | 		pstmt.setInt(1, (number - 1) * size);  // 设置分页参数
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setInt(2, size); |  |  |  | 		pstmt.setInt(2, size);  // 每页显示的记录数
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		JSONObject json = new JSONObject(); |  |  |  | 		JSONObject json = new JSONObject(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String result = ""; |  |  |  | 		String result = ""; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		int i = 1; |  |  |  | 		int i = 1; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		// 获取行数据
 |  |  |  | 		// 遍历查询结果并构造JSON格式的返回数据
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		while( resultSet.next() ) { |  |  |  | 		while (resultSet.next()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			//System.out.println("????-------" +resultSet.getInt("count"));
 |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			json.put("id", resultSet.getInt("id")); |  |  |  | 			json.put("id", resultSet.getInt("id")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			json.put("name", resultSet.getString("name")); |  |  |  | 			json.put("name", resultSet.getString("name")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			json.put("author", resultSet.getString("author")); |  |  |  | 			json.put("author", resultSet.getString("author")); | 
			
		
	
	
		
		
			
				
					|  |  | @ -95,65 +108,74 @@ public class Admin { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			json.put("position", resultSet.getString("position")); |  |  |  | 			json.put("position", resultSet.getString("position")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			json.put("status", resultSet.getInt("status")); |  |  |  | 			json.put("status", resultSet.getInt("status")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			json.put("description", resultSet.getString("description")); |  |  |  | 			json.put("description", resultSet.getString("description")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			if(i==1) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			// 拼接多个JSON对象
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			if (i == 1) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				result = json.toString(); |  |  |  | 				result = json.toString(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			}else { |  |  |  | 			} else { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				result += "," +json.toString(); |  |  |  | 				result += "," + json.toString(); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 			i++; |  |  |  | 			i++; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		map.put("data", result); |  |  |  | 		map.put("data", result); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		// 获取总数count,重写sql
 |  |  |  | 		// 获取总数
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		int count = 0; |  |  |  | 		int count = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		sql = "select count(*) as count from books "; |  |  |  | 		sql = "select count(*) as count from books "; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(where!=null && !where.isEmpty()) { |  |  |  | 		if (where != null && !where.isEmpty()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			sql += whereString; |  |  |  | 			sql += whereString;  // 根据条件计算总数
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = connection.prepareStatement(sql); |  |  |  | 		pstmt = connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(resultSet.next()) { |  |  |  | 		if (resultSet.next()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			count = resultSet.getInt("count"); |  |  |  | 			count = resultSet.getInt("count"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		map.put("count", count); |  |  |  | 		map.put("count", count); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Base.closeResource(connection, pstmt, resultSet); |  |  |  | 		Base.closeResource(connection, pstmt, resultSet); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return map; |  |  |  | 		return map; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	/** |  |  |  | 	/** | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * 通过id(String)获取分类名称 |  |  |  | 	 * 根据分类ID获取分类名称 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param id |  |  |  | 	 * | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @return |  |  |  | 	 * @param id 分类ID | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @return 分类名称 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws ClassNotFoundException |  |  |  | 	 * @throws ClassNotFoundException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws SQLException |  |  |  | 	 * @throws SQLException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 */ |  |  |  | 	 */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static String getSortName(String id) throws ClassNotFoundException, SQLException { |  |  |  | 	public static String getSortName(String id) throws ClassNotFoundException, SQLException { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(id==null || id.equals("")) |  |  |  | 		if (id == null || id.equals("")) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			return "参数错误"; |  |  |  | 			return "参数错误"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Connection connection = null; |  |  |  | 		Connection connection = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		PreparedStatement pstmt = null; |  |  |  | 		PreparedStatement pstmt = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ResultSet resultSet = null; |  |  |  | 		ResultSet resultSet = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String sql = null; |  |  |  | 		String sql = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String result = null; |  |  |  | 		String result = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		connection = Base.getConnection(); |  |  |  | 		connection = Base.getConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		sql = "select name from book_sort where id=?"; |  |  |  | 		sql = "select name from book_sort where id=?"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = connection.prepareStatement(sql); |  |  |  | 		pstmt = connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setString(1, id); |  |  |  | 		pstmt.setString(1, id); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(resultSet.next()) { |  |  |  | 		if (resultSet.next()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			result = resultSet.getString("name"); |  |  |  | 			result = resultSet.getString("name"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		}else { |  |  |  | 		} else { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			result = "查询失败"; |  |  |  | 			result = "查询失败"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Base.closeResource(connection, pstmt, null); |  |  |  | 		Base.closeResource(connection, pstmt, null); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return result; |  |  |  | 		return result; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	/** |  |  |  | 	/** | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * 根据id获取书籍信息 |  |  |  | 	 * 根据书籍ID获取书籍详细信息 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @param id |  |  |  | 	 * | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @return |  |  |  | 	 * @param id 书籍ID | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @return 书籍信息的ResultSet对象 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws ClassNotFoundException |  |  |  | 	 * @throws ClassNotFoundException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 * @throws SQLException |  |  |  | 	 * @throws SQLException | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 */ |  |  |  | 	 */ | 
			
		
	
	
		
		
			
				
					|  |  | @ -161,33 +183,43 @@ public class Admin { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Connection connection = null; |  |  |  | 		Connection connection = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		PreparedStatement pstmt = null; |  |  |  | 		PreparedStatement pstmt = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ResultSet resultSet = null; |  |  |  | 		ResultSet resultSet = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String sql = "select * from books where id=? "; |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		String sql = "select * from books where id=?"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		connection = Base.getConnection(); |  |  |  | 		connection = Base.getConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = connection.prepareStatement(sql); |  |  |  | 		pstmt = connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt.setInt(1, id); |  |  |  | 		pstmt.setInt(1, id); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		//Base.closeResource(null, null, null);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		connection.close(); |  |  |  | 		connection.close(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if(resultSet.next()) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			return resultSet; |  |  |  | 		if (resultSet.next()) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			return resultSet;  // 返回查询到的结果
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return null; |  |  |  | 		return null;  // 没有找到对应的书籍
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	/* 没用 */ |  |  |  | 	/** | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * 获取规则信息(此方法未使用) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @return 包含规则信息的JSONArray | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @throws ClassNotFoundException | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 * @throws SQLException | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static JSONArray getRules() throws ClassNotFoundException, SQLException { |  |  |  | 	public static JSONArray getRules() throws ClassNotFoundException, SQLException { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Connection connection = null; |  |  |  | 		Connection connection = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		PreparedStatement pstmt = null; |  |  |  | 		PreparedStatement pstmt = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ResultSet resultSet = null; |  |  |  | 		ResultSet resultSet = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String sql = "select * from rules"; |  |  |  | 		String sql = "select * from rules"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		JSONObject jsonObject = new JSONObject(); |  |  |  | 		JSONObject jsonObject = new JSONObject(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		JSONArray jsonArray = new JSONArray(); |  |  |  | 		JSONArray jsonArray = new JSONArray(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 	String result = ""; |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		connection = Base.getConnection(); |  |  |  | 		connection = Base.getConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		pstmt = connection.prepareStatement(sql); |  |  |  | 		pstmt = connection.prepareStatement(sql); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		resultSet = pstmt.executeQuery(); |  |  |  | 		resultSet = pstmt.executeQuery(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 	while(resultSet.next()) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		// 遍历规则表,构造JSON对象
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		while (resultSet.next()) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			jsonObject.put("id", resultSet.getString("id")); |  |  |  | 			jsonObject.put("id", resultSet.getString("id")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			jsonObject.put("borrow_num", resultSet.getString("borrow_num")); |  |  |  | 			jsonObject.put("borrow_num", resultSet.getString("borrow_num")); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			jsonObject.put("borrow_library", resultSet.getString("borrow_library")); |  |  |  | 			jsonObject.put("borrow_library", resultSet.getString("borrow_library")); | 
			
		
	
	
		
		
			
				
					|  |  | @ -195,17 +227,15 @@ public class Admin { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			jsonArray.add(jsonObject); |  |  |  | 			jsonArray.add(jsonObject); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			System.out.println(jsonArray.toString()); |  |  |  | 			System.out.println(jsonArray.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Base.closeResource(connection, pstmt, resultSet); |  |  |  | 		Base.closeResource(connection, pstmt, resultSet); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return jsonArray; |  |  |  | 		return jsonArray; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static void main(String[] args) throws ClassNotFoundException, SQLException { |  |  |  | 	public static void main(String[] args) throws ClassNotFoundException, SQLException { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		//Common common = new Common();
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		//System.out.println(common.getCount("books"));
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		Admin admin = new Admin(); |  |  |  | 		Admin admin = new Admin(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		System.out.println(admin.getSortName("2")); |  |  |  | 		System.out.println(admin.getSortName("2"));  // 示例,获取分类名称
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		//Map map =  admin.getBookList("1", "100");
 |  |  |  | 		// Map map =  admin.getBookList("1", "100");
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		//System.out.println( map.get("count"));
 |  |  |  | 		// System.out.println(map.get("count"));  // 示例,获取书籍数量
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |