我有一个文本域
<input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>
和一个具有两个构造函数
的实体CostumerCostumer(String name)
Costumer(Locale locale, String name)
使用上面的文本框,只会调用第一个构造函数!如何调用具有两个参数的构造函数,以及如何将语言环境传递给它?
答案 0 :(得分:0)
在你的位置,我会使用表格。
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>