# one-book **Repository Path**: zengzhaomin-coder/one-book ## Basic Information - **Project Name**: one-book - **Description**: book 的增删查改 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-11-24 - **Last Updated**: 2021-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### 总结 - 案例中有增删查改(crud)以及模糊查询 - 登录注册功能(用到了 session 会话) - 以及使用到了验证码登录的判断,验证码是根据内部自动生成的,然后用户输入正确才能登录或注册成功 - 案例虽小,五脏俱全 #### 提示 - 比如在 BookDao 中插入方法中还有更简便的方法 - 在遍历信息的情况下,我们可以换一种方式写 ```aidl public List list() throws SQLException, ClassNotFoundException { List books = new ArrayList<>(); String sql = "select book_id, book_name, book_author, book_price, book_press, book_sales from book"; System.out.println("要执行的语句是:" + sql); try (Connection connection = DBHelper.getConnection(); PreparedStatement statement = connection.prepareStatement(sql); ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { int id = resultSet.getInt(1); String name = resultSet.getString(2); String author = resultSet.getString(3); float price = resultSet.getFloat(4); String press = resultSet.getString(5); String sales = resultSet.getString(6); Book book = new Book(id, name, author, price, press, sales); books.add(book); } return books; } ``` 修改之后的写法,更简便了 ```aidl public List list() throws SQLException, ClassNotFoundException { List books = new ArrayList<>(); String sql = "select book_id, book_name, book_author, book_price, book_press, book_sales from book"; System.out.println("要执行的语句是:" + sql); try (Connection connection = DBHelper.getConnection(); PreparedStatement statement = connection.prepareStatement(sql); ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { books.add( new Book( resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3), resultSet.getFloat(4), resultSet.getString(5), resultSet.getString(6)) ); } } return books; } ```