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
没有合适的资源?快使用搜索试试~ 我知道了~
基于javaweb的图书管理系统源码+数据库文件(95分以上高分课设项目).zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共634个文件
png:214个
class:144个
gif:118个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
温馨提示
基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。 基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip 95分以上高分课程设计,代码完整,下载即用。基于javaweb的图书管理系统源码+数据库文件.zip
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 634 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
![avatar](https://profile-avatar.csdnimg.cn/e7a43a065ad3475bae1a17fa09e4efce_ma_nong33.jpg!1)
盈梓的博客
- 粉丝: 8311
- 资源: 2101
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
- 1
- 2
- 3
- 4
- 5
- 6
前往页