作者主页:Java毕设网
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一、项目介绍
该项目为图书管理系统,主要功能如下所示:
首页:图书借阅排行榜;
系统设置:图书馆信息、管理员设置、参数设置、书架设置;
读者管理:读者类型管理、读者档案管理;
图书管理:图书类型设置、图书档案管理;
图书借还:图书借阅、图书续借、图书归还;
系统查询:图书档案查询、图书借阅查询、借阅到期提醒;
更改口令;退出系统;
二、环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
三、技术栈
1. 后端:Structs
2. 前端:JSP+css+Javascript
四、使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
3. 将项目中connDB.properties配置文件中的数据库配置改为自己的配置;
将项目中src/com/core/ConnDB.java配置文件中的第15行和第25行数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/booksManager 登录
管理员用户名:admin 密码:admin
五、运行截图
六、相关代码
图书管理控制器
public class Book extends Action {
private BookDAO bookDAO = null;
public Book() {
this.bookDAO = new BookDAO();
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String action =request.getParameter("action");
if(action==null||"".equals(action)){
request.setAttribute("error","您的操作有误!");
return mapping.findForward("error");
}else if("bookAdd".equals(action)){
return bookAdd(mapping,form,request,response);
}else if("bookQuery".equals(action)){
return bookQuery(mapping,form,request,response);
}else if("bookModifyQuery".equals(action)){
return bookModifyQuery(mapping,form,request,response);
}else if("bookModify".equals(action)){
return bookModify(mapping,form,request,response);
}else if("bookDel".equals(action)){
return bookDel(mapping,form,request,response);
}else if("bookDetail".equals(action)){
return bookDetail(mapping,form,request,response);
}else if("bookifQuery".equals(action)){
return bookifQuery(mapping,form,request,response);
}
request.setAttribute("error","操作失败!");
return mapping.findForward("error");
}
/***********************添加图书信息**************************/
private ActionForward bookAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
BookForm bookForm = (BookForm) form;
bookForm.setBarcode(bookForm.getBarcode());
bookForm.setBookName(bookForm.getBookName());
bookForm.setTypeId(bookForm.getTypeId());
bookForm.setAuthor(bookForm.getAuthor());
bookForm.setTranslator(bookForm.getTranslator());
bookForm.setIsbn(bookForm.getIsbn());
bookForm.setPrice(bookForm.getPrice());
bookForm.setPage(bookForm.getPage());
bookForm.setBookcaseid(bookForm.getBookcaseid());
//获取系统日期
Date date1=new Date();
java.sql.Date date=new java.sql.Date(date1.getTime());
bookForm.setInTime(date.toString());
bookForm.setOperator(bookForm.getOperator());
int a=bookDAO.insert(bookForm);
if(a==1){
return mapping.findForward("bookAdd");
}else if(a==2){
request.setAttribute("error","该图书信息已经添加!");
return mapping.findForward("error");
}else{
request.setAttribute("error","图书信息添加失败!");
return mapping.findForward("error");
}
}
/***********************查询全部图书信息**************************/
private ActionForward bookQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
String str=null;
request.setAttribute("book",bookDAO.query(str)); //将查询结果保存到book中
return mapping.findForward("bookQuery"); //转到显示图书信息列表页面
}
/***********************条件查询图书信息**************************/
private ActionForward bookifQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
String str=null;
if(request.getParameter("f")!=null){
str = request.getParameter("f") + " like '%" +
request.getParameter("key") + "%";
}
request.setAttribute("ifbook",bookDAO.query(str));
return mapping.findForward("bookifQuery");
}
/***********************查询修改图书信息**************************/
private ActionForward bookModifyQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
BookForm bookForm=(BookForm)form;
bookForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookQueryif",bookDAO.queryM(bookForm));
return mapping.findForward("bookQueryModify");
}
/***********************查询图书详细信息**************************/
private ActionForward bookDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
BookForm bookForm=(BookForm)form;
bookForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("bookDetail",bookDAO.queryM(bookForm));
return mapping.findForward("bookDeatil");
}
/***********************修改图书信息**************************/
private ActionForward bookModify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
BookForm bookForm=(BookForm)form; //实例化BookForm类
bookForm.setBarcode(bookForm.getBarcode()); //获取并设置条形码属性
bookForm.setBookName(bookForm.getBookName());
bookForm.setTypeId(bookForm.getTypeId());
bookForm.setAuthor(bookForm.getAuthor());
bookForm.setTranslator(bookForm.getTranslator());
bookForm.setIsbn(bookForm.getIsbn());
bookForm.setPrice(bookForm.getPrice());
bookForm.setPage(bookForm.getPage());
bookForm.setBookcaseid(bookForm.getBookcaseid());
bookForm.setInTime(bookForm.getInTime());
bookForm.setOperator(bookForm.getOperator());
int ret=bookDAO.update(bookForm); //调用修改图书信息的方法update()
if(ret==0){
request.setAttribute("error","修改图书信息失败!");
return mapping.findForward("error"); //转到错误提示页面
}else{
return mapping.findForward("bookModify"); //转到修改成功页面
}
}
/***********************删除图书信息**************************/
private ActionForward bookDel(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
BookForm bookForm=(BookForm)form;
bookForm.setId(Integer.valueOf(request.getParameter("ID")));
int ret=bookDAO.delete(bookForm);
if(ret==0){
request.setAttribute("error","删除图书信息失败!");
return mapping.findForward("error");
}else{
return mapping.findForward("bookDel");
}
}
}
图书借阅管理控制器
public class Borrow extends Action {
/******************在构造方法中实例化Borrow类中应用的持久层类的对象**************************/
private BorrowDAO borrowDAO = null;
private ReaderDAO readerDAO=null;
private BookDAO bookDAO=null;
private ReaderForm readerForm=new ReaderForm();
public Borrow() {
this.borrowDAO = new BorrowDAO();
this.readerDAO=new ReaderDAO();
this.bookDAO=new BookDAO();
}
/******************************************************************************************/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
BorrowForm borrowForm = (BorrowForm) form;
String action =request.getParameter("action");
if(action==null||"".equals(action)){
request.setAttribute("error","您的操作有误!");
return mapping.findForward("error");
}else if("bookBorrowSort".equals(action)){
return bookBorrowSort(mapping,form,request,response);
}else if("bookborrow".equals(action)){
return bookborrow(mapping,form,request,response); //图书借阅
}else if("bookrenew".equals(action)){
return bookrenew(mapping,form,request,response); //图书续借
}else if("bookback".equals(action)){
return bookback(mapping,form,request,response); //图书归还
}else if("Bremind".equals(action)){
return bremind(mapping,form,request,response); //借阅到期提醒
}else if("borrowQuery".equals(action)){
return borrowQuery(mapping,form,request,response); //借阅信息查询
}
request.setAttribute("error","操作失败!");
return mapping.findForward("error");
}
/*********************图书借阅排行***********************/
private ActionForward bookBorrowSort(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
request.setAttribute("bookBorrowSort",borrowDAO.bookBorrowSort());
return mapping.findForward("bookBorrowSort");
}
/*********************图书借阅查询***********************/
private ActionForward borrowQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
String str=null;
String flag[]=request.getParameterValues("flag");
if (flag!=null){
String aa = flag[0];
if ("a".equals(aa)) {
if (request.getParameter("f") != null) {
str = request.getParameter("f") + " like '%" +
request.getParameter("key") + "%'";
}
}
if ("b".equals(aa)) {
String sdate = request.getParameter("sdate");
String edate = request.getParameter("edate");
if (sdate != null && edate != null) {
str = "borrowTime between '" + sdate + "' and '" + edate +
"'";
}
}
//同时选择日期和条件进行查询
if (flag.length == 2) {
if (request.getParameter("f") != null) {
str = request.getParameter("f") + " like '%" +
request.getParameter("key") + "%'";
}
String sdate = request.getParameter("sdate");
String edate = request.getParameter("edate");
String str1 = null;
if (sdate != null && edate != null) {
str1 = "borrowTime between '" + sdate + "' and '" + edate +
"'";
}
str = str + " and borr." + str1;
}
}
request.setAttribute("borrowQuery",borrowDAO.borrowQuery(str));
return mapping.findForward("borrowQuery");
}
/*********************到期提醒***********************/
private ActionForward bremind(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
request.setAttribute("Bremind",borrowDAO.bremind());
return mapping.findForward("Bremind");
}
/*********************图书借阅***********************/
private ActionForward bookborrow(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
//查询读者信息
//ReaderForm readerForm=(ReaderForm)form; //此处一定不能使用该语句进行转换
readerForm.setBarcode(request.getParameter("barcode"));
ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
request.setAttribute("readerinfo", reader);
//查询读者的借阅信息
request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
//完成借阅
String f = request.getParameter("f");
String key = request.getParameter("inputkey");
if (key != null && !key.equals("")) {
String operator = request.getParameter("operator");
BookForm bookForm=bookDAO.queryB(f, key);
if (bookForm!=null){
int ret = borrowDAO.insertBorrow(reader, bookDAO.queryB(f, key),
operator);
if (ret == 1) {
request.setAttribute("bar", request.getParameter("barcode"));
return mapping.findForward("bookborrowok");
} else {
request.setAttribute("error", "添加借阅信息失败!");
return mapping.findForward("error");
}
}else{
request.setAttribute("error", "没有该图书!");
return mapping.findForward("error");
}
}
return mapping.findForward("bookborrow");
}
/*********************图书继借***********************/
private ActionForward bookrenew(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
//查询读者信息
readerForm.setBarcode(request.getParameter("barcode"));
ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
request.setAttribute("readerinfo", reader);
//查询读者的借阅信息
request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
if(request.getParameter("id")!=null){
int id = Integer.parseInt(request.getParameter("id"));
if (id > 0) { //执行继借操作
int ret = borrowDAO.renew(id);
if (ret == 0) {
request.setAttribute("error", "图书继借失败!");
return mapping.findForward("error");
} else {
request.setAttribute("bar", request.getParameter("barcode"));
return mapping.findForward("bookrenewok");
}
}
}
return mapping.findForward("bookrenew");
}