一、流程分析
二、代码
1.view层
(1).jsp
(2).js
2.servlet层
(1)AdminBookServlet.java
1 /** 2 * 编辑图书 3 * @param req 4 * @param resp 5 * @return 6 * @throws ServletException 7 * @throws IOException 8 */ 9 public String edit(HttpServletRequest req, HttpServletResponse resp) 10 throws ServletException, IOException { 11 Map<String,String[]> map = req.getParameterMap(); 12 Book book = CommonUtils.toBean(map, Book.class); 13 Category category = new Category(); 14 category.setCid(req.getParameter("cid")); 15 book.setCategory(category); 16 bookService.eidt(book); 17 req.setAttribute("msg", "修改图书成功!"); 18 return "f:/adminjsps/msg.jsp"; 19 }
3.service层
(1).java
4.dao层
(1)BookDao.java
1 /** 2 * 修改图书 3 * @param book 4 * String sql = "insert into t_book(bid,bname,author,price,currPrice," + 5 "discount,press,publishtime,edition,pageNum,wordNum,printtime," + 6 "booksize,paper,cid,image_w,image_b)" + 7 * @throws SQLException 8 */ 9 public void edit(Book book) throws SQLException { 10 String sql = "update t_book set bname=?,author=?,price=?,currPrice=?," + 11 "discount=?,press=?,publishtime=?,edition=?,pageNum=?,wordNum=?," + 12 "printtime=?,booksize=?,paper=?,cid=? where bid=?"; 13 Object[] params = {book.getBname(),book.getAuthor(), 14 book.getPrice(),book.getCurrPrice(),book.getDiscount(), 15 book.getPress(),book.getPublishtime(),book.getEdition(), 16 book.getPageNum(),book.getWordNum(),book.getPrinttime(), 17 book.getBooksize(),book.getPaper(), 18 book.getCategory().getCid(),book.getBid()}; 19 qr.update(sql, params); 20 }