开发者学堂课程【Java Web项目实战2:图书商城:图书模板之查询所有图书(】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/35/detail/774
图书模板之查询所有图书
内容简介:
一、操作流程图
二、具体内容
一、操作流程图
left.jsp(全部分类)——BookServlet#find All()——/jsps/book/list.jsp 流程图。
二、具体内容
BookDao
1 packvage cn.itcast.bookstore.book.dao;
2
3 import java.sql.SQLException;
4 import java.util.List;
5
6 import org.apache . commons . dbutils.Que ryRunner;
7 import org.apache . commons . dbutils.handlers.BeanListHandler;
8
9 import cn.itcast.bookstore.book.domain.Book;
10import cn.itcast jdbc.TxQueryRunner;
11
12 public class BookDao{
13 private QueryRunner qr =new TxQueryRunner():
14 //**查找所有图书
15 public List<Book> findAll() {
16 try {
17 String =sql . "select *from book";
18 return qr·query(sql, new BeanListHandler<Book> (Book.class)):
19 } catch (SQLException e) {
20 throw new RuntimeException(e) ;
21 }
22 }
23 }
24
Bookservice
1 package cn.itcast .bookstore.book.service;
2
3 import java.util.List;
4
5 import cn.itcast .bookstore.book .dao. BookDao;
6 import cn.itcast.bookstore.book.domain. Book;
7
8 public class Bookservice {
9 private BookDao bookDao = new BookDao();
10
11 public List<Book>findAll() {
12 return bookDao.findAll();
13 }
14 }
15
Bookservelt
1 package cn.itcaat.bookatore.book.web.servlet;
2
3 import java.io.IOEception;
4
5 import javax .servlet.serwletException;
6 import javax.servlet.http.HttpservletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import cn.itcast.bookstore.book.web.servlet;
10import cn.itcast.servlet.Baseservlet;
11
12 public class Bookservlet extends Baseservlet {
13 private Bookservice bookservice = new Bookservice () ;
14
15 /**
16 *查询所有分类
17 *@param request
18 *@param response