Book.java
上传用户:ycdfsj258
上传日期:2022-08-04
资源大小:1094k
文件大小:8k
源码类别:

图形图象

开发平台:

Java

  1. package com.action;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import com.actionForm.BookForm;
  8. import org.apache.struts.action.Action;
  9. import com.dao.BookDAO;
  10. import java.util.Date;
  11. public class Book extends Action {
  12.     private BookDAO bookDAO = null;
  13.     public Book() {
  14.         this.bookDAO = new BookDAO();
  15.     }
  16.     public ActionForward perform(ActionMapping mapping, ActionForm form,
  17.                                  HttpServletRequest request,
  18.                                  HttpServletResponse response) {
  19.         String action =request.getParameter("action");
  20.         System.out.println("nbook*********************action="+action);
  21.         if(action==null||"".equals(action)){
  22.             request.setAttribute("error","您的操作有误!");
  23.             return mapping.findForward("error");
  24.         }else if("bookAdd".equals(action)){
  25.             return bookAdd(mapping,form,request,response);
  26.         }else if("bookQuery".equals(action)){
  27.             return bookQuery(mapping,form,request,response);
  28.         }else if("bookModifyQuery".equals(action)){
  29.             return bookModifyQuery(mapping,form,request,response);
  30.         }else if("bookModify".equals(action)){
  31.             return bookModify(mapping,form,request,response);
  32.         }else if("bookDel".equals(action)){
  33.             return bookDel(mapping,form,request,response);
  34.         }else if("bookDetail".equals(action)){
  35.             return bookDetail(mapping,form,request,response);
  36.         }else if("bookifQuery".equals(action)){
  37.             return bookifQuery(mapping,form,request,response);
  38.         }
  39.         request.setAttribute("error","操作失败!");
  40.         return mapping.findForward("error");
  41.     }
  42.     /***********************添加图书信息**************************/
  43.     private ActionForward bookAdd(ActionMapping mapping, ActionForm form,
  44.                               HttpServletRequest request,
  45.                               HttpServletResponse response){
  46.            BookForm bookForm = (BookForm) form;
  47.            bookForm.setBarcode(bookForm.getBarcode());
  48.            bookForm.setBookName(bookForm.getBookName());
  49.            bookForm.setTypeId(bookForm.getTypeId());
  50.            bookForm.setAuthor(bookForm.getAuthor());
  51.            bookForm.setTranslator(bookForm.getTranslator());
  52.            bookForm.setIsbn(bookForm.getIsbn());
  53.            bookForm.setPrice(bookForm.getPrice());
  54.            bookForm.setPage(bookForm.getPage());
  55.            bookForm.setBookcaseid(bookForm.getBookcaseid());
  56.            bookForm.setStorage(bookForm.getStorage());
  57.            //获取系统日期
  58.            Date date1=new Date();
  59.            java.sql.Date date=new java.sql.Date(date1.getTime());
  60.            bookForm.setInTime(date.toString());
  61.            bookForm.setOperator(bookForm.getOperator());
  62.            int a=bookDAO.insert(bookForm);
  63.            if(a==1){
  64.                return mapping.findForward("bookAdd");
  65.          }else if(a==2){
  66.              request.setAttribute("error","该图书信息已经添加!");
  67.              return mapping.findForward("error");
  68.          }else{
  69.              request.setAttribute("error","图书信息添加失败!");
  70.              return mapping.findForward("error");
  71.         }
  72.        }
  73.        /***********************查询全部图书信息**************************/
  74.        private ActionForward bookQuery(ActionMapping mapping, ActionForm form,
  75.                                  HttpServletRequest request,
  76.                                  HttpServletResponse response){
  77.        String str=null;
  78.        request.setAttribute("book",bookDAO.query(str));
  79.        return mapping.findForward("bookQuery");
  80.        }
  81.        /***********************条件查询图书信息**************************/
  82.        private ActionForward bookifQuery(ActionMapping mapping, ActionForm form,
  83.                                  HttpServletRequest request,
  84.                                  HttpServletResponse response){
  85.        String str=null;
  86.        if(request.getParameter("f")!=null){
  87.            str = request.getParameter("f") + " like '%" +
  88.                         request.getParameter("key") + "%";
  89.        }
  90.        request.setAttribute("ifbook",bookDAO.query(str));
  91.        System.out.print("条件查询图书信息时的str:"+str);
  92.        return mapping.findForward("bookifQuery");
  93.        }
  94.         /***********************查询修改图书信息**************************/
  95.         private ActionForward bookModifyQuery(ActionMapping mapping, ActionForm form,
  96.                                  HttpServletRequest request,
  97.                                  HttpServletResponse response){
  98.             BookForm bookForm=(BookForm)form;
  99.             System.out.println("查询修改图书信息:"+request.getParameter("ID"));
  100.             bookForm.setId(Integer.valueOf(request.getParameter("ID")));
  101.             request.setAttribute("bookQueryif",bookDAO.queryM(bookForm));
  102.             return mapping.findForward("bookQueryModify");
  103.         }
  104.         /***********************查询图书详细信息**************************/
  105.         private ActionForward bookDetail(ActionMapping mapping, ActionForm form,
  106.                                  HttpServletRequest request,
  107.                                  HttpServletResponse response){
  108.             BookForm bookForm=(BookForm)form;
  109.             bookForm.setId(Integer.valueOf(request.getParameter("ID")));
  110.             request.setAttribute("bookDetail",bookDAO.queryM(bookForm));
  111.             return mapping.findForward("bookDeatil");
  112.         }
  113.         /***********************修改图书信息**************************/
  114.         private ActionForward bookModify(ActionMapping mapping, ActionForm form,
  115.                                  HttpServletRequest request,
  116.                                  HttpServletResponse response){
  117.             BookForm bookForm=(BookForm)form;
  118.             bookForm.setBarcode(bookForm.getBarcode());
  119.             bookForm.setBookName(bookForm.getBookName());
  120.             bookForm.setTypeId(bookForm.getTypeId());
  121.             bookForm.setAuthor(bookForm.getAuthor());
  122.             bookForm.setTranslator(bookForm.getTranslator());
  123.             bookForm.setIsbn(bookForm.getIsbn());
  124.             bookForm.setPrice(bookForm.getPrice());
  125.             bookForm.setPage(bookForm.getPage());
  126.             bookForm.setBookcaseid(bookForm.getBookcaseid());
  127.             bookForm.setStorage(bookForm.getStorage());
  128.             bookForm.setInTime(bookForm.getInTime());
  129.             bookForm.setOperator(bookForm.getOperator());
  130.             int ret=bookDAO.update(bookForm);
  131.             if(ret==0){
  132.                 request.setAttribute("error","修改图书信息失败!");
  133.                 return mapping.findForward("error");
  134.             }else{
  135.                 return mapping.findForward("bookModify");
  136.             }
  137.         }
  138.         /***********************删除图书信息**************************/
  139.         private ActionForward bookDel(ActionMapping mapping, ActionForm form,
  140.                                  HttpServletRequest request,
  141.                                  HttpServletResponse response){
  142.             BookForm bookForm=(BookForm)form;
  143.             bookForm.setId(Integer.valueOf(request.getParameter("ID")));
  144.             int ret=bookDAO.delete(bookForm);
  145.             if(ret==0){
  146.                 request.setAttribute("error","删除图书信息失败!");
  147.                 return mapping.findForward("error");
  148.             }else{
  149.                 return mapping.findForward("bookDel");
  150.             }
  151.         }
  152. }