在我的 Spring MVC Java 项目中使用 Thymeleaf 时出现 500 错误

问题描述 投票:0回答:1

我在使用 Spring MVC 和 Thymeleaf 处理 Java 项目时遇到问题。每次我尝试加载页面(尤其是index.html)时,都会遇到 500 内部服务器错误。错误消息指向 TemplateInputException:

jakarta.servlet.ServletException: Request processing failed: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/people/index.html]") 
这是我的index.html 中的一个片段:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>All People</title>
</head>
<body>

<div th:each="person : ${people}">
    <a th:href="@{/people/{id}(id=${person.getId()})}" th:text="${person.getName()}">user</a>
</div>

</body>
</html>

我已经仔细检查了我的控制器,但我不知道如何解决这个问题。有人可以帮助我理解为什么 Thymeleaf 无法解析我的模板吗?任何有关解决此问题的建议将不胜感激。

java spring tomcat thymeleaf
1个回答
0
投票

我尝试用 Thymeleaf 解析你的 html,它抱怨:

特别是 xmlns:th="http://thymeleaf.org" 部分。

您可以尝试删除它,看看是否可以解决您的问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.