Java + springboot + mysql поиск не работает - PullRequest
0 голосов
/ 25 апреля 2020
import com.example.news.models.Posting;
import org.springframework.data.repository.CrudRepository;

import java.util.List;


public interface PostRepos extends CrudRepository<Posting, Long> {

    List<Posting> findByTag(String tag);

}


_____________________________________________________________________________

    @PostMapping("find")
    public String find(@RequestParam String find, Map<String, Object> model){
        Iterable<Posting> posts;
        if(find != null && find.isEmpty()) {

            posts = postRepos.findByTag(find);
        } else {

            posts = postRepos.findAll();

        }
        model.put("posts",posts);
      return "redirect:/newspage";

    }
______________________________________________________________________________
<div th:fragment="head" xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
        <h5 class="my-0 mr-md-auto font-weight-normal">ASAP NEWS</h5>
        <nav class="my-2 my-md-0 mr-md-3">
            <a class="p-2 text-dark" href="/homepage">Main page</a>
            <a class="p-2 text-dark" href="/newspage">News</a>
            <a class="p-2 text-dark" href="/newspage/addpage">Add news</a>
            <a class="p-2 text-dark" href="/aboutpage">About</a>
        </nav>
        <a>
            <form method="post" action="find">
                <label>
                    <input  type="text" placeholder="Search"  name="find">
                </label>
                <button type="submit">Find</button>

            </form>
        </a>

    </div>
</div>

1 Ответ

1 голос
/ 25 апреля 2020

кажется пропущенной ! отметкой до find.isEmpty()

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...