日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图书分类查询 Demo

發布時間:2024/3/24 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图书分类查询 Demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

視頻演示:

JavaWeb實現

源碼下載

資源下載 https://download.csdn.net/download/u014565127/12130742

目錄結構s

核心代碼展示

  • link.jsp<body><h1>鏈接頁面</h1><a href="<c:url value='/BookServlet?method=findAll'/>">查詢所有分類</a><br><a href="<c:url value='/BookServlet?method=findByCategory&category=1'/>">查詢SE分類</a><br><a href="<c:url value='/BookServlet?method=findByCategory&category=2'/>">查詢EE分類</a><br><a href="<c:url value='/BookServlet?method=findByCategory&category=3'/>">查詢框架分類</a><br></body>
  • show.jsp<body><h1 align="center">圖書列表</h1><table align="center" border="1" width="50%"><tr><th>書名</th><th>單價</th><th>分類</th></tr><c:forEach items="${bookList }" var="book"><tr><td>${book.bname }</td><td>${book.price }</td><c:choose><c:when test="${book.category eq 1 }"><td style="color:red">JavaSE</td></c:when><c:when test="${book.category eq 2 }"><td style="color:blue">JavaEE</td></c:when><c:when test="${book.category eq 3 }"><td style="color:green">JavaFramework</td></c:when></c:choose></tr></c:forEach></table> </body>
  • BookServletpublic class BookServlet extends BaseServlet {private BookDao bookDao = new BookDao();public String findAll(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {request.setAttribute("bookList", bookDao.findAll());return "/show.jsp";}public String findByCategory(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {String value =request.getParameter("category");int category = Integer.parseInt(value);request.setAttribute("bookList", bookDao.findByCategory(category));return "/show.jsp";} }
  • BookDaopublic class BookDao {private QueryRunner qr = new TxQueryRunner();public List<Book> findAll() {try {String sql = "select * from t_book";return qr.query(sql, new BeanListHandler<Book>(Book.class));} catch (SQLException e) {throw new RuntimeException(e);}}public List<Book> findByCategory(int category) {try {String sql = "select * from t_book where category=?";return qr.query(sql, new BeanListHandler<Book>(Book.class),category);} catch (SQLException e) {throw new RuntimeException(e);}} }
  • Book.javapackage com.veeja.book.domain;public class Book {private String bid;private String bname;private double price;private int category;public String getBid() {return bid;}public void setBid(String bid) {this.bid = bid;}public String getBname() {return bname;}public void setBname(String bname) {this.bname = bname;}public double getPrice() {return price;}public void setPrice(double price) {this.price = price;}public int getCategory() {return category;}public void setCategory(int category) {this.category = category;}public String toString() {return "Book [bid=" + bid + ", bname=" + bname + ", price=" + price+ ", category=" + category + "]";}}

  • END.

    總結

    以上是生活随笔為你收集整理的图书分类查询 Demo的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。