Book.java~28~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:7k
- package com.action;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- 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 perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- String action =request.getParameter("action");
- System.out.println("nbook*********************action="+action);
- if(action==null||"".equals(action)){
- request.setAttribute("error","您的操作有误!");
- return mapping.findForward("error");
- }else if("bookAdd".equals(action)){
- return bookAdd(mapping,form,request,response);
- }else if("bookQuery".equals(action)){
- return bookQuery(mapping,form,request,response);
- }else if("bookModifyQuery".equals(action)){
- return bookModifyQuery(mapping,form,request,response);
- }else if("bookModify".equals(action)){
- return bookModify(mapping,form,request,response);
- }else if("bookDel".equals(action)){
- return bookDel(mapping,form,request,response);
- }else if("bookDetail".equals(action)){
- return bookDetail(mapping,form,request,response);
- }else if("bookifQuery".equals(action)){
- return bookifQuery(mapping,form,request,response);
- }
- request.setAttribute("error","操作失败!");
- return mapping.findForward("error");
- }
- /***********************添加图书信息**************************/
- private ActionForward bookAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
- BookForm bookForm = (BookForm) actionForm;
- bookForm.setBarcode(bookForm.getBarcode());
- bookForm.setBookName(bookForm.getBookName());
- bookForm.setTypeId(bookForm.getTypeId());
- bookForm.setAuthor(bookForm.getAuthor());
- bookForm.setTranslator(bookForm.getTranslator());
- bookForm.setIsbn(bookForm.getIsbn());
- bookForm.setPrice(bookForm.getPrice());
- bookForm.setPage(bookForm.getPage());
- bookForm.setBookcaseid(bookForm.getBookcaseid());
- bookForm.setStorage(bookForm.getStorage());
- //获取系统日期
- 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==0){
- servletRequest.setAttribute("error","图书信息添加失败!");
- return actionMapping.findForward("error");
- }else if(a==2){
- servletRequest.setAttribute("error","该图书信息已经添加!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookAdd");
- }
- }
- /***********************查询全部图书信息**************************/
- private ActionForward bookQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- String str=null;
- servletRequest.setAttribute("book",bookDAO.query(str));
- return actionMapping.findForward("bookQuery");
- }
- /***********************条件查询图书信息**************************/
- private ActionForward bookifQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- String str=servletRequest.getParameter("f")+" like '%"+servletRequest.getParameter("key")+"%";
- servletRequest.setAttribute("ifbook",bookDAO.query(str));
- System.out.print("条件查询图书信息时的str:"+str);
- return actionMapping.findForward("bookifQuery");
- }
- /***********************查询修改图书信息**************************/
- private ActionForward bookModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookForm bookForm=(BookForm)actionForm;
- System.out.println("查询修改图书信息:"+servletRequest.getParameter("ID"));
- bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("bookQueryif",bookDAO.queryM(bookForm));
- return actionMapping.findForward("bookQueryModify");
- }
- /***********************查询图书详细信息**************************/
- private ActionForward bookDetail(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookForm bookForm=(BookForm)actionForm;
- bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("bookDetail",bookDAO.queryM(bookForm));
- return actionMapping.findForward("bookDeatil");
- }
- /***********************修改图书信息**************************/
- private ActionForward bookModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookForm bookForm=(BookForm)actionForm;
- bookForm.setBarcode(bookForm.getBarcode());
- bookForm.setBookName(bookForm.getBookName());
- bookForm.setTypeId(bookForm.getTypeId());
- bookForm.setAuthor(bookForm.getAuthor());
- bookForm.setTranslator(bookForm.getTranslator());
- bookForm.setIsbn(bookForm.getIsbn());
- bookForm.setPrice(bookForm.getPrice());
- bookForm.setPage(bookForm.getPage());
- bookForm.setBookcaseid(bookForm.getBookcaseid());
- bookForm.setStorage(bookForm.getStorage());
- bookForm.setInTime(bookForm.getInTime());
- bookForm.setOperator(bookForm.getOperator());
- int ret=bookDAO.update(bookForm);
- if(ret==0){
- servletRequest.setAttribute("error","修改图书信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookModify");
- }
- }
- /***********************删除图书信息**************************/
- private ActionForward bookDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- BookForm bookForm=(BookForm)actionForm;
- bookForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- int ret=bookDAO.delete(bookForm);
- if(ret==0){
- servletRequest.setAttribute("error","删除图书信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("bookDel");
- }
- }
- }