图书管理模糊查询代码
时间: 2024-06-11 15:02:19 浏览: 13
图书管理系统中的模糊查询是指用户可以输入一个关键字,系统会根据这个关键字在数据库中进行查找,并返回与之匹配的图书信息。以下是一个简单的图书管理系统模糊查询代码示例:
```
import sqlite3
# 连接到数据库
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
# 接收用户输入的关键字
keyword = input("请输入要查询的关键字:")
# 查询语句
sql = "SELECT * FROM books WHERE title LIKE '%{}%' OR author LIKE '%{}%'".format(keyword, keyword)
# 执行查询
cursor.execute(sql)
results = cursor.fetchall()
# 输出查询结果
if len(results) == 0:
print("没有找到匹配的图书!")
else:
for row in results:
print(row)
# 关闭数据库连接
conn.close()
```
以上代码使用SQLite数据库,首先连接到数据库,然后接收用户输入的关键字,使用`LIKE`关键字进行模糊查询,并将查询结果输出。如果没有找到匹配的图书,则输出提示信息。最后关闭数据库连接。
相关问题
图书管理系统web前端代码
图书管理系统web前端代码是一个基于网页浏览器运行的应用程序的用户界面,它通过丰富的图形化和交互式操作,提供了一个友好的图书管理项目的使用界面。为了实现这个功能,前端开发人员通常会使用CSS、JavaScript、Vue.js、React等技术栈,前端代码包括页面布局、样式设计、交互行为、数据请求、表单验证、响应式设计等等方面。
在图书管理系统web前端代码中,主要实现了以下功能:
1. 用户注册和登录功能,用户可以通过注册并登录账户访问该系统。
2. 图书查询和借阅功能,用户可以通过简单的输入查询到所需图书,并完成借阅操作。
3. 图书收藏和评价功能,用户收藏自己喜欢的图书并对图书进行评价。
4. 系统管理功能,管理员可以添加、删除、修改图书信息、用户信息、借阅记录等系统管理。
5. 高效的数据管理和数据展示功能,对于大量数据的操作有一定的支持。
6. 其他功能,包括模糊搜索、分页、数据统计、导出Excel等功能。
总体而言,图书管理系统web前端代码是一个与用户交互最多的模块,为了让用户能够更好的使用该系统,前端程序员在不断地优化前端界面功能和用户体验,为图书管理系统的实现提供了一个更加友好的界面。
javaweb实现图书管理系统 源代码
以下是一个基于javaweb的图书管理系统的源代码示例:
```java
// 省略了部分代码
// 登录功能
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username"); String password = request.getParameter("password");
User user = new UserDao().login(username, password);
if (user != null) {
HttpSession session = request.getSession();
session.setAttribute("user", user);
response.sendRedirect("index.jsp");
} else {
response.sendRedirect("login.jsp?error=1");
}
}
}
// 添加图书功能
public class AddBookServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String bookName = request.getParameter("bookName");
String author = request.getParameter("author");
String publisher = request.getParameter("publisher");
String price = request.getParameter("price");
Book book = new Book(bookName, author, publisher, Double.parseDouble(price));
new BookDao().addBook(book);
response.sendRedirect("bookList.jsp");
}
}
// 模糊搜索功能
public class SearchBookServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String keyword = request.getParameter("keyword");
List<Book> bookList = new BookDao().searchBook(keyword);
request.setAttribute("bookList", bookList);
request.getRequestDispatcher("bookList.jsp").forward(request, response);
}
}
// 借书功能
public class BorrowBookServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String[] bookIds = request.getParameterValues("bookId");
User user = (User) request.getSession().getAttribute("user");
new BorrowDao().borrowBook(user.getUserId(), bookIds);
response.sendRedirect("borrowList.jsp");
}
}
// 还书功能
public class ReturnBookServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String[] borrowIds = request.getParameterValues("borrowId");
new BorrowDao().returnBook(borrowIds);
response.sendRedirect("borrowList.jsp");
}
}
```
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)