Spring Boot没有从数据库中获取数据

时间:2019-02-26 13:25:35

标签: postgresql hibernate spring-boot

当我想从questionList.html中的postgresql获取数据时,它什么也没有显示。这是控制器中的方法:

@RequestMapping({ "/questionList" })
    public String listProductHandler(Model model, //
                                     @RequestParam(value = "question", defaultValue = "") String likeName,
                                     @RequestParam(value = "page", defaultValue = "1") int page) {
        final int maxResult = 5;
        final int maxNavigationPage = 10;

      PaginationResult<QuestionInfo> result = checkboxDAO.queryQuestions(page,
                maxResult, maxNavigationPage, likeName);

        model.addAttribute("paginationProducts", result);
        return "questionList";
    }

这是questionList.html,将在其中显示数据:

<div class="product-preview-container" th:each="prodInfo : ${paginationProducts.list}">
    <ul>
        <li>Id: <span th:utext="${prodInfo.id}"></span></li>
        <li>Question: <span th:utext="${prodInfo.question}"></span></li>
        <li>From: <span th:utext="${prodInfo.question}}"></span></li>
        <li>
            <a th:href="@{|/buyProduct?code=${prodInfo.code}|}">Buy Now</a>
        </li>
        <!-- For Manager edit Product -->
        <th:block sec:authorize="hasAuthority('ROLE_MANAGER')">
            <li>
                <a style="color:red;"
                   th:href="@{|/admin/question?id=${prodInfo.id}|}">Edit Question</a>
            </li>
        </th:block>
    </ul>
</div>

<br/>
<div class="page-navigator" th:if="${paginationProducts.totalPages > 1}">
    <th:block th:each="page : ${paginationProducts.navigationPages}">

        <a th:href="@{|/questionList?page=${page}|}" th:if="${page != -1}"
           class="nav-item" th:utext="${page}"></a>

        <span class="nav-item" th:if="${page == -1}"> ... </span>

queryQuestions方法为:

public PaginationResult<QuestionInfo> queryQuestions(int page, int maxResult, int maxNavigationPage,
                                                       String likeName) {
        String sql = "Select new " + QuestionInfo.class.getName() //
                + "(p.id, p.question, p.from) " + " from "//
                + Checkbox.class.getName() + " p ";
        if (likeName != null && likeName.length() > 0) {
            sql += " Where lower(p.question) like :likeName ";
        }
        sql += " order by p.createDate desc ";
        //
        Session session = this.sessionFactory.getCurrentSession();
        Query<QuestionInfo> query = session.createQuery(sql, QuestionInfo.class);

        if (likeName != null && likeName.length() > 0) {
            query.setParameter("likeName", "%" + likeName.toLowerCase() + "%");
        }
        return new PaginationResult<QuestionInfo>(query, page, maxResult, maxNavigationPage);
    }

    public PaginationResult<QuestionInfo> queryQuestions(int page, int maxResult, int maxNavigationPage) {
        return queryQuestions(page, maxResult, maxNavigationPage, null);
    }

id,question和from是Checkbox实体的属性。 我在model.addAttribute("paginationProducts", result)上设置了断点,其值为:

model: size=1 result: PaginationResult@9384

我认为我已经提供了所有必要的信息。您能告诉我为什么它什么都没显示吗?它仅显示标题“问题列表”,但其下方未显示任何内容。

0 个答案:

没有答案