Online book Store Project study notes-030 Delete level two categories

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.