gpt4 book ai didi

spring-mvc - Thymeleaf:Thymeleaf 模板解析错误

转载 作者:行者123 更新时间:2023-12-02 00:10:46 24 4
gpt4 key购买 nike

我正在实现密码重置功能。为了显示具有此功能的网页,我使用 thymeleaf。但是当我调用我的简单 demo.html 页面(参见下面的代码)时,它会抛出以下错误:

There was an unexpected error (type=Internal Server Error, status=500).

Exception parsing document: template="demo", line 10 - column

Bean 配置:

@Bean
public ClassLoaderTemplateResolver emailTemplateResolver(){
ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
emailTemplateResolver.setPrefix("templates/mail/");
emailTemplateResolver.setSuffix(".html");
emailTemplateResolver.setTemplateMode("HTML5");
emailTemplateResolver.setCharacterEncoding("UTF-8");
emailTemplateResolver.setOrder(1);
return emailTemplateResolver;
}

演示.html:

<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form th:action="@{/resetpassword(_key=${resetPasswordToken})}" method="post">
<div>
<input type="password" th:field="*{password}">
<input type="password">
</div>
</form>
</body>
</html>

Controller :

@RequestMapping(value = "/resetpassword", method = RequestMethod.GET)
public String resetpasswordView(@RequestParam(value = "_key") String resetPasswordToken, final Model model) {
System.out.println(resetPasswordToken);
model.addAttribute("resetPasswordToken", resetPasswordToken);
return "demo";
}

我在这里缺少什么?

最佳答案

默认情况下,Thymeleaf 要求您的模板是有效的 XML。您还没有关闭<input>标签,因此当它到达 </div> 时第 10 行由于标签不平衡而失败。

您可以通过关闭标签来解决问题:

<input type="password" th:field="*{password}" />

或者,您可以使用 Thymeleaf 的旧版 HTML5 模式,但它需要更多设置。

关于spring-mvc - Thymeleaf:Thymeleaf 模板解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34824212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com