/**
* 增加图书
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward addBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
BookForm bookForm = (BookForm)form;
Integer id = (Integer)bookForm.getId();
String bookName = (String)bookForm.getBookName();
String author = (String)bookForm.getAuthor();
String publisher = (String)bookForm.getPublisher();
Float price = (Float)bookForm.getPrice();
Integer type_id = (Integer)bookForm.getType_id();
BookType bt = new BookType();
bt.setId(type_id);
Integer operator_id = (Integer)bookForm.getOperator_id();
Operator op = new Operator();
op.setId(operator_id);
Integer num = (Integer)bookForm.getNum();
Book book = new Book();
book.setId(id);
book.setBookName(bookName);
book.setAuthor(author);
book.setPublisher(publisher);
book.setPrice(price);
book.setType_id(bt);
book.setInTime(new Date());
book.setOperator_id(op);
bookService.save(book);
for (int i = 1; i <= num; i++) {
Calculate cc = new Calculate();
String b = cc.createBarcode(type_id,id, i);
Barcode barcode = new Barcode();
barcode.setBookid(book);
barcode.setBarcode(b);
barcodeService.save(barcode);
}
request.setAttribute("book", book);
return this.forwardMessagePage(request, "showBookInfo", "msg", mapping);//转到图书信息列表页面
}
生成图书标号的方法:
// 生成图书编号,此编号由书类型id,书id,当前编号是此书的第几册组成
public String createBarcode(Integer typeId, Integer bookId, Integer bookNo) {
String barcode = "";
// 判断位数,生成001,010这样的字符串
if (typeId < 10) {
barcode = barcode + "00" + typeId.toString();
} else if (typeId < 100) {
barcode = barcode + "0" + typeId.toString();
} else {
barcode = barcode + typeId.toString();
} if (bookId < 10) {
barcode = barcode + "00" + bookId.toString();
} else if (bookId < 100) {
barcode = barcode + "0" + bookId.toString();
} else {
barcode = barcode + bookId.toString();
} if (bookNo < 10) {
barcode = barcode + "00" + bookNo.toString();
} else if (bookNo < 100) {
barcode = barcode + "0" + bookNo.toString();
} else {
barcode = barcode + bookNo.toString();
} return barcode;
}
* 增加图书
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward addBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
BookForm bookForm = (BookForm)form;
Integer id = (Integer)bookForm.getId();
String bookName = (String)bookForm.getBookName();
String author = (String)bookForm.getAuthor();
String publisher = (String)bookForm.getPublisher();
Float price = (Float)bookForm.getPrice();
Integer type_id = (Integer)bookForm.getType_id();
BookType bt = new BookType();
bt.setId(type_id);
Integer operator_id = (Integer)bookForm.getOperator_id();
Operator op = new Operator();
op.setId(operator_id);
Integer num = (Integer)bookForm.getNum();
Book book = new Book();
book.setId(id);
book.setBookName(bookName);
book.setAuthor(author);
book.setPublisher(publisher);
book.setPrice(price);
book.setType_id(bt);
book.setInTime(new Date());
book.setOperator_id(op);
bookService.save(book);
for (int i = 1; i <= num; i++) {
Calculate cc = new Calculate();
String b = cc.createBarcode(type_id,id, i);
Barcode barcode = new Barcode();
barcode.setBookid(book);
barcode.setBarcode(b);
barcodeService.save(barcode);
}
request.setAttribute("book", book);
return this.forwardMessagePage(request, "showBookInfo", "msg", mapping);//转到图书信息列表页面
}
生成图书标号的方法:
// 生成图书编号,此编号由书类型id,书id,当前编号是此书的第几册组成
public String createBarcode(Integer typeId, Integer bookId, Integer bookNo) {
String barcode = "";
// 判断位数,生成001,010这样的字符串
if (typeId < 10) {
barcode = barcode + "00" + typeId.toString();
} else if (typeId < 100) {
barcode = barcode + "0" + typeId.toString();
} else {
barcode = barcode + typeId.toString();
} if (bookId < 10) {
barcode = barcode + "00" + bookId.toString();
} else if (bookId < 100) {
barcode = barcode + "0" + bookId.toString();
} else {
barcode = barcode + bookId.toString();
} if (bookNo < 10) {
barcode = barcode + "00" + bookNo.toString();
} else if (bookNo < 100) {
barcode = barcode + "0" + bookNo.toString();
} else {
barcode = barcode + bookNo.toString();
} return barcode;
}
book.setId(id);
book.setBookName(bookName);
book.setAuthor(author);
book.setPublisher(publisher);
book.setPrice(price);
book.setType_id(bt);
book.setInTime(new Date());
book.setOperator_id(op);
bookService.save(book);这些都没有增加图书编号!!怎么能增加进去!
Calculate cc = new Calculate();
String b = cc.createBarcode(type_id,id, i);
Barcode barcode = new Barcode();
barcode.setBookid(book);
barcode.setBarcode(b);
barcodeService.save(barcode);
}
你用debug看看 到底这些执行了吗
int num = ((Integer)bookForm.getNum()).intValue();
Save方法