function design of library Management module

Source: Internet
Author: User
Tags date1

The specific functions of the Library management function module are as follows:
1 View a list of book listings: basic information for displaying books.
2 book details: Used to display detailed information about a specified book.
3 Adding book information: Used to add book information.
4 Modify book information: used to modify the book information.
5 Delete book information: Used to delete book information.
6 Query Book information: used to query the information of books according to different conditions.


Library Archives Management function module file Schema 1 is shown.

Library Archives Management function module file Schema 1 is shown.

The data tables involved in the Library Archives management module are the book Information table (Tb_bookinfo), the Bookshelf setting table (Tb_bookcase), the Book Type table (Tb_booktype) and the Publishing House information table (tb_publishing). These 4 data tables are correlated by corresponding fields, as shown in 2.


The action implementation of the library file function module inherits the action class. In this class, you first need to instantiate the Bookdao class of the Library archive module in the constructor method of the class (this class is used to implement interaction with the database). Action

The primary method of implementing a class is perform (), which is automatically executed and does not itself have a specific transaction, which is performed according to the action parameter value obtained by the GetParameter () method of HttpServletRequest.

Library Archive Management Module The key code for the action implementation class is as follows:
Import org.apache.struts.action.*;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Com.actionForm.BookForm;
Import org.apache.struts.action.Action;
Import Com.dao.BookDAO;
Import Java.util.Date;
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", "Your operation is wrong!") ");
Return Mapping.findforward ("error");
}else if ("Bookadd". Equals (action)) {
Return Bookadd (Mapping,form,request,response); Add book information
}else if ("Bookquery". Equals (action)) {
Return Bookquery (Mapping,form,request,response); Search all book Information
}else if ("Bookmodifyquery". Equals (action)) {
Return Bookmodifyquery (Mapping,form,request,response); Query to be applied when modifying book information
}else if ("Bookmodify". Equals (action)) {
Return bookmodify (Mapping,form,request,response); Modify book information
}else if ("Bookdel". Equals (action)) {
Return Bookdel (Mapping,form,request,response); Delete Book information
}else if ("Bookdetail". Equals (action)) {
Return Bookdetail (Mapping,form,request,response); Query book details
}else if ("Bookifquery". Equals (action)) {
Return Bookifquery (Mapping,form,request,response); Search for book information by different conditions
}
Request.setattribute ("Error", "Operation failed!") ");
Return Mapping.findforward ("error");
}
...///The other methods in this class are omitted here
}
after the administrator has logged in, select the "Book Management"/"Book Archive Management" menu item and go to the View Book List page, where you will see a list of all the book information, as well as a hyperlink to add book information, delete the book information, modify the book information.

View the book Information list page as shown in running result 3.


