【发布时间】:2021-08-09 07:06:59
【问题描述】:
我是 html 和 spring boot 的新手,我正在尝试按作者、描述在列表中的书籍中过滤和搜索。但是我的按钮似乎没有功能,请您帮忙吗?
这是来自控制器的代码:
@GetMapping(value = "/filter", produces = MediaType.APPLICATION_JSON_VALUE)
public String filterBooks (Model model, @RequestParam(name = "author", required = false) String author,
@RequestParam(name = "title", required = false) String title,
@RequestParam(name = "description", required = false) String description,
@RequestParam(name = "publishedDate", required = false) String publishedDate){
List<Book> filterBooks = bookService.filterBooks(author, title, description, publishedDate);
model.addAttribute("filterBooks", filterBooks);
// return bookService.filterBooks(author, title, description, publishedDate);
return"filter";
}
这是来自图书服务的 impl:
public List<Book> filterBooks(String author, String title, String description, String publishedDate) {
List<Book> filteredBooks = new ArrayList<>();
if (!CollectionUtils.isEmpty(books)) {
filteredBooks.addAll(books.stream()
.filter(book -> filterByAuthor(book, author) && filterByTitle(book, title)
&& filterByDesc(book, description) && filterByPublishDate(book, publishedDate))
.collect(Collectors.toList()));
}
return filteredBooks;
}
private boolean filterByAuthor(Book book, String author) {
return StringUtils.isEmpty(author) ? Boolean.TRUE : book.getAuthor().equalsIgnoreCase(author);
}
private boolean filterByTitle(Book book, String title) {
return StringUtils.isEmpty(title) ? Boolean.TRUE : book.getTitle().equalsIgnoreCase(title);
}
private boolean filterByDesc(Book book, String description) {
return StringUtils.isEmpty(description) ? Boolean.TRUE : book.getDescription().equalsIgnoreCase(description);
}
private boolean filterByPublishDate(Book book, String publishDate) {
return StringUtils.isEmpty(publishDate) ? Boolean.TRUE : book.getPublish_date().equalsIgnoreCase(publishDate);
}
这是我的过滤器 html,其中按钮搜索不起作用:https://wtools.io/paste-code/b5hg
单击按钮后,应从可用图书列表中选择图书
【问题讨论】:
标签: java html spring-boot user-interface