gpt4 book ai didi

java - 使用 Thymeleaf 渲染 HTML 模板时出错 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor'

转载 作者:行者123 更新时间:2023-12-02 09:14:56 28 4
gpt4 key购买 nike

我在使用 Thymeleaf 和 Spring Boot 渲染 HTML 页面时遇到问题。当它尝试将 html 文件中的字段标记为类中的字段时,出现错误。

错误是:org.thymeleaf.exceptions.TemplateProcessingException:执行处理器“org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”期间出错(模板:“userPreview” - 第 10 行,第 32 栏)

HTML 模板:

 <!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Email User Preview</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Send E-mail:</h1>
<form action="#" th:action="@{/sendmail}" th:object="${message}" method="post">
<p>To:: <input type="text" th:field="*{receiverEmail}" /></p>
<p>Subject: <input type="text" th:field="*{subject}" /></p>
<p>Message: <input type="text" th:field="*{message}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>

Controller :

@Controller
public class TestController {

@GetMapping("/test")
public String send() {
user.setEmailAddress("yasseen.salama@gmail.com");
try {
emailService.sendMail(user, "Hello", "Test");

} catch (MailException mailException) {
System.out.println(mailException);
}
return "Email sent.";
}
@GetMapping("/sendmail")
public String sendingMail(Model model) {
Message message = new Message();
model.addAttribute("userPreview", message);
return "userPreview";
}

@PostMapping("/sendmail")
public String mailSubmit(@ModelAttribute Message message) {
return "Result";
}
}

类消息:

public class Message {
String receiverEmail;
String subject;
String message;

public String getReceiverEmail() {
return receiverEmail;
}

public void setReceiverEmail(String receiverEmail) {
this.receiverEmail = receiverEmail;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}

最佳答案

模板中使用的对象或变量名称是 userPreview 而不是 message,因为这是模型对象中的键

关于java - 使用 Thymeleaf 渲染 HTML 模板时出错 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59072860/

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