【问题标题】:Java +springboot +mysql search doesnt workJava +spring boot +mysql 搜索不起作用
【发布时间】:2020-08-08 15:24:58
【问题描述】:
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>

【问题讨论】:

  • 您似乎忘记添加您所面临问题的全部问题/解释

标签: java mysql spring-boot maven


【解决方案1】:

find.isEmpty() 之前似乎错过了! 标记

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-20
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    相关资源
    最近更新 更多