我有一个textfield
<input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>
和具有两个构造函数的实体客户
Costumer(String name)
Costumer(Locale locale, String name)
对于上面的文本框,只调用第一个构造函数!如何调用有两个参数的构造函数,以及如何将区域设置传递给它?
如果我是你,我会用form
TestForm:
public class TestForm {
private String name;
private String locale;
public TestForm() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
@Override
public String toString() {
return "TestForm [name=" + name + ", locale=" + locale + "]";
}
}
控制器:
@RequestMapping(value = "/test", method = GET)
public String test(final ModelMap modelMap) {
modelMap.put("testForm", new TestForm());
return "/test";
}
@RequestMapping(value = "/test", method = POST)
public String posttest(@ModelAttribute("testForm") final TestForm testForm) {
System.out.println(testForm);
return "redirect:/somewhere/else";
}
test.html:
<form th:object="${testForm}" method="post">
<input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>
<input type="text" class="form-control" id="locale" th:value="*{locale}" th:field="*{locale}"/>
<button type="submit">Save</button>
</form>