package com.bookstore.action;
import java.util.List;
import java.util.Map;
import com.bookstore.dao.impl.CatalogDAO;
import com.bookstore.model.Book;
import com.bookstore.model.Catalog;
import com.bookstore.model.User;
import com.bookstore.service.IBookService;
import com.bookstore.service.ICatalogService;
import com.bookstore.service.impl.BookService;
import com.bookstore.util.Pager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookAction extends ActionSupport{
protected ICatalogService catalogService;
List<Catalog> getcataloglist;
public List<Catalog> getGetcataloglist() {
return getcataloglist;
}
public void setGetcataloglist(List<Catalog> getcataloglist) {
this.getcataloglist = getcataloglist;
}
public void setCatalogService(ICatalogService catalogService) {
this.catalogService = catalogService;
}
public String browseCatalog() throws Exception{
List catalogs=catalogService.getAllCatalogs();
Map request=(Map)ActionContext.getContext().get("request");
request.put("catalogs",catalogs);
return SUCCESS;
}
protected IBookService bookService;
public void setBookService(IBookService bookService) {
this.bookService = bookService;
}
//新书展示
public String newBook() throws Exception{
List books=bookService.getNewBook();
Map request=(Map)ActionContext.getContext().get("request");
request.put("books", books);
return SUCCESS;
}
protected Integer catalogid;//获得图书类别的ID
public String catalogid1;
public String getCatalogid1() {
return catalogid1;
}
public void setCatalogid1(String catalogid1) {
this.catalogid1 = catalogid1;
}
private Integer currentPage=1;//当前页
//生成当前页的get和set方法
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
//生成图书ID的get和set方法
public Integer getCatalogid() {
return catalogid;
}
public void setCatalogid(Integer catalogid) {
this.catalogid = catalogid;
}
//方法实现
public String browseBookPaging() throws Exception{
int totalSize=bookService.getTotalByCatalog(catalogid);
System.out.println("在这里输出的ID"+catalogid);
Pager pager=new Pager(currentPage,totalSize);
List books=bookService.getBookByCatalogidPaging(catalogid, currentPage, pager.getPageSize());
Map request=(Map)ActionContext.getContext().get("request");
request.put("books", books);
request.put("pager",pager);
//购物车要返回继续购买时,需要记住返回的地址
Map session=ActionContext.getContext().getSession();
request.put("catalogid",catalogid);
return SUCCESS;
}
private String bookname;//根据输入的书名或部分书名查询
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String searchBook() throws Exception {
List books = bookService.getRequiredBookByName(this.getBookname());
Map request = (Map)ActionContext.getContext().get("request");
System.out.println(bookname);
request.put("books",books);
return SUCCESS;
}
protected Book book;
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
//实现新增的图书添加
public String addnewbook() throws Exception {
Catalog catalog=bookService.getCatalogById(catalogid1);
book.setCatalog(catalog);
bookService.savebook(book);
return SUCCESS;
}
protected Catalog catalog;
public Catalog getCatalog() {
return catalog;
}
public void setCatalog(Catalog catalog) {
this.catalog = catalog;
}
//实现图书新增分类
public String addcatalog() throws Exception {
Catalog catalog1=new Catalog();
catalog1.setCatalogname(catalog.getCatalogname());
bookService.savecatalog(catalog1);
return SUCCESS;
}
//实现显示图书ID
public String showAddBook()
{
getcataloglist=bookService.getCatalogList();
return SUCCESS;
}
}
- 1
- 2
- 3
前往页