First, process analysis
Second, the Code
1.view Layer
and a same
2.servlet Layer
(1) Admincategoryservlet.java
1 /**2 * Delete Level two classification3 * @paramreq4 * @paramresp5 * @return6 * @throwsservletexception7 * @throwsIOException8 */9 PublicString Deletechild (httpservletrequest req, HttpServletResponse resp)Ten throwsservletexception, IOException { OneString cid = Req.getparameter ("CID"); A intCount =bookservice.findbookcountbycategory (CID); - if(Count > 0) { -Req.setattribute ("Code", "Eror"); theReq.setattribute ("msg", "There are books under this category, cannot be deleted!") "); - return"/adminjsps/msg.jsp"; - } - Service.delete (CID); + returnFindAll (req, resp); -}
3.service Layer
(1) Admincategory.java
1 /**2 * Delete Category3 * @paramCID4 */5 Public voidDelete (String cid) {6 Try {7 Categorydao.delete (CID);8}Catch(SQLException e) {9 Throw NewRuntimeException (e);Ten } One}
(2) Bookservice.java
1 /**2 * Query the number of books under a category3 * @paramCID4 * @return5 */6 Public intfindbookcountbycategory (String CID) {7 Try {8 returnbookdao.findbookcountbycategory (CID);9}Catch(SQLException e) {Ten Throw NewRuntimeException (e); One } A}
4.dao Layer
(1) Admincategorydao.java
1 /**2 * Delete Category3 * @paramCID4 * @throwsSQLException5 */6 Public voidDelete (String CID)throwsSQLException {7String sql = "Delete from t_category where cid=?";8 qr.update (SQL, CID);9}
(2) Bookdao
1 /**2 * Query the number of books under a category3 * @paramCID4 * @return5 * @throwsSQLException6 */7 Public intFindbookcountbycategory (String CID)throwsSQLException {8String sql = "SELECT COUNT (*) from T_book where cid=?";9Number count = (number) qr.query (SQL,NewScalarhandler (), CID);Ten returnCount = =NULL? 0: Count.intvalue (); One}
Web Book Mall Project study notes-030 Delete level two categories