如本教程所建议,你需要使用
th:object,
th:action并
th:field在
Thymeleaf中创建一个表单。
看起来像这样:
控制器:
@RequestMapping(value = "/showForm", method=RequestMethod.GET)public String showForm(Model model) { Foo foo = new Foo(); foo.setBar("bar"); model.addAttribute("foo", foo); ...}@RequestMapping(value = "/processForm", method=RequestMethod.POST)public String processForm(@ModelAttribute(value="foo") Foo foo) { ...}HTML:
<form action="#" th:action="@{/processForm}" th:object="${foo}" method="post"> <input type="text" th:field="*{bar}" /> <input type="submit" /></form>Foo.java:
public class Foo { private String bar; public String getBar() { return bar; } public void setBar(String bar) { this.bar = bar; }}希望这可以帮助。



