转载

图书管理系统——面向对象程序设计

一、登陆系统模块的实现

本模块主要是用户通过图书馆管理系统的首页进入该系统。用户输入正确的用户名和密码,如果登录信息有错误,则系统提示登录错误信息,并且禁止系统用户进行任何操作。若登录信息正确,系统会根据用户的身份进行相应权限的判断,读者进入前台系统,管理员进入后台系统。

二、图书管理系统代码:

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

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

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

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

listAllAcademy() { return this.getHibernateTemplate().find("from TAcademy ta"); }

public List

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

listAllStudent(Page page) {

Session session =

this.getHibernateTemplate().getSessionFactory().openSession(); Query q = session.createQuery("from TStudent ts"); q.setFirstResult(page.getStartRow()); q.setMaxResults(5); List

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

list = q.list(); if(list.size() != 0) { TBookStudent bookStudent = list.get(0); this.getHibernateTemplate().delete(bookStudent); return true; }

return false;

}

7.(1) 图书检索模块的实现

本模块主要是用户能够输入自己想要查询图书的条件来快速的检索。

public List

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

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 list = q.list(); return list;

}

正文到此结束
Loading...