|
@@ -14,86 +14,87 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
-@Repository("bookDao")
|
|
|
-public class BookDaoImpl implements BookDao {
|
|
|
|
|
|
- @Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Book> findAll() {
|
|
|
- List<Book> bookList = jdbcTemplate.
|
|
|
- query("select * from book", new BeanPropertyRowMapper<Book>(Book.class));
|
|
|
- return bookList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int insert(Book book) {
|
|
|
- String sql = """
|
|
|
- insert into book(book_id,book_name,type_id,author_id,author_name,book_img,book_desc)
|
|
|
- values(?,?,?,?,?,?,?)
|
|
|
- """;
|
|
|
- Object[] args = {book.getBookId(), book.getBookName(), book.getTypeId(),
|
|
|
- book.getAuthorId(), book.getAuthorName(), book.getBookImg(), book.getBookDesc()};
|
|
|
- int update = jdbcTemplate.update(sql, args);
|
|
|
- return update;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Book findOne(String bookId) {
|
|
|
- Book book = jdbcTemplate.queryForObject("select * from book where book_id = ?",
|
|
|
- new BeanPropertyRowMapper<Book>(Book.class), bookId);
|
|
|
- return book;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int delete(Book book) {
|
|
|
-
|
|
|
- String sql = """
|
|
|
- delete from book where book_id = ?
|
|
|
- """;
|
|
|
- Object[] args = {book.getBookId()};
|
|
|
- int update = jdbcTemplate.update(sql, args);
|
|
|
- return update;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int deleteById(String bookId) {
|
|
|
- String sql = """
|
|
|
- delete from book where book_id = ?
|
|
|
- """;
|
|
|
- int update = jdbcTemplate.update(sql, bookId);
|
|
|
- return update;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String findAuthorIdById(String bookId) {
|
|
|
-
|
|
|
- Book book = jdbcTemplate.queryForObject(
|
|
|
- "select * from book where book_id = ?",
|
|
|
- new BeanPropertyRowMapper<Book>(Book.class), bookId
|
|
|
- );
|
|
|
- System.out.println(book);
|
|
|
-
|
|
|
- String authorId = jdbcTemplate.queryForObject(
|
|
|
- "select author_id from book where book_id = ?",
|
|
|
-
|
|
|
- new SingleColumnRowMapper<>(String.class), bookId
|
|
|
- );
|
|
|
- System.out.println(authorId);
|
|
|
-
|
|
|
- return book.getAuthorId();
|
|
|
- }
|
|
|
-
|
|
|
- static class BookRowMapper implements RowMapper<String> {
|
|
|
- public static final BookRowMapper INSTANCE = new BookRowMapper();
|
|
|
-
|
|
|
- private BookRowMapper() {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
|
- return rs.getString("author_id");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|