Open the Js\menu that holds all the JavaScript code that implements the translucent background menu. JS "file, you can find the hyperlink code for the" Book Archives Management "menu item as shown below:
<a href=book.do?action=bookquery> Book Archives Management </a>
As you can see from the URL address above, the parameter value of the action involved in viewing the book Information List module is "Bookquery", and when Action=bookquery, a method Bookquery () is called to view the book information list, as follows:
if ("Bookquery". Equals (action)) {
Return Bookquery (Mapping,form,request,response);
}
In the method Bookquery () to view the book information list, first call the query () method in the Bookdao class to search all the library information, and then save the returned query results to the HttpServletRequest object book. To view a list of books information, the specific code for Bookquery () is as follows:
Private Actionforward Bookquery (actionmapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response) {
String Str=null;
Request.setattribute ("book", Bookdao.query (str));
Return Mapping.findforward ("Bookquery");
}
As you can see from the above code, the method of viewing the Bookdao class used by the book Information list is query (). In the query () method, the value of the Strif is queried first based on the values of the parameters (the value of Strif at this time is null, so the entire library information is queried), and then the query results are saved to the collection container class and returned to the container class. The specific code for the query () method is as follows:
Public Collection query (String strif) {
Bookform Bookform=null;
Collection bookcoll=new ArrayList ();
String sql= "";
if (strif!= "All" && strif!=null && strif!= "") {
Sql= "SELECT * from" (select B.*,c.name as bookcasename,p.pubname as Publishing,t.typename from Tb_bookinfo B left join Tb_b Ookcase C on b.bookcase=c.id join Tb_publishing p in B.ISBN=P.ISBN join Tb_booktype T on B.typeid=t.id where b.del=0) as B ook where book. " +strif+ "'";
}else{
Sql= "Select B.*,c.name as bookcasename,p.pubname as Publishing,t.typename from Tb_bookinfo B left joins Tb_bookcase C on B. Bookcase=c.id join Tb_publishing p on B.ISBN=P.ISBN joins Tb_booktype T on b.typeid= t.id where b.del=0 ";
}
ResultSet rs=conn.executequery (SQL);
try {
while (Rs.next ()) {
Bookform=new bookform ();
Bookform.setbarcode (rs.getstring (1));
Bookform.setbookname (rs.getstring (2));
Bookform.settypeid (Rs.getint (3));
Bookform.setauthor (Rs.getstring (4));
Bookform.settranslator (Rs.getstring (5));
BOOKFORM.SETISBN (rs.getstring (6));
Bookform.setprice (Float.valueof (rs.getstring (7))); Type conversions are required here
Bookform.setpage (Rs.getint (8));
Bookform.setbookcaseid (Rs.getint (9));
Bookform.setstorage (Rs.getint (10));
Bookform.setintime (rs.getstring (11));
Bookform.setoperator (rs.getstring (12));
Bookform.setdel (Rs.getint (13));
Bookform.setid (Integer.valueof (rs.getstring (14)));
Bookform.setbookcasename (rs.getstring (15));
Bookform.setpublishing (Rs.getstring (16));
Bookform.settypename (Rs.getstring (17));
Bookcoll.add (Bookform);
}
} catch (SQLException ex) {
}
Conn.close ();
return bookcoll;
}
in the Struts-config.xml file, configure the <forward> elements involved in viewing the list of book information as follows:
<forward name= "Bookquery" path= "/book.jsp"/>
The next task is to display the query results returned by the Bookquery () method in the action implementation class in the View book Information list page book.jsp. In book.jsp, the results of the query are first obtained through the Request.getattribute () method and saved in the connection container class, and the book information is displayed in a list in the page by looping.
After the administrator logs in to the system, select the "Book Management"/"Book Archive Management" menu item, go to the View Book list page, click on the "Add book information" hyperlink in this page and go to the Add Book information page. The Add book information page runs as shown in result 4.
The Add book information page is primarily used to collect input book information, and to verify that the input information is legitimate through a custom JavaScript function, as shown in table 1 of the form elements involved in the page.
After entering legitimate book information in the Add Book information page, click the Save button and the page will access a URL that is "Book.do?action=bookadd". From this URL address, you can know that the Add book information module involves the action parameter value of "Bookadd", that is, when action= Bookadd, will call the method of adding book information Bookadd (), the specific code is as follows:
if ("Bookadd". Equals (action)) {
Return Bookadd (Mapping,form,request,response);
}
In the method of adding book information Bookadd (), you first need to cast the received form information to the Actionform type, re-set the Setxxx method of the property by getting the GetXXX method of the specified property, and then call the Insert () in the Bookdao class Method, saves the added book information to the data table and saves the return value to the variable ret: If the return value is 1, the message is added successfully, the page is redirected to the Add Information success page, and if the return value is 2, the book information has been added and the error message "The book information has been added!" "Save to HttpServletRequest object error, and then redirect the page to the error message page, otherwise the error message" The book information added failed! "Save the object to HttpServletRequest in error, and redirect the page to the error prompt page." The specific code of the method Bookadd () for adding book information is as follows:
Private Actionforward Bookadd (actionmapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response) {
Bookform bookform = (bookform) Form;
...//This omits the code for the Setxxx method of setting the property with the GetXXX method of the related property
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", "The book information has been added!") ");
Return Mapping.findforward ("error");
}else{
Request.setattribute ("Error", "Book Info add failed!") ");
Return Mapping.findforward ("error");
}
}
As you can see from the code above, the method of adding the Bookdao class used by the book information page is insert (). In the Insert () method, first query the input book name or bar code from the data table Tb_bookinfo: If present, the flag variable is set to 2, otherwise the input information is saved to the book information table, the return value is assigned to the flag variable, and finally the flag variable is returned. Because the Insert () method that adds the book information is similar to the Insert () method for adding administrator information, only the SQL statements that query the name of the book entered or whether the barcode exists and inserts data into the book information table are given here.
The SQL statement that queries for the existence of the book name or barcode entered is as follows:
String sql1= "SELECT * from Tb_bookinfo WHERE barcode= '" +bookform.getbarcode () + "' or Bookname= '" +bookform.getbookname () + "'";
The SQL statement that inserts data into the Library information table is as follows:
sql = "Insert into Tb_bookinfo (Barcode,bookname,typeid,author,translator,isbn,price,page,bookcase,storage,intime, operator) VALUES (' "+bookform.getbarcode () +" ', ' "+bookform.getbookname () +" ', "+bookform.gettypeid () +", ' "+ Bookform.getauthor () + "', '" +bookform.gettranslator () + "', '" +BOOKFORM.GETISBN () + "'," +bookform.getprice () + "," + Bookform.getpage () + "," +bookform.getbookcaseid () + "," +bookform.getstorage () + ", '" +bookform.getintime () + "', '" + Bookform.getoperator () + "')";
In the Struts-config.xml file, configure the <forward> elements involved in adding the book information as follows:
<forward name= "Bookadd" path= "/book_ok.jsp?para=1"/>
After the administrator logs in to the system, select the "Book Management"/"Book Archive Management" menu item and go to the View Book List page, where you click on the "modify" hyperlink that follows the book information you want to edit and go to the "Modify book information" page. Modify the book information page as shown in the results of Operation 5.
After modifying the book information on the Edit book information page, click the Save button and the page will access a URL that is "book.do?action=bookmodify". From this URL address, you can know that saving modify book information involved in the parameter value of the action is "bookmodify", that is, when Action=bookmodify, will be called to save the modified book information Method Bookmodify (), the specific code is as follows:
if ("Bookmodify". Equals (action)) {
Return bookmodify (Mapping,form,request,response);
}
In saving the method Bookmodify () that modifies the book information, you first need to cast the received form information to the Actionform type and reset the Setxxx method of the property with the GetXXX method that obtains the specified property. Then call the update () method in the Bookdao class, save the modified book information to the data table Tb_bookinfo, and save the return value to the variable ret, if the return value is 0, indicating that the information modification failed, error message "Modify the book information failed!" "Save the object in HttpServletRequest to error, and then redirect the page to the message page, otherwise redirect the page to the Settings Information Success page." The specific code of the method Bookmodify () to save the modified book information is as follows:
Private Actionforward bookmodify (actionmapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response) {
Bookform bookform= (bookform) Form;
Bookform.setbarcode (Bookform.getbarcode ());
...//This omits the code for the Setxxx method of setting the property with the GetXXX method of the related property
int ret=bookdao.update (bookform);
if (ret==0) {
Request.setattribute ("Error", "Modify book information failed!") ");
Return Mapping.findforward ("error");
}else{
Return Mapping.findforward ("bookmodify");
}
}
As you can see from the code above, the method for saving the Bookdao class used to modify library information is update (). In the update () method, save the modified book information to the book Information table Tb_bookinfo, assign the return value to the flag variable, and finally return the flag variable. The specific code for the update () method is as follows:
public int update (Bookform bookform) {
String sql= "Update tb_bookinfo set typeid=" +bookform.gettypeid () + ", author= '" +bookform.getauthor () + "', translator= '" +bookform.gettranslator () + "', isbn= '" +BOOKFORM.GETISBN () + "', price=" +bookform.getprice () + ", page=" + Bookform.getpage () + ", bookcase=" +bookform.getbookcaseid () + ", storage=" +bookform.getstorage () + "where id=" + Bookform.getid () + "";
int falg=conn.executeupdate (SQL);
Conn.close ();
return falg;
}
In the Struts-config.xml file, configure the <forward> elements that are involved in modifying the book information page, with the following code:
<forward name= "bookmodify" path= "/book_ok.jsp?para=2"/>
After the administrator logs in to the system, select the "Book Management"/"Book Archive Management" menu item and go to the View Book List page, where you click the "delete" hyperlink that follows the book information you want to delete and go to the "Delete book information" page.
In the View book Information list page, you can find the hyperlink code that deletes the book information, as shown in the following code:
<a href= "book.do?action=bookdel&id=<%=id%>" > Delete </a>
As you can see from the URL address above, the parameter value of the action involved in deleting the book Information page is "Bookdel", and when Action=bookdel, the method Bookdel () that deletes the book information is called, the code is as follows:
if ("Bookdel". Equals (action)) {
Return Bookdel (Mapping,form,request,response);
}
In the method of deleting book Information Bookdel (), you first need to cast the received form information to the Actionform type, re-set the SetID method of the Actionform with the value of the obtained ID parameter, and then call Delete () in the Bookdao class Method deletes the specified book information and, based on the results of the execution, transfers the page to the appropriate page. The specific code of the method Bookdel () to delete the book information is as follows:
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", "Delete book information failed!") ");
Return Mapping.findforward ("error");
}else{
Return Mapping.findforward ("Bookdel");
}
}
As you can see from the above code, the method of deleting the Bookdao class used by the book information is Delete (). Because the data normalization principle is adopted in the design of the database, the Book information table, the book Borrowing Information table and the book return information table are closely related, that is, the book borrowing Information table and the book return information only save the book ID number, and do not save more books information, in order to ensure the integrity of the data, in deleting the book information , instead of actually deleting it, set a tag field that has only two values of 0 (meaning no deletions) or 1 (meaning that it has been deleted). When deleting, simply set the value of the field to 1. The specific code for the Delete () method that deletes the book information is as follows:
public int Delete (Bookform bookform) {
String sql= "UPDATE tb_bookinfo SET del=1 where id=" +bookform.getid () + "";
int falg=conn.executeupdate (SQL);
return falg;
}
In the Struts-config.xml file, configure the <forward> elements involved in deleting the book information, as follows:
<forward name= "Bookdel" path= "/book_ok.jsp?para=3"/>

function design of library Management module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.