J2E图书管理系统
package action;
import org.springframework.beans.factory.annotation.Autowired;
import service.impl.BookDaoImpl;
import vo.Book;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class BookAction extends ActionSupport implements ModelDriven<Book> {
Book book;
String message;
@Autowired
BookDaoImpl bookDaoImpl;
public String add() {
bookDaoImpl.saveBook(book);
message = "添加图书信息成功!";
return SUCCESS;
}
public String update() {
bookDaoImpl.updateBook(book);
message = "更新图书信息成功!";
return SUCCESS;
}
public String select() {
book = bookDaoImpl.selectBook(book.getIsbn());
setMessage("查询图书信息成功!");
return SUCCESS;
}
public String delete() {
bookDaoImpl.deleteBook(book.getIsbn());
this.setMessage("删除图书信息成功!");
return SUCCESS;
}
public BookAction() {
super();
book = new Book();
message = "";
}
@Override
public Book getModel() {
// TODO Auto-generated method stub
return book;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public BookDaoImpl getBookDaoImpl() {
return bookDaoImpl;
}
public void setBookDaoImpl(BookDaoImpl bookDaoImpl) {
this.bookDaoImpl = bookDaoImpl;
}
/*
* @Override public void validate() { // TODO Auto-generated method stub
* if(book.getName()==null || book.getName().trim().length()==0){
* this.addFieldError("name","书名不能为空"); } if(book.getAuthor()==null ||
* book.getAuthor().trim().length()==0){
* this.addFieldError("author","作者不能为空"); } if(book.getISBN()==null ||
* book.getISBN().trim().length()==0){
* this.addFieldError("ISBN","ISBN不能为空"); } if(book.getNumber()==0 ){
* this.addFieldError("number","数量不能为空"); } }
*/
}
评论