Я пытаюсь создать веб-форму HTML, которая создает Sponsored Events (класс Model), у меня есть Spring Controller, представление Thymeleaf и модель Entity. Тем не менее, я не могу заставить работать th: field независимо от того, что я пытаюсь.
Я использую эту страницу для справки https://spring.io/guides/gs/handling-form-submission/
Просмотр
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<title>Create a Sponsored Event</title>
</head>
<body>
<h1>Create a Sponsored Event</h1>
<form action="#" th:action="@{/event/create/submit}" th:object="${sponsor}" method="post">
<input type="text" th:field="*{id}"/> <!-- This Line -->
</form>
</body>
</html>
Контроллер
@Controller
@RequestMapping("events")
public class SponsorController {
private static final String CREATE_PAGE = "events/create";
@GetMapping("/create")
public String addSponsorEvent(Model model) {
model.addAttribute("sponsor", new Sponsor());
return CREATE_PAGE;
}
}
Модель
@Data
@Entity
@NoArgsConstructor
@Accessors(fluent = true)
@Table(name = "sponsor_form")
public class Sponsor {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
}
Я пытался изменить это тоже
<input type="text" th:field="*{id}"/>
<input type="text" th:field="*{id()}"/>
<input type="text" th:field="*{sponsor.id}"/>
<input type="text" th:field="*{sponsor.id()}"/>
И я получаю ошибку:
Вызывается: org.attoparser.ParseException: Ошибка при выполнении процессора 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (шаблон: "events / create" - строка 9, столбец 26)