【问题标题】:How to fix filter button如何修复过滤器按钮
【发布时间】: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


    【解决方案1】:

    你为什么要写这么多代码 解决方案:

    尝试在 JPA 的帮助下实现 CRUD 操作 从 crud 操作中,您可以使用 find by method 并实现它.. 它最简单的方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 2019-06-09
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      相关资源
      最近更新 更多