一、登陆系统模块的实现
本模块主要是用户通过图书馆管理系统的首页进入该系统。用户输入正确的用户名和密码,如果登录信息有错误,则系统提示登录错误信息,并且禁止系统用户进行任何操作。若登录信息正确,系统会根据用户的身份进行相应权限的判断,读者进入前台系统,管理员进入后台系统。
二、图书管理系统代码:
1.(1)图书馆系统登录主页面
Action层:
public String login() { boolean flag = iss.login(admin); if(flag) { return "success"; }
message = "用户名或口令错误!";
return "fail"; }
Service层:
public boolean login(TAdmin admin) { TAdmin a = isd.login(admin); if(a != null) { return true; }
return false; }
Dao层:
public TAdmin login(TAdmin admin) {
Session session =
this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery("from TAdmin a where a.adminName = ?
and a.adminPassword = ?").setString(0,
admin.getAdminName()).setString(1, admin.getAdminPassword()); TAdmin a = (TAdmin)q.uniqueResult();
return a;
}
2.图书管理模块的实现
图书管理模块主要分为图书入库、查看图书、统计图书,其中图书入库是往图书管理数据库中添加图书信息。看图书功能中可以查看图书详细信息,并对图书信息进行修改或删除某些废弃图书信息。
(1)图书入库功能的实现
点击添加图书功能,填写图书基本信息,为图书选择类型,类型是与数据库交互动态生成的下拉列表.
public String addInfoBook() {
this.sortList = ibs.listBookSort();
return "add"; }
public List<TSort> listBookSort() { return this.getHibernateTemplate().find("from TSort tsort"); }
public String addSaveBook() { ibs.saveBook(book); book = null; bookList = this.listBook(); return "Book"; }
public void saveBook(TBook book) { Date now = new Date(); book.setBuyDate(now); book.setCurrentNum(book.getTotalNum()); ibd.saveBook(book); }
public void saveBook(TBook book) {
this.getHibernateTemplate().save(book); }
3.(1)图书维护功能的实现
点击图书维护功能,展示所有图书的信息列表,在每个图书信息行后提供删除和修改操作功能,并且可以单击选定某一个图书信息后的详细信息进行详细查看图书信息。
public String listAllBook() { bookList = this.listBook(); return "Book"; }
public List<TBook> listBook(TBook book, Page page) { String hql = "from TBook tb where 1=1";
if(book!=null) {
if(book.getBookNum() != null
&& !"".equals(book.getBookNum().trim())) {
hql = hql + " and tb.bookNum = '" + book.getBookNum()+"'"; }
if(book.getBookName() != null
&& !"".equals(book.getBookName().trim())) {
hql = hql + " and tb.bookName = '" + book.getBookName()+"'";
}
if(book.getWriter() != null
&& !"".equals(book.getWriter().trim())) { hql = hql + " and tb.writer = '" + book.getWriter()+"'"; }
if(!book.getSortId().getSortId().trim().equals("-1")) {
hql = hql + " and tb.sortId.sortId = '" + book.getSortId().getSortId()+"'";
} hql = hql + " order by tb.bookName"; } else { hql = hql + " order by tb.buyDate desc"; }
Session session =
this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery(hql); q.setFirstResult(page.getStartRow()); q.setMaxResults(5); List<TBook> list = q.list();
return list;
(2)删除图书功能的实现
public String deleteOneBook() { ibs.delBookById(bookNum); bookList = this.listBook(); return "Book"; }
public String deleteMoreBook() { ibs.delMoreBook(bookNums);
bookList = this.listBook();
return "Book"; }
public void delBookById(String bookNum) {
this.getHibernateTemplate().delete(this.getHibernateTemplate().
get(TBook.class, bookNum)); }
public void delMoreBook(String[] bookNums) {
for(int i=0; i<bookNums.length;i++) {
this.getHibernateTemplate().delete(this.getHibernateTemplate().
get(TBook.class, bookNums[i])); }
}
(3)修改图书信息功能的实现
public String modifyInfoBook() {
this.sortList = ibs.listBookSort(); book = ibs.queryOneBookById(bookNum); return "modifyInfo"; }
public String modifySaveBook() { ibs.modifyBook(book); book = null; bookList = this.listBook(); return "Book";
}
public TBook queryOneBookById(String bookNum) {
TBook book = (TBook)this.getSession().createQuery("from TBook tb where tb.bookNum = ?").setString(0, bookNum).uniqueResult(); this.getSession().close(); return book;
}
public void modifyBook(TBook book) { this.getHibernateTemplate().update(book);
}
(4)查看图书详细信息功能的实现
public String infoDetailBook() { book = ibs.queryOneBookById(bookNum); return "Detail";
}
public TBook queryOneBookById(String bookNum) {
TBook book = (TBook)this.getSession().createQuery("from TBook tb where tb.bookNum = ?").setString(0, bookNum).uniqueResult(); this.getSession().close(); return book;
}
4. 学生管理模块的实现
学生管理模块主要分为添加学生、查看学生、修改学生,查看学生的详细信息。
(1)学生添加功能的实现
public String addInfoStudent() { this.academyList = iss.listAllAcademy(); return "add"; }
public void addStudent(TStudent student) { Date now = new Date(); student.setCreateDate(now); student.setLendedNum(0);
isd.saveStudent(student); } 其实现的代码如下:
public String addInfoStudent() { this.academyList = iss.listAllAcademy(); return "add"; }
public void addStudent(TStudent student) { Date now = new Date(); student.setCreateDate(now); student.setLendedNum(0);
isd.saveStudent(student); }
public List<TAcademy> listAllAcademy() { return this.getHibernateTemplate().find("from TAcademy ta"); }
public List<TClass> listAllClass() { return this.getHibernateTemplate().find("from TClass tc"); }
public void saveStudent(TStudent student) {
this.getHibernateTemplate().save(student); }
(2)学生维护功能的实现
public String listAllStudent() { studentList = this.getStudentListByPage();
return "Student"; }
public List<TStudent> listAllStudent(Page page) {
Session session =
this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery("from TStudent ts"); q.setFirstResult(page.getStartRow()); q.setMaxResults(5); List<TStudent> list = q.list();
return list; }
5.(1)删除学生功能的实现
管理员删除读者,删除时可删除一个,也可同时多选删除。
public String deleteOneStudent() { iss.deleteOneStudent(studentNum); studentList = this.getStudentListByPage(); return "Student"; }
public String deleteMoreStudent() { iss.deleteMoreStudent(studentNums); studentList = this.getStudentListByPage();
return "Student"; }
public void deleteOneStudent(String studentNum) {
this.getHibernateTemplate().delete(this.getHibernateTemplate().get(TStudent.class, studentNum)); }
public void deleteMoreStudent(String[] studentNums) { for(int i=0;i<studentNums.length;i++) {
this.getHibernateTemplate().delete(this.getHibernateTemplate().get(TStudent.class, studentNums[i])); }
}
(2)修改学生信息功能的实现
public String modifyInfoStudent() { this.student = iss.getStudentByid(studentNum); this.academyList = iss.listAllAcademy();
this.classList =
iss.listClassById(student.getAcademyId().getAcademyId()); return "modifyInfo"; }
public String modifySaveStudent() { iss.modifyStudentByid(student); student = null; studentList = this.getStudentListByPage(); return "Student";
}
public TStudent getStudentByid(String studentNum) {
return (TStudent)this.getHibernateTemplate().get(TStudent.class, studentNum); }
public void modifyStudentByid(TStudent student) { this.getHibernateTemplate().update(student);
}
(3)查看读者详细信息功能的实现
public String infoDetailStudent() { student = iss.getOneStudentById(studentNum);
return "Detail"; }
public TStudent queryOneStudentById(String studentNum) {
TStudent student = (TStudent)this.getSession().createQuery("from TStudent ts where ts.studentNum = ?").setString(0, studentNum).uniqueResult(); this.getSession().close();
return student;
}
6. 借阅信息管理模块的实现
借书信息管理模块主要分为办理图书借阅、办理图书归还、借阅信息查看,其中借阅信息查看可按图书编号和借书证编号查看。
(1)办理图书借阅功能的实现
public String saveBookStudent() { message = ils.saveBookStudent(bookStudent); return "success"; }
public String saveBookStudent(TBookStudent bookStudent) { TBook book = ild.getOneBook(bookStudent.getBookId()); if(book.getCurrentNum() == 0) { return "该书已被借完!"; } TStudent student = ild.getOneStudent(bookStudent.getStudentId()); if(student.getLendedNum() == 9) { return "借书数量已达到最大,不能在借!"; } Date borrowDate = new Date(); long l = borrowDate.getTime(); long ll = l + 30*24*60*60*1000L;
Date returnDate = new Date(ll);
bookStudent.setBorrowDate(borrowDate); bookStudent.setReturnDate(returnDate); bookStudent.setMoney(0d); //补上所欠金额的计算 ild.saveBookStudent(bookStudent); book.setCurrentNum(book.getCurrentNum()-1); ild.modifyBook(book); student.setLendedNum(student.getLendedNum()+1); ild.modifyStudent(student); return "借书成功!"; }
public void saveBookStudent(TBookStudent bookStudent) {
this.getHibernateTemplate().save(bookStudent); }
(2)办理图书归还功能的实现
public String delBookStudent() { message = ils.delBookStudent(bookStudent); return "success"; }
public String delBookStudent(TBookStudent bookStudent) { TBook book = ild.getOneBook(bookStudent.getBookId()); TStudent student = ild.getOneStudent(bookStudent.getStudentId());
boolean flag = ild.delBookStudent(bookStudent.getStudentId(), bookStudent.getBookId()); if(!flag) { return "没有该 记录!"; } book.setCurrentNum(book.getCurrentNum()+1); student.setLendedNum(student.getLendedNum()-1);
return "还书成功"; }
public boolean delBookStudent(String studentId, String bookId) {
Session session =
this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery("from TBookStudent tbs where tbs.studentId = ? and tbs.bookId = ?").setString(0, studentId).setString(1, bookId); List<TBookStudent> list = q.list(); if(list.size() != 0) { TBookStudent bookStudent = list.get(0); this.getHibernateTemplate().delete(bookStudent); return true; }
return false;
}
7.(1) 图书检索模块的实现
本模块主要是用户能够输入自己想要查询图书的条件来快速的检索。
public List<TBook> listBook() { this.sortList = ibs.listBookSort(); if(page == null) { page = new Page(); page.setCurrentPage(1); } page.setTotalRow(ibs.getBookNum(book)); page.setTotalPage((page.getTotalRow()+4)/5); page.setStartRow((page.getCurrentPage()-1) * 5); return ibs.listBook(book, page); }
public List<TBook> listBook(TBook book, Page page) { String hql = "from TBook tb where 1=1"; if(book!=null) {
if(book.getBookNum() != null
&& !"".equals(book.getBookNum().trim())) { hql = hql + " and tb.bookNum = '" + book.getBookNum()+"'";
}
if(book.getBookName() != null
&& !"".equals(book.getBookName().trim())) {
hql = hql + " and tb.bookName = '" + book.getBookName()+"'"; } if(book.getWriter() != null
&& !"".equals(book.getWriter().trim())) { hql = hql + " and tb.writer = '" + book.getWriter()+"'"; } if(!book.getSortId().getSortId().trim().equals("-1")) {
hql = hql + " and tb.sortId.sortId = '" +
book.getSortId().getSortId()+"'"; } hql = hql + " order by tb.bookName"; } else { hql = hql + " order by tb.buyDate desc"; } Session session =
this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery(hql); q.setFirstResult(page.getStartRow()); q.setMaxResults(5);
List<TBook> list = q.list(); return list;
}
三、程序截图