6. getBookListByFilter() 메서드도 다음과 같이 수정합니다.
코드 17-14 BookRepositoryImpl.java
package com.springmvc.repository;
...
@Repository
public class BookRepositoryImpl implements BookRepository {
...
➊
public Set<Book> getBookListByFilter(Map<String, List<String>> filter) {
Set<Book> booksByPublisher = new HashSet<Book>();
Set<Book> booksByCategory = new HashSet<Book>();
Set<String> criterias = filter.keySet();
if (criterias.contains("publisher")) {
for (int j = 0; j < filter.get("publisher").size(); j++) {
String publisherName = filter.get("publisher").get(j);
String SQL = "SELECT * FROM book where b_publisher LIKE '%" + publisherName + "%'"; ➋
booksByPublisher.addAll(template.query(SQL, new BookRowMapper())); ➌
}
}
if (criterias.contains("category")) {
for (int i = 0; i < filter.get("category").size(); i++) {
String category = filter.get("category").get(i);
String SQL = "SELECT * FROM book where b_category LIKE '%" + category + "%'"; ➍
booksByCategory.addAll(template.query(SQL, new BookRowMapper())); ➎
}
}
booksByCategory.retainAll(booksByPublisher);
return booksByCategory;
}
...
}