2. com.springmvc.repository 패키지에서 BookRowMapper 클래스를 생성하여 다음 내용을 작성합니다.
코드 17-10 BookRowMapper.java
package com.springmvc.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.springmvc.domain.Book;
➊
public class BookRowMapper implements RowMapper<Book> {
public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
Book book = new Book();
book.setBookId(rs.getString(1));
book.setName(rs.getString(2));
book.setUnitPrice(rs.getInt(3));
book.setAuthor(rs.getString(4));
book.setDescription(rs.getString(5));
book.setPublisher(rs.getString(6));
book.setCategory(rs.getString(7));
book.setUnitsInStock(rs.getLong(8));
book.setReleaseDate(rs.getString(9));
book.setCondition(rs.getString(10));
book.setFileName(rs.getString(11));
return book;
}
}
➊ 데이터베이스에 등록된 도서 목록의 Book 객체를 목록에 담기 위해 BookRowMapper 클래스를 생성했습니다.