First, the realization of the landing system module
This module is mainly the user through the Library Management System home page into the system. The user enters the correct user name and password, and if there is an error in the login information, the system prompts for a logon error message and prohibits any action by the system user. If the login information is correct, the system will be based on the user's identity to determine the appropriate permissions, readers into the front-end system, the administrator into the backend system.
Second, the book Management system code:
1. (1) Library System login Main Page
Action layer:
Public String Login () { boolean flag = Iss.login (Admin); if (flag) { return " Success "; }
Message =" username or password Error! ";
Return" fail "; }
Service layer:
Public boolean login (tadmin Admin) { tadmin a = Isd.logi N (Admin); if (a = null) { return true; }
return false; }
DAO Layer:
Publi C 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. The realization of Library Management module
Library Management module is mainly divided into books storage, view books, statistics books, library storage is to book management database to add books information. See the book function can view the book details, and the book information to modify or delete some of the discarded books information.
(1) The Realization of library storage function
Click Add Book function, fill in the basic information of the book, select the type for the book, type is a drop-down list dynamically generated with the database interaction.
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) Realization of Book maintenance function
Click on the book maintenance feature to display a list of all books, delete and modify operations after each book information line, and click the details of the selected book information to view the book information in detail.
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) Delete the library function
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) Modify the implementation of the library information function
public String modifyinfobook () {
this.sortlist = Ibs.listbooksort (); book = Ibs.queryonebookbyid (booknum); return "Modifyinfo"; }
public String Modifysavebook () { ibs.modifybook (book); book = null; Booklist = This.listBook (); nbsp; return ' book ';
}
Public Tbook Queryonebookbyid (String booknum) {
Tbook book = (tbook) this.ge TSession (). 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) View the implementation of the book details feature
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. Implementation of Student Management module
The Student management module is divided into adding students, viewing students, revising students, and viewing student details.
(1) The realization of students ' adding function
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); It implements the following code:
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) Realization of Student's maintenance function
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) Delete the implementation of student function
Admin Delete reader, delete one when deleted, You can also delete multiple selections at the same time.
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) The realization of modifying students ' information function
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) View the implementation of the reader's detailed information function
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. The realization of the Borrowing Information management module
The Library information management module is mainly divided into the book borrowing, handling the book return, borrowing Information view, in which the borrowing information can be viewed by the book number and library card number.
(1) The realization of the function of book borrowing
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 "The book has been borrowed!" "; } tstudent student = Ild.getonestudent (Bookstudent.getstudentid ()); if (student.getlendednum () = = 9) {return "the number of borrowed books has reached the maximum and cannot be borrowed!" "; } 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); The calculation of the amount owed is ild.savebookstudent (bookstudent); Book.setcurrentnum (Book.getcurrentnum ()-1); Ild.modifybook (book); Student.setlendednum (Student.getlendednum () +1); Ild.modifystudent (student); Return "Library success! "; }
public void Savebookstudent (Tbookstudent bookstudent) {
This.gethibernatetemplate (). Save (Bookstudent); }
(2) Realization of the function of book return
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 ' does not have this record! "; } book.setcurrentnum (Book.getcurrentnum () +1); Student.setlendednum (Student.getlendednum ()-1);
Return "book success"; }
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) Realization of book Retrieval module
This module is mainly the user can enter their own to query the conditions of the book to quickly search.
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;
}
Third, the procedure
Book Management system--object-oriented programming