我正在嘗試創(chuàng)建一個 HTML Web 表單來創(chuàng)建贊助活動(一個模型類),我有一個 Spring 控制器、一個 Thymeleaf 視圖和實體模型。然而,無論我如何嘗試,我似乎都無法讓 th:field 正常工作。我使用此頁面作為參考https://spring.io/guides/gs/handling-form-submission/看法<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"> <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:執(zhí)行處理器“org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”期間出錯(模板:“events/create”-第9行,第26欄)
1 回答

開滿天機
TA貢獻1786條經(jīng)驗 獲得超13個贊
在 Model 類 Sponsors 中,錯誤是由 @Accessors( Fluent = true) 引起的,我刪除了這一行并解決了問題。
添加回答
舉報
0/150
提交
取消