管理员端
图书管理:根据图书编号、图书名称查询图书基本信息,添加、修改、删除图书。
图书分类管理:根据分类名称查询图书分类信息,添加、修改、删除图书分类。
图书借阅:展示所有正在借阅图书的信息。
图书归还:展示所有已归还图书的信息。
公告管理:向用户发布公告。
读者管理:根据账号、姓名查询读者基本信息,添加、修改、删除读者信息。
我的:查看个人资料,修改账户密码,退出系统。
04 工程结构及其说明项目名称:manage_books
Package包说明:
05 主要功能详细设计与实现 5.1 用户端--图书查询模块
用户访问图书查询模块时显示当前可以借阅图书,有按图书名称查询图书信息的功能,可以进行借书操作。
其中查询功能的Servlet代码如下: package com.cya.controller; import java.io.IOException; import java.util.ArrayList; 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.cya.dao.BookDao; import com.cya.pojo.Book; /** * Servlet implementation class selectServlet */ @WebServlet("/selectServlet") public class selectServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public selectServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //doGet(request, response); request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); //因为在管理员界面和读者界面都有查找功能,为了将查找的结果返回正确的页面,设置了tip,tip=1表示管理员界面 int tip = Integer.parseInt(request.getParameter("tip")); String name = request.getParameter("name"); BookDao bookdao = new BookDao(); ArrayList<Book> data = bookdao.getLikeList(name); //将获取的结果存入请求中 request.setAttribute("data", data); String url = ""; //转发不同的界面 if (tip == 1) { url = response.encodeURL("/books/admin/admin_books.jsp"); } else { url = response.encodeURL("/books/user/select.jsp"); } //将请求转发 request.getRequestDispatcher(url).forward(request, response); } } 5.2 用户端--借阅信息模块
当普通用户借阅完图书,会在该模块自动生成借阅信息,如借阅日期,归还日期,也可在该模块进行还书,如下图所示。
其中,还书功能的Servlet代码如下: package com.cya.controller; import java.io.IOException; import java.io.PrintWriter; 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 javax.servlet.http.HttpSession; import com.cya.pojo.Admin; import com.cya.dao.AdminDao; import com.cya.dao.BookDao; /** * Servlet implementation class borrowServlet */ @WebServlet("/borrowServlet") public class borrowServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public borrowServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //response.getWriter().append("Served at: ").append(request.getContextPath()); //设置编码类型 request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); BookDao bookdao = new BookDao(); //为了区分借书和还书的功能,设置tip,tip为1,表示借书 int tip = Integer.parseInt(request.getParameter("tip")); if (tip == 1) { //获取图书id int bid = Integer.parseInt(request.getParameter("bid")); HttpSession session = request.getSession(); Admin admin = new Admin(); String status=request.getParameter("status"); String; if(status.equals("user")) { //获取到存入session的读者id id = (String) session.getAttribute("uid"); } else { //获取到存入session的aid读者id id = (String) session.getAttribute("aid"); } AdminDao admindao = new AdminDao(); //通过aid获取到读者的信息 admin = admindao.get_AidInfo2(id); //将借阅记录存入数据表 bookdao.borrowBook(bid, admin); response.sendRedirect("/manage_books/books/user/select.jsp"); } else { //还书功能,获取借阅记录的hid int hid = Integer.parseInt(request.getParameter("hid")); /** * 还书在管理员和读者界面都有,为了区分,设置了show字段,show为1表示读者界面 */ int show = Integer.parseInt(request.getParameter("show")); //调用还书函数,改变status字段 bookdao.borrowBook2(hid); if (show == 1) { response.sendRedirect("/manage_books/books/user/borrow.jsp"); } else { response.sendRedirect("/manage_books/books/admin/admin_borrows.jsp"); } } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } 5.3 管理员端--图书管理模块