【问题标题】:Thymeleaf view error when loading the page加载页面时出现 Thymeleaf 视图错误
【发布时间】:2019-07-24 18:26:46
【问题描述】:

想请教一下我刚开始研究spring boot的小项目,到现在想把后端表达成前端。

到目前为止,我遇到了导航栏的问题,因为我希望每个页面都有导航栏,但我不知道如何在我创建的每个 HTML 中正确包含它,但这不是我的问题。问题是我为每个页面都制作了相同的导航栏,但是当我加载我的index(/) 页面时,一切都很好,我得到了导航栏/页脚,但是当我尝试加载我的/list 页面时,我必须得到一张桌子以前我只在索引页面上有导航栏,但现在当我尝试加载页面时,我得到了这个错误:

[THYMELEAF][http-nio-8080-exec-10] 异常处理模板 “base-layout”:解析模板时出错 [list/people],模板可能 任何配置的模板都不存在或可能无法访问 解析器(模板:“base-layout” - 第 5 行,第 7 列)

我会将有问题的代码粘贴在底部,以便您尽可能帮助我

这是我的PersonController,它必须返回人员列表

@RequestMapping("/list")
  public String listPeople(Model model){
    List<Person> personList = personService.getAllPersons();

    model.addAttribute("people", personList);
    model.addAttribute("view", "list/people");

    return "base-layout";
  }

这是我的base-layout.html

<head th:include="fragments/head" th:with="pageTitle='Web in progress'"></head>

<body>
<header th:include="fragments/header"></header>
<main th:include="${view}"></main>
<footer th:include="fragments/footer"></footer>
<span th:include="fragments/scripts-bundle"></span>
</body>

如果你能告诉我我的错误在哪里,我希望让我的导航栏在每个页面上工作并加载我的人员表,以便我可以继续开发我的项目

【问题讨论】:

    标签: java thymeleaf


    【解决方案1】:

    你的问题可能是从这一行提出来的——

        model.addAttribute("view", "list/people");
    

    根据您的代码..您在list 文件夹下有一个people 片段。像这样

    --->main
        -->java
        -->resources
           -->templates
              -->fragments
              -->list // may be you miss this folder
                |_people.html
    

    【讨论】:

    • 这解决了我的错误,问题是我没有文件夹“list”。谢谢你解决了我的问题
    猜你喜欢
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多