2. BookController 클래스에 requestBooksByCategory() 메서드 내용을 다음과 같이 추가합니다.
코드 10-2 BookController.java
package com.springmvc.controller;
...
import com.springmvc.exception.CategoryException;
@Controller
@RequestMapping("/books")
public class BookController {
...
@GetMapping("/{category}")
public String requestBooksByCategory(@PathVariable("category") String bookCategory, Model model) {
List<Book> booksByCategory = bookService.getBookListByCategory(bookCategory);
if (booksByCategory == null || booksByCategory.isEmpty()) {
throw new CategoryException();
}
model.addAttribute("bookList", booksByCategory);
return "books";
}
...
}