package com.book.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import com.book.model.BorrowDetail; import com.book.util.StringUtil; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; public class BorrowDetailDao { public ResultSet list(Connection con,BorrowDetail borrowDetail)throws Exception{ StringBuffer sb=new StringBuffer("SELECT bd.*,u.username,b.book_name from borrowdetail bd,user u,book b where u.id=bd.user_id and b.id=bd.book_id"); if(borrowDetail.getUserId() != null){ sb.append(" and u.id = ?"); } if(borrowDetail.getStatus() != null){ sb.append(" and bd.status = ?"); } if(borrowDetail.getBookId() != null){ sb.append(" and bd.book_id = ?"); } sb.append(" order by bd.id"); PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sb.toString()); if(borrowDetail.getUserId() != null){ pstmt.setInt(1, borrowDetail.getUserId()); } if(borrowDetail.getStatus() != null && borrowDetail.getBookId() != null){ pstmt.setInt(2, borrowDetail.getStatus()); pstmt.setInt(3, borrowDetail.getBookId()); } return pstmt.executeQuery(); } public int add(Connection con, BorrowDetail borrowDetail) throws Exception { String sql = "insert into borrowdetail (user_id,book_id,status,borrow_time) values (?,?,?,?)"; PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql); pstmt.setInt(1, borrowDetail.getUserId()); pstmt.setInt(2, borrowDetail.getBookId()); pstmt.setInt(3, borrowDetail.getStatus()); pstmt.setLong(4, borrowDetail.getBorrowTime()); return pstmt.executeUpdate(); } public int returnBook(Connection con,BorrowDetail detail)throws Exception { String sql = "update borrowdetail set status = ? ,return_time = ? where id = ?"; PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql); pstmt.setInt(1, detail.getStatus()); pstmt.setLong(2, detail.getReturnTime()); pstmt.setInt(3, detail.getBorrowId()); return pstmt.executeUpdate(); } }

xxyylu LV2
2024年12月4日
lsglsg9 LV23
2023年12月20日
sunshine9920 LV12
2023年10月23日
hongdongdong LV14
2023年8月9日
12345681 LV2
2023年6月10日
gxluchuan LV1
2023年4月7日
lolokei LV1
2022年10月10日
喃喵xxxx LV6
2022年9月6日
zxcvbnm1580 LV1
2022年6月15日
testuser1234567 LV24
2022年5月31日