📄 managerbookaction.java
字号:
package com.web.action;import static com.common.BeanFactory.getBean;import java.sql.Timestamp;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import com.bean.Book;import com.bean.Type;import com.opensymphony.xwork2.ActionSupport;import com.service.BooksService;public class ManagerBookAction extends ActionSupport { private Integer bookid; private String bookname; private Integer typeid; private List subBook; private int currentPage = 1; private int pageCount; private int messageCount; private String price; private String author; private String isborrow; private String maxnumber; public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } private String publishing; private String purchase; public String readBookMessage() throws Exception{ HttpServletRequest request = ServletActionContext.getRequest(); BooksService service = (BooksService)getBean("booksService"); List typeList = service.findBookType(null,null); request.getSession().setAttribute("typeList", typeList); List list = service.findBooks(null, bookname, typeid); if(list==null) return "success"; separatePage(list); return "success"; } public String editorBook() throws Exception{ HttpServletRequest request = ServletActionContext.getRequest(); BooksService service = (BooksService)getBean("booksService"); List blist = service.findBooks(bookid, null, null); Book book = (Book)blist.get(0); request.setAttribute("book", book); return "success"; } public String updateBook() throws Exception{ HttpServletRequest request = ServletActionContext.getRequest(); BooksService service = (BooksService)getBean("booksService"); Book book = (Book)service.findBooks(bookid, null, null).get(0); book.setAuthor(author); book.setIsborrow(isborrow); book.setName(bookname); System.out.println(typeid+"/"+author+"/"+isborrow+"/"+bookname+"/"+maxnumber+"/"+publishing+"/"+purchase); Integer maxnum = Integer.parseInt(maxnumber); book.setMaxnumber(maxnum); book.setPublishing(publishing); Type type = (Type)service.findBookType(typeid, null).get(0); book.setType(type); book.setPurchase(Timestamp.valueOf(purchase)); service.saveOrUpdate(book); return "success"; } public String addBook() throws Exception{ HttpServletRequest request = ServletActionContext.getRequest(); BooksService service = (BooksService)getBean("booksService"); Book book = new Book(); book.setAuthor(author); book.setIsborrow(isborrow); book.setName(bookname); System.out.println(bookid+"/"+author+"/"+isborrow+"/"+bookname+"/"+maxnumber+"/"+publishing+"/"+purchase); Integer maxnum = Integer.parseInt(maxnumber); book.setMaxnumber(maxnum); book.setPublishing(publishing); Type type = (Type)service.findBookType(typeid, null).get(0); book.setType(type); book.setPurchase(Timestamp.valueOf(purchase)); Double bookprice = Double.parseDouble(price); book.setPrice(bookprice); service.saveOrUpdate(book); return "success"; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getIsborrow() { return isborrow; } public void setIsborrow(String isborrow) { this.isborrow = isborrow; } public String getMaxnumber() { return maxnumber; } public void setMaxnumber(String maxnumber) { this.maxnumber = maxnumber; } public String getPublishing() { return publishing; } public void setPublishing(String publishing) { this.publishing = publishing; } public String getPurchase() { return purchase; } public void setPurchase(String purchase) { this.purchase = purchase; } public String getBookname() { return bookname; } public void setBookname(String bookname) { this.bookname = bookname; } public Integer getTypeid() { return typeid; } public void setTypeid(Integer typeid) { this.typeid = typeid; } public List getSubBook() { return subBook; } public Integer getBookid() { return bookid; } public void setBookid(Integer bookid) { this.bookid = bookid; } public void setSubBook(List subBook) { this.subBook = subBook; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getPageCount() { return pageCount; } public void setPageCount(int pageCount) { this.pageCount = pageCount; } public int getMessageCount() { return messageCount; } public void setMessageCount(int messageCount) { this.messageCount = messageCount; } private void separatePage(List list){ if(list.isEmpty()){ messageCount = 0; return; } messageCount = list.size(); if(list.size()%4==0) pageCount = list.size()/4; else pageCount = list.size()/4 + 1; if(list.size()>currentPage*4) subBook = list.subList((currentPage-1)*4, currentPage*4); else subBook = list.subList((currentPage-1)*4, list.size()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -