Spring MVC& ThymeLeaf:th:text没有显示控制器提供的内容

时间:2016-05-22 12:43:06

标签: html spring hibernate thymeleaf

我遇到了以下问题:

我的控制器使用Hibernate DAO从数据库中获取数据。现在,我想在网站上显示该数据。提取工作正常,但不知何故,提取的数据未显示在" th:text"字段。

以下是html文件中的关键部分:

<div class="item active"
                                    th:each="article : ${getAllArticles}">
                                    <div class="carousel-content">
                                        <div>
                                        <!-- Controller generated header -->
                                            <h3 class="article_header" th:text="${hp_header}"></h3>
                                            <p>
                                                <small>Android, EU, Google</small>
                                            </p>
                                            <p th:text="${hp_content}">Lorem ipsum dolor
                                                sit amet, consetetur sadipscing elitr, sed diam nonumy
                                                eirmod tempor invidunt ut labore et dolore magna aliquyam
                                                erat, sed diam voluptua. At vero eos et accusam et justo
                                                duo dolores et ea rebum. Stet clita kasd gubergren, no sea
                                                takimata sanctus est Lorem ipsum dolor sit amet.</p>
                                            <div class="button_area">
                                                <a class="btn btn-large btn-info" href="detailview.html">
                                                    Details </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- END ITEM  -->

这是关联的控制器类:

@Controller

public class IndexController {

private Article prioArticle;

@RequestMapping("/")
public String index(Model model) {
    fetchHighPrioContent();
    model.addAttribute("hp_header", prioArticle.getHeadLine());
    System.out.println(prioArticle.getHeadLine());
    model.addAttribute("hp_content", prioArticle.getContent());
    System.out.println(prioArticle.getContent());
    return "index";
}


private void fetchHighPrioContent(){
    //get highest rated article
    prioArticle = ArticleHandler.getInstance().retriveByRank(1).get(0);
    System.out.println("DEBUG: " + prioArticle.getArtID() + " " + prioArticle.getHeadLine());
}

}

1 个答案:

答案 0 :(得分:0)

您是否曾尝试将属性中的文章放在属性之前?

像...... th:text =“$ {article.hp_content}” 像这样..... th:text =“$ {article.hp_header}”

enter link description here中查看。您有一个示例:8.4删除模板片段