この記事では、参照のためにBook Mall Classificationモジュールの前の記事に従ってください。特定のコンテンツは次のとおりです
1.関連するクラスを作成します
cn.itcast.bookstore.book
ドメイン:本
DAO:bookdao
サービス:Bookservice
web.servle:bookservlet
本
パブリッククラスブック{private string bid;プライベートストリングBName;プライベートダブル価格。プライベートストリング著者;プライベート文字列画像;プライベートカテゴリカテゴリ。プライベートブールデル;}bookdao
Public Class Bookdao {private queryrunner qr = new txqueryrunner(); / ** *すべての書籍 * @return */ public list <book> findall(){try {string sql = "select * from book where del = false"; return qr.query(sql、new beanlisthandler <book>(book.class)); } catch(sqlexception e){新しいruntimeexception(e); }} / ** * category * @param cid * @return * / public list <book> findbycategory(string cid){try {string sql = "select * from book where cid =?and del = false"; Return Qr.Query(SQL、New BeanListhandler <book>(book.class)、cid); } catch(sqlexception e){新しいruntimeexception(e); }} / ** *ロードメソッド * @param bid * @return * / public book findbybid(string bid){try { / * * bookオブジェクトにカテゴリの情報を保存する必要があります * / string sql = "select * book bid =?"; map <string、object> map = qr.query(sql、new maphandler()、bid); / * *マップを使用して2つのオブジェクトをマップし、これら2つのオブジェクトの関係を確立します! */ category category = commonutils.tobean(map、category.class); book book = commonutils.tobean(map、book.class); book.setcategory(category);戻る本; } catch(sqlexception e){新しいruntimeexception(e); }} / ***指定されたカテゴリに基づく書籍の数* @param cid* @return* / public int getCountByCid(String cid){try {string sql = "cid =?";番号cnt =(number)qr.query(sql、new scalarhandler()、cid); cnt.intvalue(); } catch(sqlexception e){新しいruntimeexception(e); }} / *** book* @param book* / public void add(book book){try {string sql = "book値に挿入(?、?、?、?、?、?、?)"; object = {book.getBid()、book.getbname()、book.getprice()、book.getauthor()、book.getimage()、book.getcategory()。getCid()}; qr.update(sql、params); } catch(sqlexception e){新しいruntimeexception(e); }} / *** book* @param bid* / public void delete(string bid){try {string sql = "update book set del = true where bid =?"; qr.update(sql、bid); } catch(sqlexception e){新しいruntimeexception(e); }} public void edit(book book){try {string sql = "book set bname =?、price =?、著者=?、画像=?、cid =?where bid =?"; object = {book.getbname()、book.getprice()、book.getauthor()、book.getimage()、book.getcategory()。getCid()、book.getBid()}; qr.update(sql、params); } catch(sqlexception e){新しいruntimeexception(e); }}}Bookservice
パブリッククラスBookservice {private bookdao bookdao = new bookdao(); / ***すべての書籍* @return*/ public list <book> findall(){return bookdao.findall(); } / ** * category by category * @param cid * @return * / public list <book> findbycategory(string cid){return bookdao.findbycategory(cid); } public Book load(string bid){return bookdao.findbybid(bid); } / *** book* @param book* / public void add(book book){bookdao.add(book); } public void delete(string bid){bookdao.delete(bid); } public void edit(book book){bookdao.edit(book); }}書店
パブリッククラスBookservletはBaseServletを拡張します{private Bookservice bookservice = new Bookservice(); public String Load(httpservletrequest request、httpservletresponse Response)スローServletexception、ioexception { / * *1。Parameterbid * 2を取得 * 2。 return "f:/jsps/book/desc.jsp"; } / ** *すべての書籍 * @param request * @param Response * @return * @throws servletexception * @throws ioexception * / public string findall(httpservletrequest request、httpservletrequest Response)スローServletexception、ioexception {request.setattribute( "Booklist"、bookervice.findall(); "f:/jsps/book/list.jsp"; } / ** * category * @param request * @param Response * @return * @throws servletexception * @throws ioexception * / public string findbycategory(httpservletrequest request、httpservletResponse応答)スローServleTexception、ioException {string cid = request.getparameter; request.setattribute( "booklist"、bookservice.findbycategory(cid)); "f:/jsps/book/list.jsp"; }}2。すべての本をクエリします
Process:Left.jsp(すべてのクラス) - > bookservlet#findall() - > /jsps/book/list.jsp
3。カテゴリごとのクエリブック
プロセス:left.jsp-> bookservlet#findbycategory() - > list.jsp
4。クエリの詳細(ロード)
プロセス:list.jsp(本をクリック) - > bookservlet#load() - > desc.jsp
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。