6. BookController 클래스에 requestBooksByFilter() 메서드를 추가합니다. 웹 요청 URL이 http://.../books/filter/bookFilter;publisher=길벗;category=IT전문서라면 @RequestMapping의 요청 매핑 경로 /filter/{bookFilter}와 매핑하게 되어 getBooksByFilter() 메서드가 실행됩니다.
코드 6-12 BookController.java
package com.springmvc.controller;
...
import java.util.Set;
import java.util.Map;
import org.springframework.web.bind.annotation.MatrixVariable;
@Controller
@RequestMapping("/books")
public class BookController {
@Autowired
private BookService bookService;
...
@GetMapping("/filter/{bookFilter}")
public String requestBooksByFilter(
@MatrixVariable(pathVar="bookFilter") Map<String, List<String>> bookFilter,
Model model) {
Set<Book> booksByFilter = bookService.getBookListByFilter(bookFilter);
model.addAttribute("bookList", booksByFilter);
return "books";
}
}