package com.books.dao.impl;
import com.books.bean.Book;
import com.books.dao.BookDao;
import com.books.utils.DelFlagE;
import com.books.utils.MyDbutils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/**
* @author xiaolong
* @date 2022年10月18日 16:28
* BookDao的实现
*/
public class BookDaoImpl implements BookDao {
String sql;
QueryRunner queryRunner;
/**
* 查询全部
*
* @param book
* @return
*/
@Override
public List<Book> list(Book book) {
queryRunner = MyDbutils.getQueryRunner();
sql = "select * from t_book where is_deleted = ?";
try {
return queryRunner.query(sql, new ResultSetHandler<List<Book>>() {
@Override
public List<Book> handle(ResultSet rs) throws SQLException {
List<Book> list = new ArrayList<>();
while (rs.next()) {
Book b = new Book();
b.setId(rs.getInt("id"));
b.setBookName(rs.getString("book_name"));
b.setAuthor(rs.getString("author"));
b.setPublish(rs.getString("publish"));
b.setIsbn(rs.getString("isbn"));
String introduction = rs.getString("introduction");
if (introduction != null && !"".equals(introduction) && introduction.length() > 20) {
introduction = rs.getString("introduction").substring(0, 20);
}
b.setIntroduction(introduction + "...");
b.setLanguage(rs.getString("language"));
b.setPrice(rs.getBigDecimal("price"));
b.setPubdate(rs.getDate("pubdate"));
b.setPressmark(rs.getString("pressmark"));
b.setIsDeleted(rs.getInt("is_deleted"));
b.setState(rs.getInt("state"));
list.add(b);
}
return list;
}
}, DelFlagE.NO.code);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
/**
* 更新书籍
*
* @param book
* @return
*/
@Override
public Integer saveBook(Book book) {
queryRunner = MyDbutils.getQueryRunner();
sql = "insert into t_book(book_name,author,publish,isbn,introduction,language,price,pubdate,pressmark)values(?,?,?,?,?,?,?,?,?)";
try {
return queryRunner.update(sql,
book.getBookName(), book.getAuthor(), book.getPublish(),
book.getIsbn(), book.getIntroduction(), book.getLanguage(),
book.getPrice(), book.getPubdate(), book.getPressmark());
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
/**
* 测试
*
* @param args
*/
public static void main(String[] args) {
Book book = new Book();
book.setId(1);
book.setBookName("时间简史");
book.setAuthor("霍金");
book.setPrice(new BigDecimal(59.9));
book.setLanguage("中文");
Calendar calendar = Calendar.getInstance();
calendar.set(1997, 4, 6);
book.setPubdate(calendar.getTime());
book.setIntroduction("一本神奇的书籍...666666");
book.setIsbn("xxxxx01012123232");
book.setPressmark("1-3-03");
book.setPublish("清华出版社");
// dao.saveBook(book);
BookDaoImpl dao = new BookDaoImpl();
dao.updateBook(book);
List<Book> list = dao.list(null);
System.out.println(list);
}
@Override
public Integer updateBook(Book book) {
queryRunner = MyDbutils.getQueryRunner();
if (book.getIsDeleted() == null || "".equals(book.getIsDeleted())) {
book.setIsDeleted(DelFlagE.NO.code);
}
if (book.getState() == null || "".equals(book.getState())) {
book.setState(0);
}
sql = "update t_book set book_name =?,author=?,publish=?,isbn=?,introduction=?,language=?,price=?,pubdate=?,state=?,is_deleted=? where id=?";
try {
return queryRunner.update(sql,
book.getBookName(), book.getAuthor(),
book.getPublish(), book.getIsbn(),
book.getIntroduction(), book.getLanguage(),
book.getPrice(), book.getPubdate(),
book.getState(), book.getIsDeleted(), book.getId());
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
@Override
public Integer deleteById(Integer id) {
QueryRunner queryRunner = MyDbutils.getQueryRunner();
sql = "update t_book set is_deleted=? where id=?";
try {
return queryRunner.update(sql, DelFlagE.YES.code, id);
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
@Override
public Book queryById(Integer id) {
queryRunner = MyDbutils.getQueryRunner();
sql = "select * from t_book where is_deleted = ? and id = ?";
try {
return queryRunner.query(sql, new ResultSetHandler<Book>() {
@Override
public Book handle(ResultSet rs) throws SQLException {
if (rs.next()) {
Book b = new Book();
b.setId(rs.getInt("id"));
b.setBookName(rs.getString("book_name"));
b.setAuthor(rs.getString("author"));
b.setPublish(rs.getString("publish"));
b.setIsbn(rs.getString("isbn"));
String introduction = rs.getString("introduction");
b.setIntroduction(introduction);
b.setLanguage(rs.getString("language"));
b.setPrice(rs.getBigDecimal("price"));
b.setPubdate(rs.getDate("pubdate"));
b.setPressmark(rs.getString("pressmark"));
b.setIsDeleted(rs.getInt("is_deleted"));
b.setState(rs.getInt("state"));
return b;
}
return null;
}
}, DelFlagE.NO.code, id);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
@Override
public List<Book> queryListByState(int code) {
queryRunner = MyDbutils.getQueryRunner();
sql = "select * from t_book where is_deleted = ? and state=?";
try {
return queryRunner.query(sql, new ResultSetHandler<List<Book>>() {
@Override
public List<Book> handle(ResultSet rs) throws SQLException {
List<Book> list = new ArrayList<>();
while (rs.next()) {
Book b = new Book();
b.setId(rs.getInt("id"));
b.setBookName(rs.getString("book_name"));
b.setAuthor(rs.getString("author"));
b.setPublish(rs.getString("publish"));
b.setIsbn(rs.getString("isbn"));
String introduction = rs.getString("introduction");
if (introduction != null && !"".equals(introduction) && introduction.length() > 20) {
introduction = rs.getString("introduction").substring(0, 20);
}
b.setIntroduction(introd
没有合适的资源?快使用搜索试试~ 我知道了~
基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip
共634个文件
png:214个
class:144个
gif:118个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 185 浏览量
2023-02-06
19:13:05
上传
评论 7
收藏 11.85MB ZIP 举报
温馨提示
基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。 基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip 高分毕业设计项目,也可作为期末大作业和课程设计,下载即用无需修改。基于Jsp+S
资源推荐
资源详情
资源评论
收起资源包目录
基于Jsp+Servlet+Mysql的图书管理系统源码+数据库.zip (634个子文件)
StudentServlet.class 6KB
StudentServlet.class 6KB
ClassServlet.class 5KB
ClassServlet.class 5KB
BookDaoImpl.class 5KB
BookDaoImpl.class 5KB
ReaderCardServlet.class 5KB
ReaderCardServlet.class 5KB
DepartmentServlet.class 5KB
DepartmentServlet.class 5KB
UserDaoImpl.class 5KB
UserDaoImpl.class 5KB
UserServlet.class 4KB
UserServlet.class 4KB
StudentDaoImpl.class 4KB
StudentDaoImpl.class 4KB
BookServlet.class 4KB
BookServlet.class 4KB
ReaderCardDaoImpl.class 4KB
ReaderCardDaoImpl.class 4KB
ClassDaoImpl.class 3KB
Book.class 3KB
ClassDaoImpl.class 3KB
Book.class 3KB
RequestParameterUtils.class 3KB
RequestParameterUtils.class 3KB
Student.class 3KB
Student.class 3KB
DepartmentDaoImpl.class 3KB
DepartmentDaoImpl.class 3KB
BookDaoImpl$1.class 3KB
BookDaoImpl$1.class 3KB
BookDaoImpl$3.class 3KB
BookDaoImpl$3.class 3KB
AuthenticationFilter.class 3KB
AuthenticationFilter.class 3KB
LendListServlet.class 2KB
LendListServlet.class 2KB
StudentDaoImpl$1.class 2KB
StudentDaoImpl$1.class 2KB
LendListServiceImpl.class 2KB
LendListServiceImpl.class 2KB
BookDaoImpl$2.class 2KB
BookDaoImpl$2.class 2KB
LendListDaoImpl.class 2KB
LendListDaoImpl.class 2KB
User.class 2KB
User.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
StudentServiceImpl.class 2KB
StudentServiceImpl.class 2KB
ReaderCardDaoImpl$3.class 2KB
ReaderCardDaoImpl$3.class 2KB
ReaderCardDaoImpl$1.class 2KB
ReaderCardDaoImpl$1.class 2KB
UserDaoImpl$1.class 2KB
UserDaoImpl$1.class 2KB
ClassDaoImpl$3.class 2KB
ClassDaoImpl$3.class 2KB
ClassDaoImpl$1.class 2KB
ClassDaoImpl$1.class 2KB
StudentDaoImpl$2.class 2KB
StudentDaoImpl$4.class 2KB
StudentDaoImpl$2.class 2KB
StudentDaoImpl$4.class 2KB
DepartmentDaoImpl$1.class 2KB
DepartmentDaoImpl$1.class 2KB
Class.class 2KB
Class.class 2KB
ReaderCard.class 2KB
ReaderCard.class 2KB
LendList.class 2KB
LendList.class 2KB
LendListDaoImpl$1.class 2KB
LendListDaoImpl$1.class 2KB
ReaderCardDaoImpl$2.class 2KB
ReaderCardDaoImpl$2.class 2KB
ClassDaoImpl$2.class 2KB
ClassDaoImpl$2.class 2KB
UserDaoImpl$4.class 2KB
UserDaoImpl$4.class 2KB
DepartmentDaoImpl$2.class 2KB
DepartmentDaoImpl$2.class 2KB
UserServiceImpl.class 2KB
UserServiceImpl.class 2KB
UserDaoImpl$2.class 2KB
UserDaoImpl$2.class 2KB
Department.class 2KB
Department.class 2KB
ReaderCardServiceImpl.class 2KB
ReaderCardServiceImpl.class 2KB
ClassServiceImpl.class 2KB
ClassServiceImpl.class 2KB
BookServiceImpl.class 1KB
BookServiceImpl.class 1KB
CharacterEncodingFilter.class 1KB
CharacterEncodingFilter.class 1KB
LogoutServlet.class 1KB
LogoutServlet.class 1KB
共 634 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
猰貐的新时代
- 粉丝: 1w+
- 资源: 2554
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页